From 4f813935e3a81b46f509883dfdb5abe7737fb58a Mon Sep 17 00:00:00 2001 From: Vovanium Date: Tue, 17 May 2022 13:14:30 +0300 Subject: [PATCH] + SDL surface / raster conversion --- examples/hello_world_sdl.adb | 7 +++++ .../sdl/video-backends-sdl-surfaces.adb | 30 +++++++++++++++++++ .../sdl/video-backends-sdl-surfaces.ads | 15 ++++++++++ 3 files changed, 52 insertions(+) create mode 100644 source/backends/sdl/video-backends-sdl-surfaces.adb diff --git a/examples/hello_world_sdl.adb b/examples/hello_world_sdl.adb index f0203f7..0b56381 100644 --- a/examples/hello_world_sdl.adb +++ b/examples/hello_world_sdl.adb @@ -1,3 +1,5 @@ +with Ada.Text_IO, Ada.Integer_Text_IO; +use Ada.Text_IO, Ada.Integer_Text_IO; with Interfaces.C; with Video.Backends.SDL.Windows; with Video.Backends.SDL.Surfaces; @@ -15,5 +17,10 @@ begin Width => Screen_Width, Height => Screen_Height); Surf := Windows.Get_Window_Surface (Wnd); + Put (Integer (Surf.w)); Put (" × "); Put (Integer (Surf.h)); New_Line; + Put ("Pitch: "); Put (Integer (Surf.pitch)); New_Line; + Put ("Bits per pixel: "); Put (Integer (Surf.format.Bits_Per_Pixel)); New_Line; + Put ("Bytes per pixel: "); Put (Integer (Surf.format.Bytes_Per_Pixel)); New_Line; + Err := Message_Boxes.Show_Message_Box (Title => "Hello World", Message => "Greetz!"); end Hello_World_SDL; diff --git a/source/backends/sdl/video-backends-sdl-surfaces.adb b/source/backends/sdl/video-backends-sdl-surfaces.adb new file mode 100644 index 0000000..edd8cda --- /dev/null +++ b/source/backends/sdl/video-backends-sdl-surfaces.adb @@ -0,0 +1,30 @@ +with Interfaces.C.Pointers; +with System.Storage_Elements; +use System.Storage_Elements; + +package body Video.Backends.SDL.Surfaces is + + package body Raster_Conversions is + + type Pixel_Array is array (Integer range <>) of Pixel; + + procedure Copy ( + Source : in Raster; + Target : in out Surface) + is + begin + for Y in Source'Range (1) loop + declare + Line : Pixel_Array (Source'Range (2)) with + Import, Address => Target.Pixels + + Storage_Offset (Y - Source'First (1)); + begin + for X in Source'Range (2) loop + Line (X) := Source (Y, X); + end loop; + end; + end loop; + end; + end Raster_Conversions; + +end Video.Backends.SDL.Surfaces; diff --git a/source/backends/sdl/video-backends-sdl-surfaces.ads b/source/backends/sdl/video-backends-sdl-surfaces.ads index c1c9a10..0ef0f90 100644 --- a/source/backends/sdl/video-backends-sdl-surfaces.ads +++ b/source/backends/sdl/video-backends-sdl-surfaces.ads @@ -23,4 +23,19 @@ package Video.Backends.SDL.Surfaces is type Surface_Access is access all Surface with Convention => C; + generic + type Pixel is private; + type Raster is array (Integer range <>, Integer range <>) of aliased Pixel; + Default : Pixel; + package Raster_Conversions is + procedure Copy ( + Source : in Raster; + Target : in out Surface) + with + Pre => Source'Length (1) = Target.h + and Source'Length (2) = Target.w + and Target.format.Bits_Per_Pixel = Pixel'Size; + -- Copy video raster to sdl surface. Source and target should have same dimensions + end Raster_Conversions; + end Video.Backends.SDL.Surfaces;