From 39d3db4cbdfa9d55c428bce9382166744406f936 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Wed, 28 Mar 2018 13:42:35 +1100 Subject: Added FLTK.Images.Shared and completed FLTK.Devices.Surfaces.Image --- src/c_fl_image_surface.cpp | 4 + src/c_fl_image_surface.h | 1 + src/c_fl_shared_image.cpp | 82 ++++++++++ src/c_fl_shared_image.h | 42 ++++++ src/fltk-devices-surfaces-image.adb | 15 ++ src/fltk-devices-surfaces-image.ads | 5 +- src/fltk-images-shared.adb | 290 ++++++++++++++++++++++++++++++++++++ src/fltk-images-shared.ads | 107 +++++++++++++ 8 files changed, 545 insertions(+), 1 deletion(-) create mode 100644 src/c_fl_shared_image.cpp create mode 100644 src/c_fl_shared_image.h create mode 100644 src/fltk-images-shared.adb create mode 100644 src/fltk-images-shared.ads (limited to 'src') diff --git a/src/c_fl_image_surface.cpp b/src/c_fl_image_surface.cpp index eb8d26e..305e3cc 100644 --- a/src/c_fl_image_surface.cpp +++ b/src/c_fl_image_surface.cpp @@ -35,6 +35,10 @@ void * fl_image_surface_image(IMAGE_SURFACE s) { return reinterpret_cast(s)->image(); } +void * fl_image_surface_highres_image(IMAGE_SURFACE s) { + return reinterpret_cast(s)->highres_image(); +} + diff --git a/src/c_fl_image_surface.h b/src/c_fl_image_surface.h index 3ecafd3..0ad97a3 100644 --- a/src/c_fl_image_surface.h +++ b/src/c_fl_image_surface.h @@ -22,6 +22,7 @@ extern "C" void fl_image_surface_draw_decorated_window(IMAGE_SURFACE s, void * w extern "C" void * fl_image_surface_image(IMAGE_SURFACE s); +extern "C" void * fl_image_surface_highres_image(IMAGE_SURFACE s); extern "C" void fl_image_surface_set_current(IMAGE_SURFACE s); diff --git a/src/c_fl_shared_image.cpp b/src/c_fl_shared_image.cpp new file mode 100644 index 0000000..c31b12f --- /dev/null +++ b/src/c_fl_shared_image.cpp @@ -0,0 +1,82 @@ + + +#include +#include +#include "c_fl_shared_image.h" + + + + +SHARED_IMAGE fl_shared_image_get(const char * f, int w, int h) { + return Fl_Shared_Image::get(f, w, h); +} + +SHARED_IMAGE fl_shared_image_get2(void * r) { + return Fl_Shared_Image::get(reinterpret_cast(r)); +} + +SHARED_IMAGE fl_shared_image_find(const char * n, int w, int h) { + return Fl_Shared_Image::find(n, w, h); +} + +void release_fl_shared_image(SHARED_IMAGE i) { + reinterpret_cast(i)->release(); +} + +SHARED_IMAGE fl_shared_image_copy(SHARED_IMAGE i, int w, int h) { + return reinterpret_cast(i)->copy(w, h); +} + +SHARED_IMAGE fl_shared_image_copy2(SHARED_IMAGE i) { + return reinterpret_cast(i)->copy(); +} + + + + +void fl_shared_image_color_average(SHARED_IMAGE i, int c, float b) { + reinterpret_cast(i)->color_average(c, b); +} + +void fl_shared_image_desaturate(SHARED_IMAGE i) { + reinterpret_cast(i)->desaturate(); +} + + + + +const char * fl_shared_image_name(SHARED_IMAGE i) { + return reinterpret_cast(i)->name(); +} + +void fl_shared_image_reload(SHARED_IMAGE i) { + reinterpret_cast(i)->reload(); +} + +void fl_shared_image_uncache(SHARED_IMAGE i) { + reinterpret_cast(i)->uncache(); +} + + + + +void fl_shared_image_scaling_algorithm(int v) { + Fl_Shared_Image::scaling_algorithm(static_cast(v)); +} + +void fl_shared_image_scale(SHARED_IMAGE i, int w, int h, int p, int e) { + reinterpret_cast(i)->scale(w, h, p, e); +} + + + + +void fl_shared_image_draw(SHARED_IMAGE i, int x, int y, int w, int h, int cx, int cy) { + reinterpret_cast(i)->draw(x, y, w, h, cx, cy); +} + +void fl_shared_image_draw2(SHARED_IMAGE i, int x, int y) { + reinterpret_cast(i)->draw(x, y); +} + + diff --git a/src/c_fl_shared_image.h b/src/c_fl_shared_image.h new file mode 100644 index 0000000..6c6abdf --- /dev/null +++ b/src/c_fl_shared_image.h @@ -0,0 +1,42 @@ + + +#ifndef FL_SHARED_IMAGE_GUARD +#define FL_SHARED_IMAGE_GUARD + + + + +typedef void* SHARED_IMAGE; + + + + +extern "C" SHARED_IMAGE fl_shared_image_get(const char * f, int w, int h); +extern "C" SHARED_IMAGE fl_shared_image_get2(void * r); +extern "C" SHARED_IMAGE fl_shared_image_find(const char * n, int w, int h); +extern "C" void release_fl_shared_image(SHARED_IMAGE i); +extern "C" SHARED_IMAGE fl_shared_image_copy(SHARED_IMAGE i, int w, int h); +extern "C" SHARED_IMAGE fl_shared_image_copy2(SHARED_IMAGE i); + + + + +extern "C" void fl_shared_image_color_average(SHARED_IMAGE i, int c, float b); +extern "C" void fl_shared_image_desaturate(SHARED_IMAGE i); + + +extern "C" const char * fl_shared_image_name(SHARED_IMAGE i); +extern "C" void fl_shared_image_reload(SHARED_IMAGE i); +extern "C" void fl_shared_image_uncache(SHARED_IMAGE i); + + +extern "C" void fl_shared_image_scaling_algorithm(int v); +extern "C" void fl_shared_image_scale(SHARED_IMAGE i, int w, int h, int p, int e); + + +extern "C" void fl_shared_image_draw(SHARED_IMAGE i, int x, int y, int w, int h, int cx, int cy); +extern "C" void fl_shared_image_draw2(SHARED_IMAGE i, int x, int y); + + +#endif + diff --git a/src/fltk-devices-surfaces-image.adb b/src/fltk-devices-surfaces-image.adb index 0621e39..1955bf3 100644 --- a/src/fltk-devices-surfaces-image.adb +++ b/src/fltk-devices-surfaces-image.adb @@ -44,6 +44,11 @@ package body FLTK.Devices.Surfaces.Image is return System.Address; pragma Import (C, fl_image_surface_image, "fl_image_surface_image"); + function fl_image_surface_highres_image + (S : in System.Address) + return System.Address; + pragma Import (C, fl_image_surface_highres_image, "fl_image_surface_highres_image"); + @@ -138,6 +143,16 @@ package body FLTK.Devices.Surfaces.Image is end Get_Image; + function Get_Highres_Image + (This : in Image_Surface) + return FLTK.Images.Shared.Shared_Image is + begin + return Img : FLTK.Images.Shared.Shared_Image do + Wrapper (Img).Void_Ptr := fl_image_surface_highres_image (This.Void_Ptr); + end return; + end Get_Highres_Image; + + procedure Set_Current diff --git a/src/fltk-devices-surfaces-image.ads b/src/fltk-devices-surfaces-image.ads index 1c7e383..6023af2 100644 --- a/src/fltk-devices-surfaces-image.ads +++ b/src/fltk-devices-surfaces-image.ads @@ -3,6 +3,7 @@ with FLTK.Images.RGB, + FLTK.Images.Shared, FLTK.Widgets.Groups.Windows; @@ -50,7 +51,9 @@ package FLTK.Devices.Surfaces.Image is (This : in Image_Surface) return FLTK.Images.RGB.RGB_Image; - -- Get_Highres_Image + function Get_Highres_Image + (This : in Image_Surface) + return FLTK.Images.Shared.Shared_Image; diff --git a/src/fltk-images-shared.adb b/src/fltk-images-shared.adb new file mode 100644 index 0000000..e5bd240 --- /dev/null +++ b/src/fltk-images-shared.adb @@ -0,0 +1,290 @@ + + +with + + Interfaces.C.Strings, + System; + +use type + + System.Address; + + +package body FLTK.Images.Shared is + + + function fl_shared_image_get + (F : in Interfaces.C.char_array; + W, H : in Interfaces.C.int) + return System.Address; + pragma Import (C, fl_shared_image_get, "fl_shared_image_get"); + + function fl_shared_image_get2 + (I : in System.Address) + return System.Address; + pragma Import (C, fl_shared_image_get2, "fl_shared_image_get2"); + + function fl_shared_image_find + (N : in Interfaces.C.char_array; + W, H : in Interfaces.C.int) + return System.Address; + pragma Import (C, fl_shared_image_find, "fl_shared_image_find"); + + procedure fl_shared_image_release + (I : in System.Address); + pragma Import (C, fl_shared_image_release, "fl_shared_image_release"); + + function fl_shared_image_copy + (I : in System.Address; + W, H : in Interfaces.C.int) + return System.Address; + pragma Import (C, fl_shared_image_copy, "fl_shared_image_copy"); + + function fl_shared_image_copy2 + (I : in System.Address) + return System.Address; + pragma Import (C, fl_shared_image_copy2, "fl_shared_image_copy2"); + + + + + procedure fl_shared_image_color_average + (I : in System.Address; + C : in Interfaces.C.int; + B : in Interfaces.C.C_float); + pragma Import (C, fl_shared_image_color_average, "fl_shared_image_color_average"); + + procedure fl_shared_image_desaturate + (I : in System.Address); + pragma Import (C, fl_shared_image_desaturate, "fl_shared_image_desaturate"); + + + + + function fl_shared_image_name + (I : in System.Address) + return Interfaces.C.Strings.chars_ptr; + pragma Import (C, fl_shared_image_name, "fl_shared_image_name"); + + procedure fl_shared_image_reload + (I : in System.Address); + pragma Import (C, fl_shared_image_reload, "fl_shared_image_reload"); + + procedure fl_shared_image_uncache + (I : in System.Address); + pragma Import (C, fl_shared_image_uncache, "fl_shared_image_uncache"); + + + + + procedure fl_shared_image_scaling_algorithm + (A : in Interfaces.C.int); + pragma Import (C, fl_shared_image_scaling_algorithm, "fl_shared_image_scaling_algorithm"); + + procedure fl_shared_image_scale + (I : in System.Address; + W, H, P, E : in Interfaces.C.int); + pragma Import (C, fl_shared_image_scale, "fl_shared_image_scale"); + + + + + procedure fl_shared_image_draw + (I : in System.Address; + X, Y, W, H, CX, CY : in Interfaces.C.int); + pragma Import (C, fl_shared_image_draw, "fl_shared_image_draw"); + + procedure fl_shared_image_draw2 + (I : in System.Address; + X, Y : in Interfaces.C.int); + pragma Import (C, fl_shared_image_draw2, "fl_shared_image_draw2"); + + + + + overriding procedure Finalize + (This : in out Shared_Image) is + begin + if This.Void_Ptr /= System.Null_Address and then + This in Shared_Image'Class + then + fl_shared_image_release (This.Void_Ptr); + This.Void_Ptr := System.Null_Address; + end if; + Finalize (Image (This)); + end Finalize; + + + + + package body Forge is + + function Create + (Filename : in String; + W, H : in Integer) + return Shared_Image is + begin + return This : Shared_Image do + This.Void_Ptr := fl_shared_image_get + (Interfaces.C.To_C (Filename), + Interfaces.C.int (W), + Interfaces.C.int (H)); + end return; + end Create; + + + function Create + (From : in FLTK.Images.RGB.RGB_Image'Class) + return Shared_Image is + begin + return This : Shared_Image do + This.Void_Ptr := fl_shared_image_get2 (Wrapper (From).Void_Ptr); + end return; + end Create; + + + function Find + (Name : in String; + W, H : in Integer := 0) + return Shared_Image is + begin + return This : Shared_Image do + This.Void_Ptr := fl_shared_image_find + (Interfaces.C.To_C (Name), + Interfaces.C.int (W), + Interfaces.C.int (H)); + if This.Void_Ptr = System.Null_Address then + raise No_Image_Error; + end if; + end return; + end Find; + + end Forge; + + + + + function Copy + (This : in Shared_Image; + Width, Height : in Natural) + return Shared_Image'Class is + begin + return Copied : Shared_Image do + Copied.Void_Ptr := fl_shared_image_copy + (This.Void_Ptr, + Interfaces.C.int (Width), + Interfaces.C.int (Height)); + end return; + end Copy; + + + function Copy + (This : in Shared_Image) + return Shared_Image'Class is + begin + return Copied : Shared_Image do + Copied.Void_Ptr := fl_shared_image_copy2 (This.Void_Ptr); + end return; + end Copy; + + + + + procedure Color_Average + (This : in out Shared_Image; + Col : in Color; + Amount : in Blend) is + begin + fl_shared_image_color_average + (This.Void_Ptr, + Interfaces.C.int (Col), + Interfaces.C.C_float (Amount)); + end Color_Average; + + + procedure Desaturate + (This : in out Shared_Image) is + begin + fl_shared_image_desaturate (This.Void_Ptr); + end Desaturate; + + + + + function Name + (This : in Shared_Image) + return String is + begin + return Interfaces.C.Strings.Value (fl_shared_image_name (This.Void_Ptr)); + end Name; + + + procedure Reload + (This : in out Shared_Image) is + begin + fl_shared_image_reload (This.Void_Ptr); + end Reload; + + + procedure Uncache + (This : in out Shared_Image) is + begin + fl_shared_image_uncache (This.Void_Ptr); + end Uncache; + + + + + procedure Set_Scaling_Algorithm + (To : in Scaling_Kind) is + begin + fl_shared_image_scaling_algorithm (Scaling_Kind'Pos (To)); + end Set_Scaling_Algorithm; + + + procedure Scale + (This : in out Shared_Image; + W, H : in Integer; + Proportional : in Boolean := True; + Can_Expand : in Boolean := False) is + begin + fl_shared_image_scale + (This.Void_Ptr, + Interfaces.C.int (W), + Interfaces.C.int (H), + Boolean'Pos (Proportional), + Boolean'Pos (Can_Expand)); + end Scale; + + + + + procedure Draw + (This : in Shared_Image; + X, Y, W, H : in Integer; + CX, CY : in Integer := 0) is + begin + fl_shared_image_draw + (This.Void_Ptr, + Interfaces.C.int (X), + Interfaces.C.int (Y), + Interfaces.C.int (W), + Interfaces.C.int (H), + Interfaces.C.int (CX), + Interfaces.C.int (CY)); + end Draw; + + + procedure Draw + (This : in Shared_Image; + X, Y : in Integer) is + begin + fl_shared_image_draw2 + (This.Void_Ptr, + Interfaces.C.int (X), + Interfaces.C.int (Y)); + end Draw; + + +end FLTK.Images.Shared; + diff --git a/src/fltk-images-shared.ads b/src/fltk-images-shared.ads new file mode 100644 index 0000000..9214c8d --- /dev/null +++ b/src/fltk-images-shared.ads @@ -0,0 +1,107 @@ + + +with + + FLTK.Images.RGB; + + +package FLTK.Images.Shared is + + + type Shared_Image is new Image with private; + + type Scaling_Kind is (Nearest, Bilinear); + + + + + package Forge is + + function Create + (Filename : in String; + W, H : in Integer) + return Shared_Image; + + function Create + (From : in FLTK.Images.RGB.RGB_Image'Class) + return Shared_Image; + + function Find + (Name : in String; + W, H : in Integer := 0) + return Shared_Image; + + end Forge; + + + + + function Copy + (This : in Shared_Image; + Width, Height : in Natural) + return Shared_Image'Class; + + function Copy + (This : in Shared_Image) + return Shared_Image'Class; + + + + + procedure Color_Average + (This : in out Shared_Image; + Col : in Color; + Amount : in Blend); + + procedure Desaturate + (This : in out Shared_Image); + + + + + function Name + (This : in Shared_Image) + return String; + + procedure Reload + (This : in out Shared_Image); + + procedure Uncache + (This : in out Shared_Image); + + + + + procedure Set_Scaling_Algorithm + (To : in Scaling_Kind); + + procedure Scale + (This : in out Shared_Image; + W, H : in Integer; + Proportional : in Boolean := True; + Can_Expand : in Boolean := False); + + + + + procedure Draw + (This : in Shared_Image; + X, Y, W, H : in Integer; + CX, CY : in Integer := 0); + + procedure Draw + (This : in Shared_Image; + X, Y : in Integer); + + +private + + + type Shared_Image is new Image with null record; + + overriding procedure Finalize + (This : in out Shared_Image); + + +end FLTK.Images.Shared; + -- cgit