Discussion:
[cairo] output png fully-formatted png image to STDOUT or memory location
Pablo Romero
2009-02-11 19:33:19 UTC
Permalink
Hello,
IM trying to find a way to feed a cairo png image to imagemagick without having to write to a temporary disk file.

I looked into using cairo's image_surface_get_data() to return a pointer to the image pixels, but that unfortunately points to the raw image pixels, and I need to pass the full, "ready-to-write-to-disk" png image to imagemagick.

Is it possible to write a png file to STDOUT or to a specific, pre-allocated memory location???

more specifically, I only need 1 function from imagemagick that isnt avaible in cairo:
"setcompressionquality"

is it possible to set the compression quality on a png image in cairo????
this way I wouldnt have to deal with imagemagick



_________________________________________________________________
Windows Live?: Keep your life in sync.
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_022009
Dominic Lachowicz
2009-02-11 19:40:07 UTC
Permalink
There's cairo_surface_write_to_png_stream(). Call that, with your
"closure" = stdout, and your write function just a small wrapper
around fwrite().

Of course, you could write to a byte buffer in memory, and pass that
to an ImageMagick blob just as easily.
Post by Pablo Romero
Hello,
IM trying to find a way to feed a cairo png image to imagemagick without having to write to a temporary disk file.
I looked into using cairo's image_surface_get_data() to return a pointer to the image pixels, but that unfortunately points to the raw image pixels, and I need to pass the full, "ready-to-write-to-disk" png image to imagemagick.
Is it possible to write a png file to STDOUT or to a specific, pre-allocated memory location???
"setcompressionquality"
is it possible to set the compression quality on a png image in cairo????
this way I wouldnt have to deal with imagemagick
_________________________________________________________________
Windows Live?: Keep your life in sync.
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_022009
_______________________________________________
cairo mailing list
cairo at cairographics.org
http://lists.cairographics.org/mailman/listinfo/cairo
--
Counting bodies like sheep to the rhythm of the war drums.
Dominic Lachowicz
2009-02-11 20:11:32 UTC
Permalink
Hi Pablo,
Im somewhat confused on how to use the write_to_png_stream() function.
could you give a quick example?
You pass it a function to call whenever cairo wants to write PNG data,
as well as a user_data parameter. Your example would look something
like the following (error checking omitted):

cairo_status_t my_write_function(void *closure,
unsigned char *data,
unsigned int length)
{
fwrite(data, 1, length, (FILE*)closure);
return CAIRO_STATUS_SUCCESS;
}

cairo_surface_t* my_surface = ...;
cairo_surface_write_to_png_stream(my_surface, my_callback, stdout);
also, could you provide a simple example of the logic needed to create the byte buffer???
The idea is to maintain a pointer to a grow-able region of memory, and
append 'length' bytes of 'data' to it in your callback. It's just like
a C++ vector, or a Glib GByteArray. How you implement that (eg. one
could use malloc/realloc plus memcpy, c++'s std::vector, a GString,
...) is left as an exercise for the reader.

Also, cairo's write_png() function is just a *very* small wrapper
around libpng. You could look at the sources of
http://cgit.freedesktop.org/cairo/tree/src/cairo-png.c, and easily
write your own write_png() function that saves an image surface's
data. That way, you could set the compression level without needing
any changes in cairo.

Best,
Dom
Pablo Romero
2009-02-12 15:47:22 UTC
Permalink
Could someone please walk me through setting up a simple "cairo_write_func_t" function, that would print a png image to STDOUT and/or to a byte buffer in memory???

Im not a very strong C programmer.
Thanks,
P.Romero



----------------------------------------
Date: Wed, 11 Feb 2009 14:40:07 -0500
Subject: Re: [cairo] output png fully-formatted png image to STDOUT or memory location
From: domlachowicz at gmail.com
To: romero619 at hotmail.com
CC: cairo at cairographics.org
There's cairo_surface_write_to_png_stream(). Call that, with your
"closure" = stdout, and your write function just a small wrapper
around fwrite().
Of course, you could write to a byte buffer in memory, and pass that
to an ImageMagick blob just as easily.
Post by Pablo Romero
Hello,
IM trying to find a way to feed a cairo png image to imagemagick without having to write to a temporary disk file.
I looked into using cairo's image_surface_get_data() to return a pointer to the image pixels, but that unfortunately points to the raw image pixels, and I need to pass the full, "ready-to-write-to-disk" png image to imagemagick.
Is it possible to write a png file to STDOUT or to a specific, pre-allocated memory location???
"setcompressionquality"
is it possible to set the compression quality on a png image in cairo????
this way I wouldnt have to deal with imagemagick
_________________________________________________________________
Windows Live?: Keep your life in sync.
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_022009
_______________________________________________
cairo mailing list
cairo at cairographics.org
http://lists.cairographics.org/mailman/listinfo/cairo
--
Counting bodies like sheep to the rhythm of the war drums.
_________________________________________________________________
Windows Live?: Keep your life in sync.
http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t1_allup_howitworks_022009
Gerdus van Zyl
2009-02-12 18:07:25 UTC
Permalink
Why can't you just pass the raw pixels to imagemagick?
(MagickImportImagePixels) or you could try the low-fi approach of
running the command line tools on the cairo created png.

~G
Post by Pablo Romero
Could someone please walk me through setting up a simple "cairo_write_func_t" function, that would print a png image to STDOUT and/or to a byte buffer in memory???
Im not a very strong C programmer.
Thanks,
P.Romero
----------------------------------------
Date: Wed, 11 Feb 2009 14:40:07 -0500
Subject: Re: [cairo] output png fully-formatted png image to STDOUT or memory location
From: domlachowicz at gmail.com
To: romero619 at hotmail.com
CC: cairo at cairographics.org
There's cairo_surface_write_to_png_stream(). Call that, with your
"closure" = stdout, and your write function just a small wrapper
around fwrite().
Of course, you could write to a byte buffer in memory, and pass that
to an ImageMagick blob just as easily.
Post by Pablo Romero
Hello,
IM trying to find a way to feed a cairo png image to imagemagick without having to write to a temporary disk file.
I looked into using cairo's image_surface_get_data() to return a pointer to the image pixels, but that unfortunately points to the raw image pixels, and I need to pass the full, "ready-to-write-to-disk" png image to imagemagick.
Is it possible to write a png file to STDOUT or to a specific, pre-allocated memory location???
"setcompressionquality"
is it possible to set the compression quality on a png image in cairo????
this way I wouldnt have to deal with imagemagick
_________________________________________________________________
Windows Live?: Keep your life in sync.
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_022009
_______________________________________________
cairo mailing list
cairo at cairographics.org
http://lists.cairographics.org/mailman/listinfo/cairo
--
Counting bodies like sheep to the rhythm of the war drums.
_________________________________________________________________
Windows Live?: Keep your life in sync.
http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t1_allup_howitworks_022009
_______________________________________________
cairo mailing list
cairo at cairographics.org
http://lists.cairographics.org/mailman/listinfo/cairo
Loading...