Menu

#23 Add support to XPM parser.

1.2
closed
Blady
None
2015-08-02
2015-08-01
Blady
No

Hello,

When translating Linxtris from GTKAda to Gnoga, I needed to read some XPM files. Whereas it is present in Components included in Gnoga but not built.
So I propose to add it to Makefile, as modified in attached patch file.

For convenient purpose I propose to add a procedure to read and convert XPM file into Image data:
procedure New_From_XPM (Image : out Pixel_Data_Access; File_Name : String) is
use Parsers.Multiline_Source.XPM;
use Parsers.Multiline_Source.Text_IO;
use Ada.Text_IO;
function To_Red
(Value : RGB_Color) return Gnoga.Types.Color_Type is
(Gnoga.Types.Color_Type (Value / 16#10000#));
function To_Green
(Value : RGB_Color) return Gnoga.Types.Color_Type is
(Gnoga.Types.Color_Type ((Value mod 16#10000#) / 16#100#));
function To_Blue
(Value : RGB_Color) return Gnoga.Types.Color_Type is
(Gnoga.Types.Color_Type (Value mod 16#100#));
XPM_File : aliased File_Type;
begin
Open (XPM_File, In_File, File_Name);
declare
XPM_Source : aliased Source (XPM_File'Access);
XPM_Header : constant Descriptor := Get (XPM_Source'Access);
XMP_Map : constant Color_Tables.Table := Get (XPM_Source'Access, XPM_Header);
XPM_Image : constant Pixel_Buffer := Get (XPM_Source'Access, XPM_Header, XMP_Map);
begin
Image := new Gnoga.Types.Pixel_Data_Type (1 .. XPM_Header.Width, 1 .. XPM_Header.Height);
for X in Image'Range (1) loop
for Y in Image'Range (2) loop
Image (X, Y) :=
(To_Red (XPM_Image (X, Y)),
To_Green (XPM_Image (X, Y)),
To_Blue (XPM_Image (X, Y)),
Alpha => 255);
end loop;
end loop;
end;
Close (XPM_File);
end New_From_XPM;

Note: I'm not sure of the good choice of orientation between X and Y axis of XPM versus Gnoga Image.

HTH, Pascal.

1 Attachments

Discussion

  • David Botton

    David Botton - 2015-08-02
    • assigned_to: Blady
    • Milestone: 1.0 --> 1.2
     
  • David Botton

    David Botton - 2015-08-02

    Looks reasonable to me.

     
  • Blady

    Blady - 2015-08-02
    • status: open --> closed
     
  • Blady

    Blady - 2015-08-02

    XPM parser support added with commit 23a393b.

     

Log in to post a comment.