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