>refactor< images

This commit is contained in:
Vovanium 2023-08-04 03:02:53 +03:00
parent 8c81158ba9
commit 2f392b68f1
11 changed files with 227 additions and 211 deletions

View File

@ -0,0 +1,40 @@
with Video.Images.Raster.Generic_Fixed;
with Video.Colors.Maps.Generic_Fixed;
with Video.Colors.Maps.Shared_Palettes;
package Video.Images.Indexed.Fixed is
generic
with package Base is new Indexed_Base (<>);
package Generic_Fixed is
package With_Own_Palette is new Raster.Generic_Fixed (
Raster_Images => Base.Raster,
Parent => Base.Own.Base_Color_Map,
Map_Color => Base.Own.Map_Color);
type Image_with_Own_Palette is new With_Own_Palette.Image with null record;
--
package With_Shared_Palette is new Raster.Generic_Fixed (
Raster_Images => Base.Raster,
Parent => Base.Shared.Base_Color_Map,
Map_Color => Base.Shared.Map_Color);
type Image_with_Shared_Palette is new With_Shared_Palette.Image with null record;
end Generic_Fixed;
--package Fixed_Index_1 is new Generic_Fixed (
-- Base => Index_1_Base);
--package Fixed_Index_4 is new Generic_Fixed (
-- Base => Index_4_Base);
-- Above does not compile due to bug in GNAT
package Fixed_Index_8 is new Generic_Fixed (
Base => Index_8_Base);
end Video.Images.Indexed.Fixed;

View File

@ -0,0 +1,38 @@
with Video.Colors.Maps.Generic_Fixed;
with Video.Colors.Maps.Shared_Palettes;
with Video.Images.Raster.Generic_Unbounded;
package Video.Images.Indexed.Unbounded is
generic
with package Base is new Indexed_Base (<>);
package Generic_Unbounded is
package With_Own_Palette is new Raster.Generic_Unbounded (
Raster_Images => Base.Raster,
Parent => Base.Own.Base_Color_Map,
Map_Color => Base.Own.Map_Color);
type Image_with_Own_Palette is new With_Own_Palette.Image with null record;
--
package With_Shared_Palette is new Raster.Generic_Unbounded (
Raster_Images => Base.Raster,
Parent => Base.Shared.Base_Color_Map,
Map_Color => Base.Shared.Map_Color);
type Image_with_Shared_Palette is new With_Shared_Palette.Image with null record;
end Generic_Unbounded;
package Unbounded_Index_1 is new Generic_Unbounded (
Base => Index_1_Base);
package Unbounded_Index_4 is new Generic_Unbounded (
Base => Index_4_Base);
package Unbounded_Index_8 is new Generic_Unbounded (
Base => Index_8_Base);
end Video.Images.Indexed.Unbounded;

View File

@ -0,0 +1,71 @@
with Ada.Finalization;
use Ada.Finalization;
with Video.Pixels.Indexed, Video.Colors.Palettes, Video.Colors.Maps;
use Video.Pixels.Indexed, Video.Colors.Palettes, Video.Colors.Maps;
with Video.Colors.Maps.Generic_Fixed;
with Video.Colors.Maps.Shared_Palettes;
package Video.Images.Indexed is
type Indexed_Image is limited interface and Raster_Image and Constant_Color_Map;
function Pixel_Index (
Source : Indexed_Image;
A : Point)
return Color_Index is abstract;
-- A pixel index value, an untyped way to read it
-- note: Function is named `Pixel_Index` to avoid confusing with `Pixel` group
-- As it returns integer type it can break type safety
--
generic
type Pixel_Type is mod <>;
type Array_Type is array (Integer range <>, Integer range <>) of Pixel_Type;
package Indexed_Base is
package Raster is new Generic_Raster (
Pixel_Type => Pixel_Type,
Array_Type => Array_Type,
Parent => Indexed_Image);
package Fixed_Color_Maps is new Colors.Maps.Generic_Fixed (0, Pixel_Type'Modulus - 1);
generic
type Parent_Color_Map is new Video.Colors.Maps.Constant_Color_Map with private;
package Images_with_Color_Map is
type Base_Color_Map is abstract new Parent_Color_Map and Raster.Image with null record;
function Map_Color (Map : Base_Color_Map; Pixel : Pixel_Type) return Color
is (Map.Map_Color (Color_Index (Pixel))) with Inline;
overriding function Pixel_Index (
Source : Base_Color_Map;
A : Point)
return Color_Index
is (Color_Index (Pixel_Type'(Raster.Image'Class (Source).Pixel (A))));
end Images_with_Color_Map;
package Own is new Images_with_Color_Map (
Parent_Color_Map => Fixed_Color_Maps.Fixed_Color_Map);
package Shared is new Images_with_Color_Map (
Parent_Color_Map => Colors.Maps.Shared_Palettes.Constant_Shared_Palette);
end Indexed_Base;
package Index_1_Base is new Indexed_Base (
Pixel_Type => Index_1_Pixel,
Array_Type => Index_1_Array);
package Index_4_Base is new Indexed_Base (
Pixel_Type => Index_4_Pixel,
Array_Type => Index_4_Array);
package Index_8_Base is new Indexed_Base (
Pixel_Type => Index_8_Pixel,
Array_Type => Index_8_Array);
end Video.Images.Indexed;

View File

@ -1,74 +0,0 @@
with Video.Images.Raster.Generic_Fixed;
with Video.Colors.Maps.Generic_Fixed;
with Video.Colors.Maps.Shared_Palettes;
package Video.Images.Raster.Indexed.Fixed is
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 (
Pixel_Type => Pixel_Type,
Array_Type => Array_Type,
Parent => Indexed_Raster_Image);
package Generic_Fixed is
Last_Color_Index : constant Color_Index := Color_Index (Pixel_Type'Modulus - 1);
-- Last color index. Used for palette bounds
generic
type Parent_Color_Map is new Video.Colors.Maps.Constant_Color_Map with private;
package Images_with_Color_Map is
type Base_Color_Map is abstract new Parent_Color_Map with null record;
function Map_Color (Map : Base_Color_Map; Pixel : Pixel_Type) return Color
is (Map.Map_Color (Color_Index (Pixel))) with Inline;
package Image_Base is new Raster.Generic_Fixed (
Raster_Images => Raster_Images,
Parent => Base_Color_Map);
type Image is new Image_Base.Image with null record;
-- An actual type
overriding function Pixel_Index (
Source : Image;
A : Point)
return Natural
is (Integer (Source.Pixels (A.Y, A.X)));
end Images_with_Color_Map;
--
package Fixed_Color_Maps is new Colors.Maps.Generic_Fixed (0, Last_Color_Index);
package With_Own_Palette is new Images_with_Color_Map (Fixed_Color_Maps.Fixed_Color_Map);
subtype Image_with_Own_Palette is With_Own_Palette.Image;
--
package With_Shared_Palette is new Images_with_Color_Map (
Colors.Maps.Shared_Palettes.Constant_Shared_Palette);
subtype Image_with_Shared_Palette is With_Shared_Palette.Image;
end Generic_Fixed;
-- package Fixed_Index_1 is new Fixed_Indexed (
-- Pixel_Type => Index_1_Pixel,
-- Array_Type => Index_1_Array);
-- package Fixed_Index_4 is new Fixed_Indexed (
-- Pixel_Type => Index_4_Pixel,
-- Array_Type => Index_4_Array);
-- note: Due to bug in current GNAT above won't compile
package Fixed_Index_8 is new Generic_Fixed (
Pixel_Type => Index_8_Pixel,
Array_Type => Index_8_Array,
Raster_Images => Index_8);
end Video.Images.Raster.Indexed.Fixed;

View File

@ -1,74 +0,0 @@
with Video.Colors.Maps.Generic_Fixed;
with Video.Colors.Maps.Shared_Palettes;
with Video.Images.Raster.Generic_Unbounded;
package Video.Images.Raster.Indexed.Unbounded is
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 (
Pixel_Type => Pixel_Type,
Array_Type => Array_Type,
Parent => Indexed_Raster_Image);
package Generic_Unbounded is
Last_Color_Index : constant Color_Index := Color_Index (Pixel_Type'Modulus - 1);
-- Last color index. Used for palette bounds
generic
type Parent_Color_Map is new Colors.Maps.Constant_Color_Map with private;
package Images_with_Color_Map is
type Base_Color_Map is abstract new Parent_Color_Map with null record;
function Map_Color (Map : Base_Color_Map; Pixel : Pixel_Type) return Color
is (Map.Map_Color (Color_Index (Pixel))) with Inline;
package Image_Base is new Raster.Generic_Unbounded (
Raster_Images => Raster_Images,
Parent => Base_Color_Map);
type Image is new Image_Base.Image with null record;
-- An actual type
overriding function Pixel_Index (
Source : Image;
A : Point)
return Color_Index
is (Color_Index (Pixel_Type'(Source.Pixel (A))));
end Images_with_Color_Map;
--
package Fixed_Color_Maps is new Colors.Maps.Generic_Fixed (0, Last_Color_Index);
package With_Own_Palette is new Images_with_Color_Map (Fixed_Color_Maps.Fixed_Color_Map);
subtype Image_with_Own_Palette is With_Own_Palette.Image;
--
package With_Shared_Palette is new Images_with_Color_Map (
Colors.Maps.Shared_Palettes.Constant_Shared_Palette);
subtype Image_with_Shared_Palette is With_Shared_Palette.Image;
end Generic_Unbounded;
package Unbounded_Index_1 is new Generic_Unbounded (
Pixel_Type => Index_1_Pixel,
Array_Type => Index_1_Array,
Raster_Images => Index_1);
package Unbounded_Index_4 is new Generic_Unbounded (
Pixel_Type => Index_4_Pixel,
Array_Type => Index_4_Array,
Raster_Images => Index_4);
package Unbounded_Index_8 is new Generic_Unbounded (
Pixel_Type => Index_8_Pixel,
Array_Type => Index_8_Array,
Raster_Images => Index_8);
end Video.Images.Raster.Indexed.Unbounded;

View File

@ -1,36 +0,0 @@
with Ada.Finalization;
use Ada.Finalization;
with Video.Pixels.Indexed, Video.Colors.Palettes, Video.Colors.Maps;
use Video.Pixels.Indexed, Video.Colors.Palettes, Video.Colors.Maps;
package Video.Images.Raster.Indexed is
type Indexed_Raster_Image is limited interface and Raster_Image and Constant_Color_Map;
function Pixel_Index (
Source : Indexed_Raster_Image;
A : Point)
return Color_Index is abstract;
-- A pixel index value, an untyped way to read it
-- note: Function is named `Pixel_Index` to avoid confusing with `Pixel` group
-- As it returns integer type it can break type safety
--
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 (
Pixel_Type => Index_4_Pixel,
Array_Type => Index_4_Array,
Parent => Indexed_Raster_Image);
package Index_8 is new Generic_Raster (
Pixel_Type => Index_8_Pixel,
Array_Type => Index_8_Array,
Parent => Indexed_Raster_Image);
end Video.Images.Raster.Indexed;

View File

@ -1,10 +0,0 @@
with Video.Images.Raster.Generic_Fixed;
package Video.Images.Raster.RGB.Fixed is
package Fixed_RGB888 is new Raster.Generic_Fixed (
Raster_Images => RGB888,
Parent => RGB888_Base.Raster_Image_Base,
Map_Color => RGB888_Base.Map_Color);
end Video.Images.Raster.RGB.Fixed;

View File

@ -1,15 +0,0 @@
with Video.Images.Raster.Generic_Unbounded;
package Video.Images.Raster.RGB.Unbounded is
package Unbounded_RGB565 is new Generic_Unbounded (
Raster_Images => RGB565,
Parent => RGB565_Base.Raster_Image_Base,
Map_Color => RGB565_Base.Map_Color);
package Unbounded_RGB888 is new Generic_Unbounded (
Raster_Images => RGB888,
Parent => RGB888_Base.Raster_Image_Base,
Map_Color => RGB888_Base.Map_Color);
end Video.Images.Raster.RGB.Unbounded;

View File

@ -0,0 +1,35 @@
with Video.Images.Raster.Generic_Fixed;
package Video.Images.RGB.Fixed is
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 (
Pixel_Type => Pixel_Type,
Array_Type => Array_Type,
Parent => RGB_Raster_Image);
with package Base is new RGB.Base (
Pixel_Type => Pixel_Type,
To_Color => To_Color);
package Generic_Fixed is
package Fixed_Base is new Raster.Generic_Fixed (
Raster_Images => Raster_Images,
Parent => Base.Raster_Image_Base,
Map_Color => Base.Map_Color);
-- Generic instantiation
type Image is new Fixed_Base.Image with null record;
-- Actual Unbounded RGB Image
end Generic_Fixed;
package Fixed_RGB888 is new Generic_Fixed (
Pixel_Type => RGB888_Pixel,
Array_Type => RGB888_Array,
Raster_Images => RGB888,
Base => RGB888_Base);
end Video.Images.RGB.Fixed;

View File

@ -0,0 +1,41 @@
with Video.Images.Raster.Generic_Unbounded;
package Video.Images.RGB.Unbounded is
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 (
Pixel_Type => Pixel_Type,
Array_Type => Array_Type,
Parent => RGB_Raster_Image);
with package Base is new RGB.Base (
Pixel_Type => Pixel_Type,
To_Color => To_Color);
package Generic_Unbounded is
package Unbounded_Base is new Raster.Generic_Unbounded (
Raster_Images => Raster_Images,
Parent => Base.Raster_Image_Base,
Map_Color => Base.Map_Color);
-- Generic instantiation
type Image is new Unbounded_Base.Image with null record;
-- Actual Unbounded RGB Image
end Generic_Unbounded;
package Unbounded_RGB565 is new Generic_Unbounded (
Pixel_Type => RGB565_Pixel,
Array_Type => RGB565_Array,
Raster_Images => RGB565,
Base => RGB565_Base);
package Unbounded_RGB888 is new Generic_Unbounded (
Pixel_Type => RGB888_Pixel,
Array_Type => RGB888_Array,
Raster_Images => RGB888,
Base => RGB888_Base);
end Video.Images.RGB.Unbounded;

View File

@ -4,7 +4,7 @@
with Video.Pixels.RGB;
use Video.Pixels.RGB;
package Video.Images.Raster.RGB is
package Video.Images.RGB is
type RGB_Raster_Image is limited interface and Raster_Image;
@ -36,4 +36,4 @@ package Video.Images.Raster.RGB is
package RGB888_Base is new Base (
Pixel_Type => RGB888_Pixel);
end Video.Images.Raster.RGB;
end Video.Images.RGB;