aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2025-04-11 22:21:26 +1200
committerJedidiah Barber <contact@jedbarber.id.au>2025-04-11 22:21:26 +1200
commitfb4183c9244ee31aa5cb8bc9745c9242b1fafeeb (patch)
treea33c13dd090a1798a6638b9762dcc7187438f980
parent192b9538fcbe46649dccd44b499a0d52d17cf283 (diff)
Moved Size_Type to FLTK and better incorporated it into Bitmaps and RGB_Images
-rw-r--r--body/fltk-draw.adb9
-rw-r--r--body/fltk-images-bitmaps.adb14
-rw-r--r--body/fltk-images-rgb.adb16
-rw-r--r--doc/fl.html10
-rw-r--r--doc/fl_bitmap.html33
-rw-r--r--doc/fl_draw.html12
-rw-r--r--doc/fl_rgb_image.html25
-rw-r--r--spec/fltk-draw.ads12
-rw-r--r--spec/fltk-images-bitmaps.ads17
-rw-r--r--spec/fltk-images-rgb.ads23
-rw-r--r--spec/fltk.ads11
-rw-r--r--test/animated.adb19
-rw-r--r--test/color_chooser.adb7
13 files changed, 123 insertions, 85 deletions
diff --git a/body/fltk-draw.adb b/body/fltk-draw.adb
index 3ce8918..38ccb80 100644
--- a/body/fltk-draw.adb
+++ b/body/fltk-draw.adb
@@ -1049,7 +1049,7 @@ package body FLTK.Draw is
X, Y, W : in Interfaces.C.int;
Buf_Ptr : in Storage.Integer_Address)
is
- Data_Buffer : Color_Component_Array (1 .. Integer (W));
+ Data_Buffer : Color_Component_Array (1 .. Size_Type (W));
for Data_Buffer'Address use Storage.To_Address (Buf_Ptr);
pragma Import (Ada, Data_Buffer);
begin
@@ -1120,7 +1120,7 @@ package body FLTK.Draw is
X, Y, W : in Interfaces.C.int;
Buf_Ptr : in Storage.Integer_Address)
is
- Data_Buffer : Color_Component_Array (1 .. Integer (W));
+ Data_Buffer : Color_Component_Array (1 .. Size_Type (W));
for Data_Buffer'Address use Storage.To_Address (Buf_Ptr);
pragma Import (Ada, Data_Buffer);
begin
@@ -1173,7 +1173,10 @@ package body FLTK.Draw is
Alpha : in Integer := 0)
return Color_Component_Array
is
- My_Len : constant Integer := (if Alpha = 0 then W * H * 3 else W * H * 4);
+ My_Len : constant Size_Type :=
+ (if Alpha = 0
+ then Size_Type (W) * Size_Type (H) * 3
+ else Size_Type (W) * Size_Type (H) * 4);
Result : Color_Component_Array (1 .. My_Len);
Buffer : Storage.Integer_Address;
begin
diff --git a/body/fltk-images-bitmaps.adb b/body/fltk-images-bitmaps.adb
index 4597151..5b59c13 100644
--- a/body/fltk-images-bitmaps.adb
+++ b/body/fltk-images-bitmaps.adb
@@ -191,15 +191,15 @@ package body FLTK.Images.Bitmaps is
function Data_Size
(This : in Bitmap)
- return Natural is
+ return Size_Type is
begin
- return Bytes_Needed (This.Get_W) * This.Get_H;
+ return Size_Type (Bytes_Needed (This.Get_W)) * Size_Type (This.Get_H);
end Data_Size;
function Get_Datum
(This : in Bitmap;
- Place : in Positive)
+ Place : in Positive_Size)
return Color_Component
is
The_Data : Color_Component_Array (1 .. This.Data_Size);
@@ -212,7 +212,7 @@ package body FLTK.Images.Bitmaps is
procedure Set_Datum
(This : in out Bitmap;
- Place : in Positive;
+ Place : in Positive_Size;
Value : in Color_Component)
is
The_Data : Color_Component_Array (1 .. This.Data_Size);
@@ -225,8 +225,8 @@ package body FLTK.Images.Bitmaps is
function Slice
(This : in Bitmap;
- Low : in Positive;
- High : in Natural)
+ Low : in Positive_Size;
+ High : in Size_Type)
return Color_Component_Array
is
The_Data : Color_Component_Array (1 .. This.Data_Size);
@@ -239,7 +239,7 @@ package body FLTK.Images.Bitmaps is
procedure Overwrite
(This : in out Bitmap;
- Place : in Positive;
+ Place : in Positive_Size;
Values : in Color_Component_Array)
is
The_Data : Color_Component_Array (1 .. This.Data_Size);
diff --git a/body/fltk-images-rgb.adb b/body/fltk-images-rgb.adb
index 00fc1ed..71d2520 100644
--- a/body/fltk-images-rgb.adb
+++ b/body/fltk-images-rgb.adb
@@ -275,21 +275,21 @@ package body FLTK.Images.RGB is
function Data_Size
(This : in RGB_Image)
- return Natural
+ return Size_Type
is
Per_Line : constant Natural := This.Get_Line_Size;
begin
if Per_Line = 0 then
- return This.Get_W * This.Get_D * This.Get_H;
+ return Size_Type (This.Get_W) * Size_Type (This.Get_D) * Size_Type (This.Get_H);
else
- return Per_Line * This.Get_H;
+ return Size_Type (Per_Line) * Size_Type (This.Get_H);
end if;
end Data_Size;
function Get_Datum
(This : in RGB_Image;
- Place : in Positive)
+ Place : in Positive_Size)
return Color_Component
is
The_Data : Color_Component_Array (1 .. This.Data_Size);
@@ -302,7 +302,7 @@ package body FLTK.Images.RGB is
procedure Set_Datum
(This : in out RGB_Image;
- Place : in Positive;
+ Place : in Positive_Size;
Value : in Color_Component)
is
The_Data : Color_Component_Array (1 .. This.Data_Size);
@@ -315,8 +315,8 @@ package body FLTK.Images.RGB is
function Slice
(This : in RGB_Image;
- Low : in Positive;
- High : in Natural)
+ Low : in Positive_Size;
+ High : in Size_Type)
return Color_Component_Array
is
The_Data : Color_Component_Array (1 .. This.Data_Size);
@@ -329,7 +329,7 @@ package body FLTK.Images.RGB is
procedure Overwrite
(This : in out RGB_Image;
- Place : in Positive;
+ Place : in Positive_Size;
Values : in Color_Component_Array)
is
The_Data : Color_Component_Array (1 .. This.Data_Size);
diff --git a/doc/fl.html b/doc/fl.html
index 9cefff7..96bb11d 100644
--- a/doc/fl.html
+++ b/doc/fl.html
@@ -51,6 +51,16 @@
<td>Menu_Flag</td>
</tr>
+ <tr>
+ <td>size_t</td>
+ <td>Size_Type</td>
+ </tr>
+
+ <tr>
+ <td>size_t</td>
+ <td>Positive_Size</td>
+ </tr>
+
</table>
diff --git a/doc/fl_bitmap.html b/doc/fl_bitmap.html
index 922b1b5..edaf6a4 100644
--- a/doc/fl_bitmap.html
+++ b/doc/fl_bitmap.html
@@ -62,31 +62,31 @@ const uchar * array;
<td><pre>
function Data_Size
(This : in Bitmap)
- return Natural;
+ return Size_Type;
function Get_Datum
(This : in Bitmap;
- Place : in Positive)
+ Place : in Positive_Size)
return Color_Component
with Pre => Place <= This.Data_Size;
procedure Set_Datum
(This : in out Bitmap;
- Place : in Positive;
+ Place : in Positive_Size;
Value : in Color_Component)
with Pre => Place <= This.Data_Size;
function Slice
(This : in Bitmap;
- Low : in Positive;
- High : in Natural)
+ Low : in Positive_Size;
+ High : in Size_Type)
return Color_Component_Array
with Pre => High <= This.Data_Size,
- Post => Slice'Result'Length = Integer'Max (0, High - Low + 1);
+ Post => Slice'Result'Length = Size_Type'Max (0, High - Low + 1);
procedure Overwrite
(This : in out Bitmap;
- Place : in Positive;
+ Place : in Positive_Size;
Values : in Color_Component_Array)
with Pre => Place + Values'Length - 1 <= This.Data_Size;
@@ -115,7 +115,24 @@ function Create
(Data : in Color_Component_Array;
Width, Height : in Natural)
return Bitmap
-with Pre => Data'Length = To_Next_Byte (Width) * Height;
+with Pre =>
+ Data'Length >= Size_Type (Bytes_Needed (Width)) * Size_Type (Height);
+</pre></td>
+ </tr>
+
+</table>
+
+
+
+<table class="function">
+ <tr><th colspan="2">Static Functions and Procedures</th></tr>
+
+ <tr>
+<td>&nbsp;</td>
+<td><pre>
+function Bytes_Needed
+ (Bits : in Natural)
+ return Natural;
</pre></td>
</tr>
diff --git a/doc/fl_draw.html b/doc/fl_draw.html
index 55b08bd..aca154a 100644
--- a/doc/fl_draw.html
+++ b/doc/fl_draw.html
@@ -419,8 +419,8 @@ procedure Draw_Image
Flip_Horizontal : in Boolean := False;
Flip_Vertical : in Boolean := False)
with Pre => (if Line_Size = 0
- then Data'Length >= W * H * Depth
- else Data'Length >= Line_Size * H);
+ then Data'Length >= Size_Type (W) * Size_Type (H) * Size_Type (Depth)
+ else Data'Length >= Size_Type (Line_Size) * Size_Type (H));
</pre></td>
</tr>
@@ -451,8 +451,8 @@ procedure Draw_Image_Mono
Flip_Horizontal : Boolean := False;
Flip_Vertical : Boolean := False)
with Pre => (if Line_Size = 0
- then Data'Length >= W * H * Depth
- else Data'Length >= Line_Size * H);
+ then Data'Length >= Size_Type (W) * Size_Type (H) * Size_Type (Depth)
+ else Data'Length >= Size_Type (Line_Size) * Size_Type (H));
</pre></td>
</tr>
@@ -916,8 +916,8 @@ function Read_Image
return Color_Component_Array
with Post =>
(if Alpha = 0
- then Read_Image'Result'Length = W * H * 3
- else Read_Image'Result'Length = W * H * 4);
+ then Read_Image'Result'Length = Size_Type (W) * Size_Type (H) * 3
+ else Read_Image'Result'Length = Size_Type (W) * Size_Type (H) * 4);
</pre></td>
</tr>
diff --git a/doc/fl_rgb_image.html b/doc/fl_rgb_image.html
index 061b07a..6d5427d 100644
--- a/doc/fl_rgb_image.html
+++ b/doc/fl_rgb_image.html
@@ -62,31 +62,31 @@ const uchar * array;
<td><pre>
function Data_Size
(This : in RGB_Image)
- return Natural;
+ return Size_Type;
function Get_Datum
(This : in RGB_Image;
- Place : in Positive)
+ Place : in Positive_Size)
return Color_Component
with Pre => Place <= This.Data_Size;
procedure Set_Datum
(This : in out RGB_Image;
- Place : in Positive;
+ Place : in Positive_Size;
Value : in Color_Component)
with Pre => Place <= This.Data_Size;
function Slice
(This : in RGB_Image;
- Low : in Positive;
- High : in Natural)
+ Low : in Positive_Size;
+ High : in Size_Type)
return Color_Component_Array
with Pre => High <= This.Data_Size,
- Post => Slice'Result'Length = Integer'Max (0, High - Low + 1);
+ Post => Slice'Result'Length = Size_Type'Max (0, High - Low + 1);
procedure Overwrite
(This : in out RGB_Image;
- Place : in Positive;
+ Place : in Positive_Size;
Values : in Color_Component_Array)
with Pre => Place + Values'Length - 1 <= This.Data_Size;
@@ -106,7 +106,8 @@ with Post => All_Data'Result'Length = This.Data_Size;
<tr>
<td><pre>
-Fl_RGB_Image(const uchar *bits, int W, int H, int D=3, int LD=0);
+Fl_RGB_Image(const uchar *bits, int W, int H,
+ int D=3, int LD=0);
</pre></td>
<td><pre>
function Create
@@ -116,8 +117,8 @@ function Create
Line_Size : in Natural := 0)
return RGB_Image
with Pre => (if Line_Size = 0
- then Data'Length = Width * Height * Depth
- else Data'Length = Line_Size * Height)
+ then Data'Length >= Size_Type (Width) * Size_Type (Height) * Size_Type (Depth)
+ else Data'Length >= Size_Type (Line_Size) * Size_Type (Height))
and Data'Length <= Get_Max_Size;
</pre></td>
</tr>
@@ -147,7 +148,7 @@ static void max_size(size_t size);
</pre></td>
<td><pre>
procedure Set_Max_Size
- (Value : in Natural);
+ (Value : in Size_Type);
</pre></td>
</tr>
@@ -157,7 +158,7 @@ static size_t max_size();
</pre></td>
<td><pre>
function Get_Max_Size
- return Natural;
+ return Size_Type;
</pre></td>
</tr>
diff --git a/spec/fltk-draw.ads b/spec/fltk-draw.ads
index 8346112..a2c66f3 100644
--- a/spec/fltk-draw.ads
+++ b/spec/fltk-draw.ads
@@ -256,8 +256,8 @@ package FLTK.Draw is
Flip_Horizontal : in Boolean := False;
Flip_Vertical : in Boolean := False)
with Pre => (if Line_Size = 0
- then Data'Length >= W * H * Depth
- else Data'Length >= Line_Size * H);
+ then Data'Length >= Size_Type (W) * Size_Type (H) * Size_Type (Depth)
+ else Data'Length >= Size_Type (Line_Size) * Size_Type (H));
procedure Draw_Image
(X, Y, W, H : in Integer;
@@ -272,8 +272,8 @@ package FLTK.Draw is
Flip_Horizontal : Boolean := False;
Flip_Vertical : Boolean := False)
with Pre => (if Line_Size = 0
- then Data'Length >= W * H * Depth
- else Data'Length >= Line_Size * H);
+ then Data'Length >= Size_Type (W) * Size_Type (H) * Size_Type (Depth)
+ else Data'Length >= Size_Type (Line_Size) * Size_Type (H));
procedure Draw_Image_Mono
(X, Y, W, H : in Integer;
@@ -299,8 +299,8 @@ package FLTK.Draw is
return Color_Component_Array
with Post =>
(if Alpha = 0
- then Read_Image'Result'Length = W * H * 3
- else Read_Image'Result'Length = W * H * 4);
+ then Read_Image'Result'Length = Size_Type (W) * Size_Type (H) * 3
+ else Read_Image'Result'Length = Size_Type (W) * Size_Type (H) * 4);
diff --git a/spec/fltk-images-bitmaps.ads b/spec/fltk-images-bitmaps.ads
index 73afc62..9577273 100644
--- a/spec/fltk-images-bitmaps.ads
+++ b/spec/fltk-images-bitmaps.ads
@@ -33,7 +33,8 @@ package FLTK.Images.Bitmaps is
(Data : in Color_Component_Array;
Width, Height : in Natural)
return Bitmap
- with Pre => Data'Length >= Bytes_Needed (Width) * Height;
+ with Pre =>
+ Data'Length >= Size_Type (Bytes_Needed (Width)) * Size_Type (Height);
end Forge;
@@ -66,31 +67,31 @@ package FLTK.Images.Bitmaps is
function Data_Size
(This : in Bitmap)
- return Natural;
+ return Size_Type;
function Get_Datum
(This : in Bitmap;
- Place : in Positive)
+ Place : in Positive_Size)
return Color_Component
with Pre => Place <= This.Data_Size;
procedure Set_Datum
(This : in out Bitmap;
- Place : in Positive;
+ Place : in Positive_Size;
Value : in Color_Component)
with Pre => Place <= This.Data_Size;
function Slice
(This : in Bitmap;
- Low : in Positive;
- High : in Natural)
+ Low : in Positive_Size;
+ High : in Size_Type)
return Color_Component_Array
with Pre => High <= This.Data_Size,
- Post => Slice'Result'Length = Integer'Max (0, High - Low + 1);
+ Post => Slice'Result'Length = Size_Type'Max (0, High - Low + 1);
procedure Overwrite
(This : in out Bitmap;
- Place : in Positive;
+ Place : in Positive_Size;
Values : in Color_Component_Array)
with Pre => Place + Values'Length - 1 <= This.Data_Size;
diff --git a/spec/fltk-images-rgb.ads b/spec/fltk-images-rgb.ads
index 242098a..d893cec 100644
--- a/spec/fltk-images-rgb.ads
+++ b/spec/fltk-images-rgb.ads
@@ -6,8 +6,7 @@
with
- FLTK.Images.Pixmaps,
- System.Storage_Elements;
+ FLTK.Images.Pixmaps;
package FLTK.Images.RGB is
@@ -20,8 +19,6 @@ package FLTK.Images.RGB is
type RGB_Image_Array is array (Positive range <>) of RGB_Image;
- type Size_Type is mod 2 ** System.Storage_Elements.Integer_Address'Size;
-
@@ -48,8 +45,8 @@ package FLTK.Images.RGB is
Line_Size : in Natural := 0)
return RGB_Image
with Pre => (if Line_Size = 0
- then Data'Length >= Width * Height * Depth
- else Data'Length >= Line_Size * Height)
+ then Data'Length >= Size_Type (Width) * Size_Type (Height) * Size_Type (Depth)
+ else Data'Length >= Size_Type (Line_Size) * Size_Type (Height))
and Data'Length <= Get_Max_Size;
function Create
@@ -101,31 +98,31 @@ package FLTK.Images.RGB is
function Data_Size
(This : in RGB_Image)
- return Natural;
+ return Size_Type;
function Get_Datum
(This : in RGB_Image;
- Place : in Positive)
+ Place : in Positive_Size)
return Color_Component
with Pre => Place <= This.Data_Size;
procedure Set_Datum
(This : in out RGB_Image;
- Place : in Positive;
+ Place : in Positive_Size;
Value : in Color_Component)
with Pre => Place <= This.Data_Size;
function Slice
(This : in RGB_Image;
- Low : in Positive;
- High : in Natural)
+ Low : in Positive_Size;
+ High : in Size_Type)
return Color_Component_Array
with Pre => High <= This.Data_Size,
- Post => Slice'Result'Length = Integer'Max (0, High - Low + 1);
+ Post => Slice'Result'Length = Size_Type'Max (0, High - Low + 1);
procedure Overwrite
(This : in out RGB_Image;
- Place : in Positive;
+ Place : in Positive_Size;
Values : in Color_Component_Array)
with Pre => Place + Values'Length - 1 <= This.Data_Size;
diff --git a/spec/fltk.ads b/spec/fltk.ads
index f5add9b..964af79 100644
--- a/spec/fltk.ads
+++ b/spec/fltk.ads
@@ -6,7 +6,8 @@
with
- Ada.Finalization;
+ Ada.Finalization,
+ System;
private with
@@ -34,18 +35,22 @@ package FLTK is
-- Text buffers for marshalling purposes will be this size.
Buffer_Size : constant Natural := 1024;
+ -- For image data arrays.
+ type Size_Type is mod 2 ** System.Word_Size;
+ subtype Positive_Size is Size_Type range 1 .. Size_Type'Last;
+
-- Color --
- -- Values scale from A/Black to X/White
+ -- Values scale from A/Black to X/White.
type Greyscale is new Character range 'A' .. 'X';
type Color is mod 2**32;
type Color_Component is mod 256;
- type Color_Component_Array is array (Positive range <>) of aliased Color_Component;
+ type Color_Component_Array is array (Positive_Size range <>) of aliased Color_Component;
subtype Blend is Float range 0.0 .. 1.0;
diff --git a/test/animated.adb b/test/animated.adb
index 4a5b570..4f6f590 100644
--- a/test/animated.adb
+++ b/test/animated.adb
@@ -34,7 +34,8 @@ is
Dimension : constant Integer := 256;
- subtype Image_Data is FLTK.Color_Component_Array (1 .. Dimension ** 2 * Channels);
+ subtype Image_Data is FLTK.Color_Component_Array
+ (1 .. FLTK.Size_Type (Dimension ** 2 * Channels));
type Image_Data_Array is array (Positive range <>) of Image_Data;
@@ -43,7 +44,7 @@ is
begin
for X in Integer range 0 .. 9 loop
for Y in Integer range 0 .. 9 loop
- Store (Y * Dimension * Channels + X * Channels + 4) := 255;
+ Store (FLTK.Size_Type (Channels * (Y * Dimension + X) + 4)) := 255;
end loop;
end loop;
end Black_Box_Corner;
@@ -82,10 +83,10 @@ is
My_Alpha := FLTK.Color_Component (Float (My_Alpha) * (1.0 - Fill) * 10.0);
end if;
- Store (Y * Dimension * Channels + X * Channels + 1) := Grey;
- Store (Y * Dimension * Channels + X * Channels + 2) := Grey;
- Store (Y * Dimension * Channels + X * Channels + 3) := Grey;
- Store (Y * Dimension * Channels + X * Channels + 4) := My_Alpha;
+ Store (FLTK.Size_Type (Channels * (Y * Dimension + X) + 1)) := Grey;
+ Store (FLTK.Size_Type (Channels * (Y * Dimension + X) + 2)) := Grey;
+ Store (FLTK.Size_Type (Channels * (Y * Dimension + X) + 3)) := Grey;
+ Store (FLTK.Size_Type (Channels * (Y * Dimension + X) + 4)) := My_Alpha;
end if;
end loop;
end loop;
@@ -106,8 +107,10 @@ is
if (X + X_Offset >= 0) and (X + X_Offset < Dimension) then
for Y in Integer range Y_Offset - W .. Y_Offset + W - 1 loop
Grey := FLTK.Color_Component (abs (Y - Y_Offset));
- Store (Y * Dimension * Channels + (X + X_Offset) * Channels + 3) := Grey;
- Store (Y * Dimension * Channels + (X + X_Offset) * Channels + 4) := 127;
+ Store (FLTK.Size_Type
+ (Channels * (Y * Dimension + (X + X_Offset)) + 3)) := Grey;
+ Store (FLTK.Size_Type
+ (Channels * (Y * Dimension + (X + X_Offset)) + 4)) := 127;
end loop;
end if;
end loop;
diff --git a/test/color_chooser.adb b/test/color_chooser.adb
index b77283c..1c7537c 100644
--- a/test/color_chooser.adb
+++ b/test/color_chooser.adb
@@ -21,6 +21,7 @@ with
use type
FLTK.Color,
+ FLTK.Size_Type,
FLTK.Asks.Confirm_Result;
@@ -44,14 +45,14 @@ is
return FLTK.Color_Component_Array
is
X_Frac, Y_Frac : Long_Float;
- Offset : Integer;
+ Offset : FLTK.Size_Type;
begin
- return Data : FLTK.Color_Component_Array (1 .. W * H * 3) do
+ return Data : FLTK.Color_Component_Array (1 .. FLTK.Size_Type (W * H * 3)) do
for Y in 0 .. H - 1 loop
Y_Frac := Long_Float (Y) / Long_Float (H - 1);
for X in 0 .. W - 1 loop
X_Frac := Long_Float (X) / Long_Float (W - 1);
- Offset := 3 * (Y * W + X);
+ Offset := 3 * FLTK.Size_Type (Y * W + X);
Data (Offset + 1) :=
FLTK.Color_Component (255.0 * (1.0 - X_Frac) * (1.0 - Y_Frac));
Data (Offset + 2) :=