From b0b1ec003d0a41ed3d2951757379889cded7f27b Mon Sep 17 00:00:00 2001 From: Vovanium Date: Thu, 3 Aug 2023 18:55:45 +0300 Subject: [PATCH] * Some cleanup for Image types --- source/base/video-images-raster-argb.ads | 6 +- .../video-images-raster-generic_fixed.ads | 2 +- .../video-images-raster-generic_unbounded.ads | 2 +- ...eo-images-raster-indexed-generic_fixed.ads | 2 +- ...mages-raster-indexed-generic_unbounded.ads | 2 +- source/base/video-images-raster-indexed.adb | 14 ----- source/base/video-images-raster-indexed.ads | 28 ++------- .../video-images-raster-rgb-generic_fixed.ads | 2 +- ...eo-images-raster-rgb-generic_unbounded.ads | 2 +- source/base/video-images-raster-rgb.ads | 4 +- source/base/video-images-raster.ads | 56 ----------------- source/base/video-images.ads | 61 +++++++++++++++++++ 12 files changed, 76 insertions(+), 105 deletions(-) delete mode 100644 source/base/video-images-raster-indexed.adb diff --git a/source/base/video-images-raster-argb.ads b/source/base/video-images-raster-argb.ads index 9b7dcd3..79a4fa0 100644 --- a/source/base/video-images-raster-argb.ads +++ b/source/base/video-images-raster-argb.ads @@ -8,17 +8,17 @@ package Video.Images.Raster.ARGB is type ARGB_Raster_Image is limited interface and Raster_Image; - package ARGB1555 is new Generic_Raster_Images ( + package ARGB1555 is new Generic_Raster ( Pixel_Type => ARGB1555_Pixel, Array_Type => ARGB1555_Array, Parent => ARGB_Raster_Image); - package ARGB4444 is new Generic_Raster_Images ( + package ARGB4444 is new Generic_Raster ( Pixel_Type => ARGB4444_Pixel, Array_Type => ARGB4444_Array, Parent => ARGB_Raster_Image); - package ARGB8888 is new Generic_Raster_Images ( + package ARGB8888 is new Generic_Raster ( Pixel_Type => ARGB8888_Pixel, Array_Type => ARGB8888_Array, Parent => ARGB_Raster_Image); diff --git a/source/base/video-images-raster-generic_fixed.ads b/source/base/video-images-raster-generic_fixed.ads index 49abdd6..119eb2b 100644 --- a/source/base/video-images-raster-generic_fixed.ads +++ b/source/base/video-images-raster-generic_fixed.ads @@ -3,7 +3,7 @@ -- generic - with package Raster_Images is new Generic_Raster_Images (<>); + with package Raster_Images is new Generic_Raster (<>); type Parent is abstract tagged private; with function Map_Color (Map : Parent; Pixel : Raster_Images.Pixel_Type) return Color is <>; package Video.Images.Raster.Generic_Fixed is diff --git a/source/base/video-images-raster-generic_unbounded.ads b/source/base/video-images-raster-generic_unbounded.ads index d8bf4fc..294b60c 100644 --- a/source/base/video-images-raster-generic_unbounded.ads +++ b/source/base/video-images-raster-generic_unbounded.ads @@ -5,7 +5,7 @@ with Ada.Containers.Indefinite_Holders; with Video.Pixels.Generic_Holders; generic - with package Raster_Images is new Generic_Raster_Images (<>); + with package Raster_Images is new Generic_Raster (<>); type Parent is abstract tagged private; with function Map_Color (Map : Parent; Pixel : Raster_Images.Pixel_Type) return Color is <>; package Video.Images.Raster.Generic_Unbounded is diff --git a/source/base/video-images-raster-indexed-generic_fixed.ads b/source/base/video-images-raster-indexed-generic_fixed.ads index 76e4db9..d13b6f2 100644 --- a/source/base/video-images-raster-indexed-generic_fixed.ads +++ b/source/base/video-images-raster-indexed-generic_fixed.ads @@ -8,7 +8,7 @@ with Video.Colors.Maps.Shared_Palettes; generic type Pixel_Type is mod <>; type Array_Type is array (Integer range <>, Integer range <>) of Pixel_Type; - with package Raster_Images is new Generic_Raster_Images ( + with package Raster_Images is new Generic_Raster ( Pixel_Type => Pixel_Type, Array_Type => Array_Type, Parent => Indexed_Raster_Image); diff --git a/source/base/video-images-raster-indexed-generic_unbounded.ads b/source/base/video-images-raster-indexed-generic_unbounded.ads index b1d18b4..5f94fc9 100644 --- a/source/base/video-images-raster-indexed-generic_unbounded.ads +++ b/source/base/video-images-raster-indexed-generic_unbounded.ads @@ -7,7 +7,7 @@ with Video.Images.Raster.Generic_Unbounded; generic type Pixel_Type is mod <>; type Array_Type is array (Integer range <>, Integer range <>) of Pixel_Type; - with package Raster_Images is new Generic_Raster_Images ( + with package Raster_Images is new Generic_Raster ( Pixel_Type => Pixel_Type, Array_Type => Array_Type, Parent => Indexed_Raster_Image); diff --git a/source/base/video-images-raster-indexed.adb b/source/base/video-images-raster-indexed.adb deleted file mode 100644 index 5103f0b..0000000 --- a/source/base/video-images-raster-indexed.adb +++ /dev/null @@ -1,14 +0,0 @@ -package body Video.Images.Raster.Indexed is - - function Map_Color ( - Source : Image_with_Shared_Palette; - Index : Color_Index) - return Color - is (Source.Color_Map (Index)); - - function To_Palette ( - Source : Image_with_Shared_Palette) - return Palette - is (Source.Color_Map.all); - -end Video.Images.Raster.Indexed; \ No newline at end of file diff --git a/source/base/video-images-raster-indexed.ads b/source/base/video-images-raster-indexed.ads index 7c1f4e0..e316293 100644 --- a/source/base/video-images-raster-indexed.ads +++ b/source/base/video-images-raster-indexed.ads @@ -13,44 +13,24 @@ package Video.Images.Raster.Indexed is return Color_Index is abstract; -- A pixel index value, an untyped way to read it - -- note: Function is named `Pixel_Index` to avoid mixed it with `Pixel` group + -- note: Function is named `Pixel_Index` to avoid confusing with `Pixel` group -- As it returns integer type it can break type safety - type Image_with_Shared_Palette is abstract new Controlled and Indexed_Raster_Image with private; - -- Base for Image using externally provided palette - - -- Descend from controlled: there likely to be controlled types in the class - - overriding function Map_Color ( - Source : Image_with_Shared_Palette; - Index : Color_Index) - return Color; - - function To_Palette ( - Source : Image_with_Shared_Palette) - return Palette; - -- - package Index_1 is new Generic_Raster_Images ( + package Index_1 is new Generic_Raster ( Pixel_Type => Index_1_Pixel, Array_Type => Index_1_Array, Parent => Indexed_Raster_Image); - package Index_4 is new Generic_Raster_Images ( + package Index_4 is new Generic_Raster ( Pixel_Type => Index_4_Pixel, Array_Type => Index_4_Array, Parent => Indexed_Raster_Image); - package Index_8 is new Generic_Raster_Images ( + package Index_8 is new Generic_Raster ( Pixel_Type => Index_8_Pixel, Array_Type => Index_8_Array, Parent => Indexed_Raster_Image); -private - - type Image_with_Shared_Palette is abstract new Controlled and Indexed_Raster_Image with record - Color_Map : access constant Palette; - end record; - end Video.Images.Raster.Indexed; diff --git a/source/base/video-images-raster-rgb-generic_fixed.ads b/source/base/video-images-raster-rgb-generic_fixed.ads index 4a53010..c6fb451 100644 --- a/source/base/video-images-raster-rgb-generic_fixed.ads +++ b/source/base/video-images-raster-rgb-generic_fixed.ads @@ -7,7 +7,7 @@ generic type Pixel_Type is private; type Array_Type is array (Integer range <>, Integer range <>) of Pixel_Type; with function To_Color (Pixel : Pixel_Type) return Color is <>; - with package Raster_Images is new Generic_Raster_Images ( + with package Raster_Images is new Generic_Raster ( Pixel_Type => Pixel_Type, Array_Type => Array_Type, Parent => RGB_Raster_Image); diff --git a/source/base/video-images-raster-rgb-generic_unbounded.ads b/source/base/video-images-raster-rgb-generic_unbounded.ads index a081e0f..803b9ce 100644 --- a/source/base/video-images-raster-rgb-generic_unbounded.ads +++ b/source/base/video-images-raster-rgb-generic_unbounded.ads @@ -7,7 +7,7 @@ generic type Pixel_Type is private; type Array_Type is array (Integer range <>, Integer range <>) of Pixel_Type; with function To_Color (Pixel : Pixel_Type) return Color is <>; - with package Raster_Images is new Generic_Raster_Images ( + with package Raster_Images is new Generic_Raster ( Pixel_Type => Pixel_Type, Array_Type => Array_Type, Parent => RGB_Raster_Image); diff --git a/source/base/video-images-raster-rgb.ads b/source/base/video-images-raster-rgb.ads index f92afe3..7bb32dd 100644 --- a/source/base/video-images-raster-rgb.ads +++ b/source/base/video-images-raster-rgb.ads @@ -8,12 +8,12 @@ package Video.Images.Raster.RGB is type RGB_Raster_Image is limited interface and Raster_Image; - package RGB565 is new Generic_Raster_Images ( + package RGB565 is new Generic_Raster ( Pixel_Type => RGB565_Pixel, Array_Type => RGB565_Array, Parent => RGB_Raster_Image); - package RGB888 is new Generic_Raster_Images ( + package RGB888 is new Generic_Raster ( Pixel_Type => RGB888_Pixel, Array_Type => RGB888_Array, Parent => RGB_Raster_Image); diff --git a/source/base/video-images-raster.ads b/source/base/video-images-raster.ads index 8dc586e..8cae953 100644 --- a/source/base/video-images-raster.ads +++ b/source/base/video-images-raster.ads @@ -2,63 +2,7 @@ -- Raster Image that is a regular grid of discrete pixels -- -with Video.Integer_Geometry, Video.Colors; -use Video.Integer_Geometry, Video.Colors; - package Video.Images.Raster is - type Raster_Image is limited interface and Image; - -- Root type for raster images - - function Bounding_Box ( - Source : Raster_Image) - return Box is abstract; - -- Raster bounds in pixels - - function Pixel ( - Source : Raster_Image; - A : Point) - return Color is abstract; - -- Color of an individual pixel - - -- A helper generic package to keep types with the same format togeter - - generic - type Pixel_Type is private; - type Array_Type is array (Integer range <>, Integer range <>) of Pixel_Type; - type Parent is limited interface and Raster_Image; - package Generic_Raster_Images is - - -- Alias them so external code can use them - - type Image is limited interface and Parent; - -- A raster image those pixel type is defined - - --function Map_Color ( - -- Source : Image; - -- Pixel : Pixel_Type) return Color is abstract; - - function Pixel ( - Source : Image; - A : Point) return Pixel_Type is abstract; - -- Get a single pixel - - procedure Query_Raster ( - Source : in Image; - Query : not null access procedure (R : in Array_Type)) is abstract; - -- Query actual raster (maybe by chunks, seee below) - - procedure Process_Raster ( - Target : in out Image; - Process : not null access procedure (R : in out Array_Type)) is null; - -- Modify actual raster. Might be null for images that are not modifiable. - -- Non modifiable image could be declared constant so this call will not compile - - -- If Raster is not used as the main image storage, these subprograms - -- may split the data into chunks and call Query/Process several times. - -- One time per chuunk. Chunk size could generally depend on available RAM - -- for temporary storage. - - end Generic_Raster_Images; end Video.Images.Raster; diff --git a/source/base/video-images.ads b/source/base/video-images.ads index dde907c..5667394 100644 --- a/source/base/video-images.ads +++ b/source/base/video-images.ads @@ -1,10 +1,71 @@ -- -- Handling for images, say sources of graphic information. -- +with Video.Integer_Geometry, Video.Colors; +use Video.Integer_Geometry, Video.Colors; + package Video.Images with Pure is type Image is limited interface; -- The interface for image -- (Not file format, but vector/raster, various pixel types etc.) + function Bounding_Box ( + Source : Image) + return Box is abstract; + -- Image bounds in native (whatever it means) resolution + + function Pixel ( + Source : Image; + A : Point) + return Color is abstract; + -- Color of an individual pixel in native resolution + -- Generally it is an average color for (X .. X + 1, T .. Y + 1) square + + type Raster_Image is limited interface and Image; + -- Root type for raster images + + -- A helper generic package to keep types with the same format togeter + + generic + type Pixel_Type is private; + type Array_Type is array (Integer range <>, Integer range <>) of Pixel_Type; + type Parent is limited interface and Raster_Image; + package Generic_Raster is + + -- Alias them so external code can use them + + -- Passing Parent allow added level of hierarchy + -- Indexed, RGB etc images are grouped + + type Image is limited interface and Parent; + -- A raster image those pixel type is defined + + --function Map_Color ( + -- Source : Image; + -- Pixel : Pixel_Type) return Color is abstract; + + function Pixel ( + Source : Image; + A : Point) return Pixel_Type is abstract; + -- Get a single pixel + + procedure Query_Raster ( + Source : in Image; + Query : not null access procedure (R : in Array_Type)) is abstract; + -- Query actual raster (maybe by chunks, seee below) + + procedure Process_Raster ( + Target : in out Image; + Process : not null access procedure (R : in out Array_Type)) is null; + -- Modify actual raster. Might be null for images that are not modifiable. + -- Non modifiable image could be declared constant so this call will not compile + + -- If Raster is not used as the main image storage, these subprograms + -- may split the data into chunks and call Query/Process several times. + -- One time per chuunk. Chunk size could generally depend on available RAM + -- for temporary storage. + + end Generic_Raster; + end Video.Images;