[cairo] Using gimp c file image

Dominic Lachowicz domlachowicz at gmail.com
Thu Dec 17 14:34:02 PST 2009


Hi Michael,

create_from_png() loads the PNG from a file on disk.

create_from_stream() allows you to supply your own read func. So, you
could feed it in data from memory. Or from a URL. Or something like
that. Cairo will repeatedly call the read_func to request the next N
bytes of data from your resource.

On Thu, Dec 17, 2009 at 5:29 PM, gurnett at telia.com <gurnett at telia.com> wrote:
> I'm a bit confused with
>
> cairo_image_surface_create_from_png_stream.
>
> If the resource stream looks exactly like the png file, why is a read_func
> required?
>
> Is it
> possible just to get the part of the code used by
> cairo_image_surface_create_from_png and use that as the read_func.
>
> Michael
>
>
>
>
>>----Ursprungligt meddelande----
>>Från: gurnett at telia.com
>>Datum: 2009-12-17 13:52
>>Till: <dov.grobgeld at gmail.com>
>>Kopia: <cairo at cairographics.org>
>>Ärende: Re: [cairo] Using gimp c file image
>>
>>Thanks.
>>
>>I am looking at the second option to use i conjunction with a resource. Using
>>resources seems like the best way instead of converting to gimp c images.
>>
>>Tack så mycket (Thanks alot)
>>
>>Michael
>>
>>>----Ursprungligt meddelande----
>>>Från: dov.grobgeld at gmail.com
>>>Datum: 2009-12-17 13:37
>>>Till: "gurnett at telia.com"<gurnett at telia.com>
>>>Kopia: <cairo at cairographics.org>
>>>Ärende: Re: [cairo] Using gimp c file image
>>>
>>>You can use gdk_pixbuf and in your build system do:
>>>
>>>gdk-pixbuf-csource --name=foo_inline foo.png > foo.i
>>>
>>>And in your c-source do:
>>>
>>>#include "foo.i"
>>>
>>>:
>>>
>>>GdkPixbuf* foo_pixbuf = gdk_pixbuf_new_from_inline(sizeof
>>(foo_inline),
>>>                           foo_inline,
>>>                           FALSE,
>>>                           &error);
>>>
>>>You can then create a image surface through:
>>>
>>>    cairo_surface_t *surface = cairo_image_surface_create_for_data
>>>(gdk_pixbuf_get_pixels(foo_pixbuf),
>>>
>>>gdk_pixbuf_get_has_alpha(foo_pixbuf) ? CAIRO_FORMAT_ARGB32 :
>>>CAIRO_FORMAT_FORMAT_RGB24
>>>                                         gdk_pixbuf_get_width(foo_pixbuf),
>>>                                         gdk_pixbuf_get_height(foo_pixbuf),
>>>                                         gdk_pixbuf_get_rowstride
>>(foo_pixbuf));
>>>    gdk_pixbuf_unref(foo_pixbuf);
>>>
>>>
>>>There is one problem though, which is that cairo and gdk pixbuf does not
>>>agree on the order of R,G,B and alpha. So you will have to swap the data
>>>before you do this. (Instead of gdk pixbuf you can use any image library,
>>>e.g. libpng, opencv, FreeImage, etc.)
>>>
>>>Another option if cairo has been compiled with PNG support, is to do:
>>>
>>>cairo_surface_t * cairo_image_surface_create_from_png_stream
>>>                  (cairo_read_func_t read_func,
>>>                   void *closure);
>>>
>>>You will then have to write a read_func instance that will provide data from
>>>your baked png file.
>>>
>>>Hope this helps.
>>>
>>>Lycka till!
>>>Dov
>>>
>>>On Thu, Dec 17, 2009 at 11:05, gurnett at telia.com <gurnett at telia.com> wrote:
>>>
>>>> I have an app that has a lot of png files. I've asked previously if it was
>>>> possible to use embedded png images with cairo, but this did not seem
>>>> possible.
>>>> As I really want to bake all this images into the exe I was wondering if it
>>>> is
>>>> possible to use the gimp c file image format and use that instead of
>>>>
>>>> image=cairo_image_surface_create_from_png("image.png");
>>>>
>>>> Thanks
>>>>
>>>> Michael
>>>> --
>>>> cairo mailing list
>>>> cairo at cairographics.org
>>>> http://lists.cairographics.org/mailman/listinfo/cairo>>>>
>>
>>
>>--
>>cairo mailing list
>>cairo at cairographics.org
>>http://lists.cairographics.org/mailman/listinfo/cairo
>>
>
>
> --
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>



-- 
"I like to pay taxes. With them, I buy civilization." --  Oliver Wendell Holmes


More information about the cairo mailing list