[cairo] Embedding jpeg in pdf

Michael Sløgedal michael at makeweb.no
Mon Jul 14 07:40:18 PDT 2008


Hi,

 

This is my first post, so bear with me, and take my suggestions lightly. I
realize Cairo probably is and has been trying to take a different path than
what i’m suggesting below – i just hope you can see through what i’m trying
to say. There are so many uses for Cairo, and i see other libraries can be
used to support certain functions – however some things belong in the same
place. What i’m using Cairo for a.t.m. is a web based, template based PDF
merging/generator system that takes images (jpegs), other pdfs, as sources,
as well as allowing text input (pango), vector drawing (cairo) etc etc.

 

So, if you are going to implement jpeg support in cairo to reduce pdf file
sizes, why not go full out and implement it like PNG support?

 

Example functions to back my suggestion:

 

cairo_image_surface_create_from_jpeg() – to create a image surface with the
jpeg data attached.

cairo_surface_write_to_jpeg() – to write any surface to file as jpeg.

cairo_surface_get_data() – retrieves data in format specified in function
below, default being RAW. If the surface doesn’t already have an up to date
compressed version of the image data, it will be compressed to said format.

cairo_surface_set_output_format(enum FORMAT) – sets default output format
for cairo_paint() and cairo_surface_get_data(), like JPEG/PNG/RAW

 

a)      Internally, jpeg buffer will be separate from image buffer, and jpeg
will only be UNCOMPRESSED if one of the following is true:

 

1)      Image data is being changed (painting, drawing, filling, etc) – jpeg
will be uncompressed to image buffer before changes applied

2)      Jpeg surface is being painted to a surface that doesn’t support jpeg
data

 

b)      Similarly, when one of the following is true, image data will be
(RE)COMPRESSED to jpeg:

 

1)      image surface is flagged with cairo_surface_set_output_format(JPEG)
and painted to for example a PDF

2)      image surface is saved with cairo_surface_write_to_png/jpeg()

3)      image surface is extracted with cairo_surface_get_data() and the
output format is set to JPEG and any embedded jpeg data is not up-to-date
(ref a1).

 

This way, you can both use cairo to embed jpegs to pdfs at no recompression
cost, since image surface will not have changed – while also allow getting
images from other sources and add them to a pdf as JPEG.

 

I realize You could put much of this responsibility on to the users, but I
see it being much easier to use Cairo if the support was built in – the only
user change needed to support jpegs would be to use the above mentioned
functions to load/save jpegs.

 

If necessary, make it optional. Go with the default of only jpeg data
attachment and no re/compression – but allow for –with-jpeglib for those who
needs it.

 

PS. If going in this direction is an option, cairo_surface_write_to_png/jpeg
would be obsolete with cairo_surface_set_output_format(), and all could be
replaced with one function; cairo_surface_write_to_file()

 

PPS. Please change PDF support so it allows memory-only surfaces :)

 

Kind regards,

 

Michael S

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20080714/18cad8bb/attachment.htm 


More information about the cairo mailing list