reading raw (cairo surface) image data from memory

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
romero619

reading raw (cairo surface) image data from memory

Post by romero619 »

Hi,
dont know if this is possible or if anyone has experience with this.
I have an existing app that uses cairo.

I need to modify a cairo "image surface" IN MEMORY before writing to disk.
I can get an unsigned char pointer to the data in memory using cairos "image_surface_get_data" function.

However I dont know the length, since cairo apparently doesnt provide this info.
Im guessing that it should just be (pixel_height)*(pixel_width)*(4) for RGBA right??? need help on this...

Also, Im assuming that I would simply pass this info to MagickReadImageBlob(), correct???
something like "MagickReadImageBlob(mw,blobptr,3600)"
also need help figuring out how to this...

last question: the in-memory image is a png file.
Im not clear if the image has 'meta-data' that IM can read & figure out, or if I have to manually set the image attributes in my magickwand prior (or after?) reading the blob...how does this work???

Please help, thanks...
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: reading raw (cairo surface) image data from memory

Post by magick »

Check out the source module coders/svg.c. In it we convert a cairo_surface_t to MagickCore Image structure. It should provide enough insight to help you with your own code.
romero619

Re: reading raw (cairo surface) image data from memory

Post by romero619 »

ok, thanks.
Im taking a look at the example code, but honestly, it seems pretty complex & low-level.
I was hoping to be able to stay at a higher level with wand.
is this do-able in wand, or will I be forced to work in magick-core?

I see that theres a "MagickImportImagePixels" function.
would this achieve what I need?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: reading raw (cairo surface) image data from memory

Post by magick »

All MagickCore methods are available from MagickWand. We encourage you to continue to use MagickWand. You can create an Image* image with MagickCore API calls similar to the method outlined in the coders/svg.c module and import it into MagickWand with the NewMagickWandFromImage() method.
romero619

Re: reading raw (cairo surface) image data from memory

Post by romero619 »

I apologize, I still need assistance.
I have been looking at the svg example code, but it looks very confusing, Im not clear on how the cairo surface is being converted to an imagemagick image.

What is the simplest way that I can convert a cairo_image_surface_t to an imagemagick image????

was I incorrect to believe that I can simply pass a pointer to the cairo image data in memory to an imagemagick function???

please help, Im stuck...
Thanks
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: reading raw (cairo surface) image data from memory

Post by magick »

The example in magick/svg.c is all we have to offer because we know it works. Perhaps another user may be of assistance.
Post Reply