comp.lang.ada
 help / color / mirror / Atom feed
* zLibAda vs ZipAda (which should I use, if any)?
@ 2016-08-25 20:17 Aurele
  2016-08-25 21:02 ` Qun-Ying
                   ` (4 more replies)
  0 siblings, 5 replies; 21+ messages in thread
From: Aurele @ 2016-08-25 20:17 UTC (permalink / raw)


Hi all, I'm faced with two possible options for reading/accessing the contents of a zip (.zip) file from within my Ada application. One option is to use zLibAda (by Dmitriy: http://zlib-ada.sourceforge.net/), the other is to use ZipAda (by Gautier: http://unzip-ada.sourceforge.net/). I have no idea how either one works and/or if they are appropriate for what I want to do!

On one hand, zLibAda (original zLib in C) is really well documented online but zLibAda is essentially a wrapper to the zLib DLL (I think). On the other, ZipAda is written in Ada, makes a clean compile, but it might not be entirely documented (essentially, I have no idea what I'm looking at/for).  

Anyway, my objective is to read a zip (.zip) file that contains compressed images (bmp, jpg, tga, etc...) and then build a list (table) of available images with its attributes (name... and/or I can determine its size separately if I have access, etc...).

I don't want to go through both zLibAda and ZipAda only to find out I'm on the wrong path so I was hopping someone might have used these package and mind  enlightening me on their use (assume the file I'm reading is "Images.zip", and has say 5 images of 250x250 pixels).

Thanks o/
Aurele


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  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
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 21+ messages in thread
From: Qun-Ying @ 2016-08-25 21:02 UTC (permalink / raw)


I haven't used both, but zLibAda is only a wrapper for zlib, which does 
not read zip file. Only ZipAda could read zip file.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 21+ messages in thread
From: Jeffrey R. Carter @ 2016-08-25 21:33 UTC (permalink / raw)


On 08/25/2016 01:17 PM, Aurele wrote:
> Hi all, I'm faced with two possible options for reading/accessing the
> contents of a zip (.zip) file from within my Ada application. One option is
> to use zLibAda (by Dmitriy: http://zlib-ada.sourceforge.net/), the other is
> to use ZipAda (by Gautier: http://unzip-ada.sourceforge.net/). I have no idea
> how either one works and/or if they are appropriate for what I want to do!
> 
> Anyway, my objective is to read a zip (.zip) file that contains compressed
> images (bmp, jpg, tga, etc...) and then build a list (table) of available
> images with its attributes (name... and/or I can determine its size
> separately if I have access, etc...).
> 
> I don't want to go through both zLibAda and ZipAda only to find out I'm on
> the wrong path so I was hopping someone might have used these package and
> mind  enlightening me on their use (assume the file I'm reading is
> "Images.zip", and has say 5 images of 250x250 pixels).

Looking at Zip-Ada package Zip, it seems that you can do what you want easily
(untested):

with Ada.Text_IO;
with Zip;

procedure Zip_Test is
   procedure Print_One (Name : in String);
   -- Outputs Name to Current_Output, followed by an EOL

   procedure Print_All is new Zip.Traverse (Action => Print_One);
   -- Outputs the names of all the entries in a Zip_Info to Current_Output,
   -- separated by EOLs

   procedure Print_One (Name : in String) is
      -- Empty
   begin -- Print_One
      Ada.Text_IO.Put_Line (Item => Name);
   end Print_One;

   Info : Zip.Zip_Info;
begin -- Zip_Test
   Zip.Load (Info => Info, From => "Images.zip");
   Ada.Text_IO.Put_Line (Integer'Image (Zip.Entries (Info) ) & " entries");
   Print_All (Info);
end Zip_Test;

You'd want to use an instantiation of Traverse_Verbose to get more information
about the entries than just their names.

-- 
Jeff Carter
"We call your door-opening request a silly thing."
Monty Python & the Holy Grail
17


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  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-27 19:33 ` Aurele
  4 siblings, 0 replies; 21+ messages in thread
From: Aurele @ 2016-08-25 22:07 UTC (permalink / raw)



Thanks Jeffery, it gets me started (understanding by osmosis :) ) 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  2016-08-25 20:17 zLibAda vs ZipAda (which should I use, if any)? Aurele
                   ` (2 preceding siblings ...)
  2016-08-25 22:07 ` Aurele
@ 2016-08-25 23:07 ` Aurele
  2016-08-25 23:43   ` gautier_niouzes
  2016-08-27 19:33 ` Aurele
  4 siblings, 1 reply; 21+ messages in thread
From: Aurele @ 2016-08-25 23:07 UTC (permalink / raw)


Looking at AdaZip a bit closer with the Info I received (thanks guys), I do not think AdaZip provide file type specific extraction services (thanks for the heads up Qunying"). I may have to write that myself as a layer over or in addition to ZipAda.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  2016-08-25 23:07 ` Aurele
@ 2016-08-25 23:43   ` gautier_niouzes
  2016-08-25 23:55     ` Aurele
  0 siblings, 1 reply; 21+ messages in thread
From: gautier_niouzes @ 2016-08-25 23:43 UTC (permalink / raw)


Le vendredi 26 août 2016 01:07:12 UTC+2, Aurele a écrit :
> Looking at AdaZip a bit closer with the Info I received (thanks guys), I do not think AdaZip provide file type specific extraction services (thanks for the heads up Qunying"). I may have to write that myself as a layer over or in addition to ZipAda.

Not sure about AdaZip, but Zip-Ada provides this service, and Jeff found which one: Traverse_Verbose.

  -- Same as Traverse, but Action gives also full technical informations
  -- about the compressed entry.
  generic
    with procedure Action(
      name             : String; -- 'name' is compressed entry's name
      file_index       : Zip_Streams.ZS_Index_Type;
      comp_size        : File_size_type;
      uncomp_size      : File_size_type;
      crc_32           : Interfaces.Unsigned_32;
      date_time        : Time;
      method           : PKZip_method;
      name_encoding    : Zip_name_encoding;
      read_only        : Boolean;
      encrypted_2_x    : Boolean; -- PKZip 2.x encryption
      user_code        : in out Integer
    );
  procedure Traverse_verbose( z: Zip_info );

You can find an example of scanning of the Zip file's directory for images here (using the non-verbose version):

http://globe3d.sf.net/g3d_html/globe_3d-textures__adb.htm#181_13

Cheers
Gautier


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  2016-08-25 23:43   ` gautier_niouzes
@ 2016-08-25 23:55     ` Aurele
  2016-08-26  0:18       ` gautier_niouzes
  0 siblings, 1 reply; 21+ messages in thread
From: Aurele @ 2016-08-25 23:55 UTC (permalink / raw)


> Not sure about AdaZip, but Zip-Ada provides this service, 


Hi Gautier, sorry about that. I meant ZipAda (or Zip-Ada). And thanks for the link, I'll definitely check it out !

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  2016-08-25 23:55     ` Aurele
@ 2016-08-26  0:18       ` gautier_niouzes
  2016-08-26  1:44         ` Aurele
  0 siblings, 1 reply; 21+ messages in thread
From: gautier_niouzes @ 2016-08-26  0:18 UTC (permalink / raw)


Le vendredi 26 août 2016 01:55:42 UTC+2, Aurele a écrit :
> > Not sure about AdaZip, but Zip-Ada provides this service, 
> 
> Hi Gautier, sorry about that. I meant ZipAda (or Zip-Ada). And thanks for the link, I'll definitely check it out !

Just kidding - I forgot the ";-)" ...


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  2016-08-26  0:18       ` gautier_niouzes
@ 2016-08-26  1:44         ` Aurele
  2016-08-26 12:36           ` gautier_niouzes
  0 siblings, 1 reply; 21+ messages in thread
From: Aurele @ 2016-08-26  1:44 UTC (permalink / raw)


Got Zip.Traverse_Verbose working ok, cool Zip-Ada feature!  Thanks.

I'm still trying to figure how to display the zip(ped) image directly and display the names of all entries in lists without, and the directory information. There is so much stuff in Zip-Ada, not sure where to turn sometime. I also noticed that GLOBE_3D interfaces with Zip-Ada but implements its own image handling routine.  I'll look at that next. Long way to go....


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  2016-08-26  1:44         ` Aurele
@ 2016-08-26 12:36           ` gautier_niouzes
  2016-08-26 14:23             ` Aurele
  0 siblings, 1 reply; 21+ messages in thread
From: gautier_niouzes @ 2016-08-26 12:36 UTC (permalink / raw)


> I'm still trying to figure how to display the zip(ped) image directly

By directly, do you mean without extracting the image as a file ?
In this case, it is possible with UnZip.Streams. Then you can use the Generic Image Decoder for decoding your image.

> and display the names of all entries in lists without,

Not clear without what, but displaying the names is done through Traverse or Traverse_Verbose.

> and the directory information. 

More specifically ?

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  2016-08-26 12:36           ` gautier_niouzes
@ 2016-08-26 14:23             ` Aurele
  2016-08-26 15:16               ` gautier_niouzes
  0 siblings, 1 reply; 21+ messages in thread
From: Aurele @ 2016-08-26 14:23 UTC (permalink / raw)


> In this case, it is possible with UnZip.Streams. 

I started looking at UnZip this morning. Thanks!    I looked at Globe_3D for an example but the UnZip function there seems tightly integrated with Globe_3D's drawing/GL setup features. Have you never considered formally documenting Zip-Ada?

> More specifically ?

Re the Traverse_Verbose information, for my requirement I mean, I'll need to filter out the directory and name information separately for listing (display) purpose (Zip entry: "texture\sky\blue.jpg" ==> "texture\sky\" and "blue", separately). 


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  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
  0 siblings, 2 replies; 21+ messages in thread
From: gautier_niouzes @ 2016-08-26 15:16 UTC (permalink / raw)


On Friday, August 26, 2016 at 4:23:11 PM UTC+2, Aurele wrote:
> > In this case, it is possible with UnZip.Streams. 
> 
> I started looking at UnZip this morning. Thanks!    I looked at Globe_3D for an example but the UnZip function there seems tightly integrated with Globe_3D's drawing/GL setup features.

I'm afraid you are confused.
The GLOBE_3D library is using the Zip-Ada library (for managing textures and other items), but fortunately not the reverse...

> Have you never considered formally documenting Zip-Ada?

It depends on what you mean by "formally documenting", but there are commented package specifications, an introductory note (zipada.txt), small demos, tools, tests.
For instance there is a demo called Demo_UnZip which demonstrates UnZip.Streams. I'd start from there...

> > More specifically ?
> 
> Re the Traverse_Verbose information, for my requirement I mean, I'll need to filter out the directory and name information separately for listing (display) purpose (Zip entry: "texture\sky\blue.jpg" ==> "texture\sky\" and "blue", separately).

last_dot, last_slash: Natural:= 0;

for i in name'Range loop
  case name(i) is
    when '.'       => last_dot:= i;
    when '/' | '\' => last_slash:= i;
  end case;
end loop;

Or you can use Ada.Directories, there are functions to do these splits.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  2016-08-26 15:16               ` gautier_niouzes
@ 2016-08-26 15:46                 ` Jeffrey R. Carter
  2016-08-26 16:05                 ` Aurele
  1 sibling, 0 replies; 21+ messages in thread
From: Jeffrey R. Carter @ 2016-08-26 15:46 UTC (permalink / raw)


On 08/26/2016 08:16 AM, gautier_niouzes@hotmail.com wrote:
> 
> for i in name'Range loop
>   case name(i) is
>     when '.'       => last_dot:= i;
>     when '/' | '\' => last_slash:= i;
>   end case;
> end loop;
> 
> Or you can use Ada.Directories, there are functions to do these splits.

Or Ada.Strings.Fixed.Index.

-- 
Jeff Carter
"I'm a lumberjack and I'm OK."
Monty Python's Flying Circus
54

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  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
  1 sibling, 1 reply; 21+ messages in thread
From: Aurele @ 2016-08-26 16:05 UTC (permalink / raw)


> I'm afraid you are confused.
> The GLOBE_3D library is using the Zip-Ada library (for managing textures and other items), but fortunately not the reverse...

LOL you may be right, I may be confused. But I'm looking at your GLOBE_3D demo and the package that caught my attention is inside GLOBE_3D. Namely its the "GLOBE_3D.Textures" package and its use of "UnZip.Streams". Lots going on there.  

QUESTION: Does Zip-Ada pass a flag or something if/when a copy of an entry is found, or is the addition of the word "copy" and the end of the Zip_Info Name entry the only clue of its existance?

Thanks for the filtering advice. Also, thanks Jeff for the tip o7

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  2016-08-26 16:05                 ` Aurele
@ 2016-08-26 23:04                   ` Aurele
  2016-08-27  5:30                     ` gautier_niouzes
  0 siblings, 1 reply; 21+ messages in thread
From: Aurele @ 2016-08-26 23:04 UTC (permalink / raw)


Zip-Ada Works very well.  Goes through the Zip file real fast and I can quickly identify the directories, files and image extensions. Converting them back into usable images appears to be a completely different problem (well its new to me).  In essence, I'll now try to reconstruct the image using UnZip.Streams.Open (from Zip-Ada). Not sure where that will lead me...

Anyway,  thanks for you help !

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  2016-08-26 23:04                   ` Aurele
@ 2016-08-27  5:30                     ` gautier_niouzes
  2016-08-27 11:52                       ` Aurele
  0 siblings, 1 reply; 21+ messages in thread
From: gautier_niouzes @ 2016-08-27  5:30 UTC (permalink / raw)


> Converting them back into usable images appears to be a completely different problem (well its new to me).  In essence, I'll now try to reconstruct the image using UnZip.Streams.Open (from Zip-Ada). Not sure where that will lead me...

Sure, it is a different question.
Since you are considering decoding the images (for thumbnail or icon generation perhaps ?), I guess this will be helpful to you:
https://sf.net/projects/gen-img-dec/
Supports the BMP, GIF, JPEG, PNG, PNM, TGA formats.
The demo in test/mini.adb can be adapted: replace the Stream_IO file by the the opened Zip stream...

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  2016-08-27  5:30                     ` gautier_niouzes
@ 2016-08-27 11:52                       ` Aurele
  2016-08-27 16:31                         ` Aurele
  0 siblings, 1 reply; 21+ messages in thread
From: Aurele @ 2016-08-27 11:52 UTC (permalink / raw)


> Since you are considering decoding the images (for thumbnail or icon generation perhaps ?), 

That is correct Gautier, in addition to listing the zip file images by name (in a pull-down list or menu), I'd also like to preview the said images in thumbnail form itself inside a popup Window. 

Thank for the link, I'll let you know how it turns out o7


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  2016-08-27 11:52                       ` Aurele
@ 2016-08-27 16:31                         ` Aurele
  2016-08-27 19:15                           ` gautier_niouzes
  0 siblings, 1 reply; 21+ messages in thread
From: Aurele @ 2016-08-27 16:31 UTC (permalink / raw)


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


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  2016-08-27 16:31                         ` Aurele
@ 2016-08-27 19:15                           ` gautier_niouzes
  0 siblings, 0 replies; 21+ messages in thread
From: gautier_niouzes @ 2016-08-27 19:15 UTC (permalink / raw)


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 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  2016-08-25 20:17 zLibAda vs ZipAda (which should I use, if any)? Aurele
                   ` (3 preceding siblings ...)
  2016-08-25 23:07 ` Aurele
@ 2016-08-27 19:33 ` Aurele
  2016-08-27 20:16   ` Aurele
  4 siblings, 1 reply; 21+ messages in thread
From: Aurele @ 2016-08-27 19:33 UTC (permalink / raw)


Thanks, was just looking at your To_Bmp demo and also noticed you had txt file (which I should have seen/read first).  So the steps are fairly straight forward....

1) Load the image header from stream
2) Prepare the retrieval of the image ?
3) Load/decode the image itself

Sounds easy. Thanks!

I have not check/looked yest but is the Zip-Ada "UnZip.Streams.Zipped_File_Type" type a subtype of "Ada.Streams.Stream_IO.File_Type" ? 

In otherwords, if I have:

 UnZip.Streams.Open( File         => FileType,
                     Archive_Info => ZipFileInfo,
                     Name         => ASU.To_String( Info_Ptr.Data_Ptr( 31 ).FullName ) );

can I user 

Ada.Streams.Stream_IO.Stream_Access( UnZip.Streams.Stream( FileType ) )

When in calling GID.Load_image_header( .....) ?



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: zLibAda vs ZipAda (which should I use, if any)?
  2016-08-27 19:33 ` Aurele
@ 2016-08-27 20:16   ` Aurele
  0 siblings, 0 replies; 21+ messages in thread
From: Aurele @ 2016-08-27 20:16 UTC (permalink / raw)


Got it, 

UnZip.Streams.Open( File         => FileType,
                    Archive_Info => ZipFileInfo,
                    Name         => ASU.To_String( ... ) );

then

GID.Load_image_header( i,
                       UnZip.Streams.Stream( FileType ).all );

And all is well !!!

Thanks for your help Gautier
                         


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2016-08-27 20:16 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2016-08-27 19:33 ` Aurele
2016-08-27 20:16   ` Aurele

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