Missing Gdk_Pixbuf_New_From_Data

View: New views
4 Messages — Rating Filter:   Alert me  

Missing Gdk_Pixbuf_New_From_Data

by Adrian Hoe :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I am looking at GtkAda source (previous version and the latest 2.10.0 from Libre site). I found on the last line in gdk-pixbuf.ads that gdk_pixbuf_new_from_data is missing or is not implemented. Why?

Is there any method to read pixbuf from Ada.Streams? I believe the missing function can do that with some implementation of conversion and stuff. Has anyone done this before?

Thanks.
--
"If you missed the rising sun and the morning dew, don't miss the beautiful sunset." -- Adrian Hoe inspired by Michal Nowak, June 15 2004



_______________________________________________
gtkada mailing list
gtkada@...
http://lists.adacore.com/mailman/listinfo/gtkada

Re: Missing Gdk_Pixbuf_New_From_Data

by Arnaud Charlet :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Please do not cross post to multiple lists, thanks.

> I am looking at GtkAda source (previous version and the latest 2.10.0  
> from Libre site). I found on the last line in gdk-pixbuf.ads that  
> gdk_pixbuf_new_from_data is missing or is not implemented. Why?

Because nobody has implemented it so far.

> Is there any method to read pixbuf from Ada.Streams? I believe the  

You can probably use Gdk_New_From_Xpm_Data for this purpose, or implement
(and contribute) binding for gdk_pixbuf_new_from_data.

Arno
_______________________________________________
gtkada mailing list
gtkada@...
http://lists.adacore.com/mailman/listinfo/gtkada

Re: Missing Gdk_Pixbuf_New_From_Data

by Dmitry A. Kazakov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 25 Sep 2007 22:06:38 +0800, you wrote:

> I am looking at GtkAda source (previous version and the latest 2.10.0  
> from Libre site). I found on the last line in gdk-pixbuf.ads that  
> gdk_pixbuf_new_from_data is missing or is not implemented. Why?

Because it requires flat arrays I guess.

You can use it directly using pragma Import. For example:

   X_Size : constant GInt := 16;
   Y_Size : constant GInt := 16;
   type Pixbuf_Image is array (Natural range 0..1023) of GUChar;
   pragma Convention (C, Pixbuf_Image);
   Pixels : constant Pixbuf_Image :=
   (  255,255,255,  0, 255,255,255,  0, 255,255,255,  0, 255,255,255,  0,
      255,255,255,  0, 255,255,255,  0, 255,255,255,  0, 255,255,255,  0,
      255,255,255,  0, 255,255,255,  0, 255,255,255,  0, 255,255,255,  0,
      255,255,255,  0, 255,255,255,  0, 255,255,255,  0, 255,255,255,  0,
     ...
   );
   function Get_Pixbuf
            (  Data       : Pixbuf_Image   := Pixels;
               Colorspace : Gdk_Colorspace := Colorspace_RGB;
               Has_Alpha  : GBoolean := 1;
               Bits       : Int := 8;
               Width      : Int := Int (X_Size);
               Height     : Int := Int (Y_Size);
               Rowstride  : Int := 64;
               Fn         : Address := Null_Address;
               Fn_Data    : Address := Null_Address
            )  return Gdk_Pixbuf;
   pragma Import (C, Get_Pixbuf, "gdk_pixbuf_new_from_data");

> Is there any method to read pixbuf from Ada.Streams? I believe the  
> missing function can do that with some implementation of conversion  
> and stuff. Has anyone done this before?

I did a slightly different thing, a generator of Ada packages from XPM
files. See

   http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm#xpm2gtkada

With streams, you would first read the image pixels from the stream into
the memory and then call gdk_pixbuf_new_from_data. If you don't know the
image size in advance as in my example, you can use System.Address in the
first parameter of gdk_pixbuf_new_from_data instead.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
_______________________________________________
gtkada mailing list
gtkada@...
http://lists.adacore.com/mailman/listinfo/gtkada

Parent Message unknown Re: Missing Gdk_Pixbuf_New_From_Data

by Dmitry A. Kazakov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 25 Sep 2007 23:40:57 +0800, you wrote:

> On Sep 25, 2007, at 11:37 PM, Dmitry A. Kazakov wrote:
>
>> On Tue, 25 Sep 2007 22:06:38 +0800, you wrote:
>>
>>> I am looking at GtkAda source (previous version and the latest 2.10.0
>>> from Libre site). I found on the last line in gdk-pixbuf.ads that
>>> gdk_pixbuf_new_from_data is missing or is not implemented. Why?
>>
>> Because it requires flat arrays I guess.
>>
>> You can use it directly using pragma Import. For example:
>>
>>    X_Size : constant GInt := 16;
>>    Y_Size : constant GInt := 16;
>>    type Pixbuf_Image is array (Natural range 0..1023) of GUChar;
>>    pragma Convention (C, Pixbuf_Image);
>>    Pixels : constant Pixbuf_Image :=
>>    (  255,255,255,  0, 255,255,255,  0, 255,255,255,  0,  
>> 255,255,255,  0,
>>       255,255,255,  0, 255,255,255,  0, 255,255,255,  0,  
>> 255,255,255,  0,
>>       255,255,255,  0, 255,255,255,  0, 255,255,255,  0,  
>> 255,255,255,  0,
>>       255,255,255,  0, 255,255,255,  0, 255,255,255,  0,  
>> 255,255,255,  0,
>>      ...
>>    );
>>    function Get_Pixbuf
>>             (  Data       : Pixbuf_Image   := Pixels;
>>                Colorspace : Gdk_Colorspace := Colorspace_RGB;
>>                Has_Alpha  : GBoolean := 1;
>>                Bits       : Int := 8;
>>                Width      : Int := Int (X_Size);
>>                Height     : Int := Int (Y_Size);
>>                Rowstride  : Int := 64;
>>                Fn         : Address := Null_Address;
>>                Fn_Data    : Address := Null_Address
>>             )  return Gdk_Pixbuf;
>>    pragma Import (C, Get_Pixbuf, "gdk_pixbuf_new_from_data");

> I am new at manipulating JPEG and graphic formats.
>
> How does gdk_pixbuf_read_from_data work? Say I have read a JPEG image  
> into stream. Can it recognize the "data" is JPEG?
>
> What is Rowstride?

gdk_pixbuf_new_from_data works with raw square images stored row-wise. The
parameter Rowstride determines the size of a row in octets (bytes). In the
example I gave, we have 4 bytes (RGB + alpha). The horizontal image size is
16 pixels, so Rowstride is 16*4=64. When rows occupy unaligned memory
blocks it is sometimes better to align them at the appropriate boundary. In
that case Rowstride might be greater than <pixel-size> x <columns>. As you
see it is very low-level.

If you have JPEG you could:

1. unpack JPEG in the memory and then use gdk_pixbuf_new_from_data.
2. gdk_pixbuf_new_from_file which understands JPEG.

The second option should certainly work with Ada.Streams. But if you get
JPEG from a stream, then to feed gdk_pixbuf_new_from_file you will need a
named pipe (to have a file name for it). That would make you OS-dependent.
Same if you tired to use memory-mapped files.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
_______________________________________________
gtkada mailing list
gtkada@...
http://lists.adacore.com/mailman/listinfo/gtkada
LightInTheBox - Buy quality products at wholesale price