[gtkada] Missing Gdk_Pixbuf_New_From_Data
Dmitry A. Kazakov
mailbox at dmitry-kazakov.de
Tue Sep 25 20:11:02 CEST 2007
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
More information about the gtkada
mailing list