comp.lang.ada
 help / color / mirror / Atom feed
From: gautier_niouzes@hotmail.com
Subject: Re: zLibAda vs ZipAda (which should I use, if any)?
Date: Sat, 27 Aug 2016 12:15:48 -0700 (PDT)
Date: 2016-08-27T12:15:48-07:00	[thread overview]
Message-ID: <3a8cd248-f74a-423e-8a5d-2af6a4a5a9e8@googlegroups.com> (raw)
In-Reply-To: <5d5c2b37-148a-46e5-9b12-479253704595@googlegroups.com>

Le samedi 27 août 2016 18:31:30 UTC+2, Aurele a écrit :
> Hi Gautier, I think your GID packages will provide the services I need. Very well done by the way.  
> 
> Maybe you can save me some time and guide me on its use for my needs.  I've inserted some code below that show how I'll load the images from the zip file using Zip-Ada, I arrange the data (not shown), and then I need to call GID procedure to load as Handle.
> 
> Any comments or ideas? 
> 
> declare
> 
>   package ASU renames Ada.Strings.Unbounded;
> 
>   type Entry_ID is new Integer range -1..Integer'Last;
> 
>   type iEntry is record
>     Texture_ID : ZipFile.Entry_ID;
>     FullName   : Ada.Strings.Unbounded.Unbounded_String;
>     Directory  : Ada.Strings.Unbounded.Unbounded_String;
>     EntryName  : Ada.Strings.Unbounded.Unbounded_String;
>     Extension  : Ada.Strings.Unbounded.Unbounded_String;
>   end record;
>   type iEntryEntry_Ptr is access all ZipFile.iEntry;
> 
>   subtype iEntry_Array_Size is Entry_ID;
> 
>   type iEntry_Array is array ( iEntry_Array_Size range <> ) of aliased ZipFile.iEntry;
>   type iEntry_Array_Ptr is access all ZipFile.iEntry_Array;
> 
>   type Information is record
>     File_Location   : Ada.Strings.Unbounded.Unbounded_String;
>     File_Name       : Ada.Strings.Unbounded.Unbounded_String;
>     Total_Entries   : Natural;
>     Texture_Entries : Natural;
>     Data_Ptr        : ZipFile.iEntry_Array_Ptr;
>   end record;
>   type Information_Ptr is access all ZipFile.Information;
> 
>   Zip_File_Name         : constant String := "Textures.zip";
>   Zip_File_Entries      : iEntry_Array_Size;
> 
>   lpTexture_Array       : aliased iEntry_Array_Ptr;
>   lpTexture_Info        : aliased Information_Ptr
> 
>   Local_Index           : Entry_ID;
> 
>   ZipFileInfo           : Zip.Zip_Info;
>   FileType              : UnZip.Streams.Zipped_File_Type;
> 
> -----------------------------------------------------------------
> begin
> 
>   Zip.Load( ZipFileInfo, Zip_File_Name );
> 
>   Zip_File_Entries := iEntry_Array_Size( Zip.Entries( ZipFileInfo ) );
> 
>   lpTexture_Array  := new ZipFile.iEntry_Array( 1..Zip_File_Entries );
>   lpTexture_Info   := new ZipFile.Information;
> 
>   -- Scan procedure not shown here but is straight forward...
>   Scan( ZipFileInfo, FileName, Info_Ptr ); -- FILL INFO_PTR
> 
>   -- Simple test....  try to retrieve an image at index = 10
> 
>   Local_Index := 10; -- TEST: image at index = 10
> 
>   UnZip.Streams.Open
>     ( File         => FileType,
>       Archive_Info => ZipFileInfo,
>       Name  => ASU.To_String( Info_Ptr.Data_Ptr( Local_Index ).FullName ) 
>      );
> 
>   -- ???????????????????????????????????????????????????????
>   -- LoadImage is below, no idea yet what has to be done
> 
>   LoadImage( FileNeme => Info_Ptr.Data_Ptr( Local_Index ).EntryName,
>              FileExt  => Info_Ptr.Data_Ptr( Local_Index ).Extension,
>              FullName => Ada.Streams.Stream_IO.Stream_Access( UnZip.Streams.Stream( FileType ) ) );
> 
>   UnZip.Streams.Close( FileType );
> 
> end;
> 
> 
> -----------------------------------------------------------------
> - TBD: Call "GID" procedure to load image (DIB or BMP (bitmap))
> 
> type Hande is access all System.Address;  
> hBitmap : Hande := NULL;
> 
> procedure LoadImage ( FileName : Ada.Strings.Unbounded.Unbounded_String;
>                       FileExt  : Ada.Strings.Unbounded.Unbounded_String;
>                       FullName : Ada.Strings.Unbounded.Unbounded_String ) is
> begin
>                    -- --------------------------
>   hBitmap := ?;    -- Call GID directly here ??? Steps ????
>                    -----------------------------
> end LoadImage;
> 
> -----------------------------------------------------------------
> 
> Cheers and thanks
> Aurele

I'm just copy-pasting useful things from the To_BMP example, which will be ok for a Windows bitmap. I skip the image rotation stuff to simplify...

  type Byte_Array is array(Integer range <>) of Unsigned_8;
  type p_Byte_Array is access Byte_Array;
  procedure Dispose is new Ada.Unchecked_Deallocation(Byte_Array, p_Byte_Array);

  img_buf: p_Byte_Array:= null;

  procedure Load_raw_image(
    image : in out GID.Image_descriptor;
    buffer: in out p_Byte_Array
  )
  is
    subtype Primary_color_range is Unsigned_8;
    subtype U16 is Unsigned_16;
    image_width: constant Positive:= GID.Pixel_width(image);
    image_height: constant Positive:= GID.Pixel_height(image);
    padded_line_size_x: constant Positive:=
      4 * Integer(Float'Ceiling(Float(image_width) * 3.0 / 4.0));
    padded_line_size_y: constant Positive:=
      4 * Integer(Float'Ceiling(Float(image_height) * 3.0 / 4.0));
    -- (in bytes)
    idx: Integer;
    --
    procedure Set_X_Y (x, y: Natural) is
    pragma Inline(Set_X_Y);
    begin
      idx:= 3 * x + padded_line_size_x * y;
    end Set_X_Y;
    --
    procedure Put_Pixel_without_bkg (
      red, green, blue : Primary_color_range;
      alpha            : Primary_color_range
    )
    is
    pragma Inline(Put_Pixel_without_bkg);
    pragma Warnings(off, alpha); -- alpha is just ignored
    begin
      buffer(idx..idx+2):= (blue, green, red);
      -- GID requires us to look to next pixel for next time:
      idx:= idx + 3;
    end Put_Pixel_without_bkg;
    --
    procedure BMP24_Load_without_bkg is
      new GID.Load_image_contents(
        Primary_color_range,
        Set_X_Y,
        Put_Pixel_without_bkg,
        Feedback,
        GID.fast
      );
    next_frame: Ada.Calendar.Day_Duration;
  begin
    Dispose(buffer);
    buffer:= new Byte_Array(0..padded_line_size_x * GID.Pixel_height(image) - 1);
    BMP24_Load_without_bkg(image, next_frame);
  end Load_raw_image;

...
    i: GID.Image_descriptor;
  begin
    GID.Load_image_header(i, Your_nice_stream_Access.all, True);
    Load_raw_image(i, img_buf);
  end;

Now you surely know better how to let the image buffer (img_buf) meet the hBitmap handle (some Windows-ish bureaucracy ;-) )
_________________________ 
Gautier's Ada programming 
http://gautiersblog.blogspot.com/search/label/Ada 
NB: follow the above link for a valid e-mail address 

  reply	other threads:[~2016-08-27 19:15 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-25 20:17 zLibAda vs ZipAda (which should I use, if any)? Aurele
2016-08-25 21:02 ` Qun-Ying
2016-08-25 21:33 ` Jeffrey R. Carter
2016-08-25 22:07 ` Aurele
2016-08-25 23:07 ` Aurele
2016-08-25 23:43   ` gautier_niouzes
2016-08-25 23:55     ` Aurele
2016-08-26  0:18       ` gautier_niouzes
2016-08-26  1:44         ` Aurele
2016-08-26 12:36           ` gautier_niouzes
2016-08-26 14:23             ` Aurele
2016-08-26 15:16               ` gautier_niouzes
2016-08-26 15:46                 ` Jeffrey R. Carter
2016-08-26 16:05                 ` Aurele
2016-08-26 23:04                   ` Aurele
2016-08-27  5:30                     ` gautier_niouzes
2016-08-27 11:52                       ` Aurele
2016-08-27 16:31                         ` Aurele
2016-08-27 19:15                           ` gautier_niouzes [this message]
2016-08-27 19:33 ` Aurele
2016-08-27 20:16   ` Aurele
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox