[cairo] Embedding jpeg in pdf
Adrian Johnson
ajohnson at redneon.com
Sat Jul 12 21:23:50 PDT 2008
One of the items on the ROADMAP [1] for 1.8 is jpeg embedding in the
PDF, PS, and win32-printing backends.
There are a couple of ways this could be implemented. The minimal
approach would be to add a function to supply the jpeg data to a
surface. The jpeg data would be used instead of the image data when
embedding the surface image in backends that support jpeg. The advantage
of this approach is that no dependency on a jpeg library is required.
The disadvantage is that the user would need to be careful to ensure
that the surface has the same content as the jpeg image otherwise
fallback images are going to be wrong.
The other approach is to provide a cairo_image_surface_create_from_jpeg
function. The advantage is a simpler API for applications to use. The
disadvantage is the libjpeg dependency.
I have created three patches to implement these two ideas on the jpeg
branch of my git repository [2]. The first patch adds the API function
void
cairo_surface_set_jpeg_data (cairo_surface_t *surface,
unsigned char *data,
long length)
to supply the jpeg data to a surface.
The second patch implements PDF embedding of jpeg images. The third
patch adds the API function:
cairo_surface_t *
cairo_image_surface_create_from_jpeg (const char *filename)
The current limitations of these patches that I am aware of are:
- I am not sure who should own the data supplied by
cairo_surface_set_jpeg_data() and whether the entire data or only the
pointer should be copied when snapshotting surfaces.
- cairo_image_surface_create_from_jpeg() does not free the jpeg data
when the surface is destroyed.
- The error handling in cairo_image_surface_create_from_jpeg() is
probably wrong.
- A create_from_jpeg_stream function would also be required if we are
going to use cairo_image_surface_create_from_jpeg().
Any comments on which approach to jpeg embedding we should take and what
the API should look like?
[1] http://www.cairographics.org/roadmap/
[2]
http://gitweb.freedesktop.org/?p=users/ajohnson/cairo.git;a=shortlog;h=jpeg
More information about the cairo
mailing list