[cairo] Embedding jpeg in pdf

Bill Spitzak spitzak at thefoundry.co.uk
Mon Jul 14 13:25:25 PDT 2008

Based on my experiences with the mess that was inserted into fltk, I 
think the following is the right solution, that both gets an api that 
end users really want, and also avoids jpg dependencies.

There would be a new type of surface, replacing the png one, and 
designed to hold an *arbitrary* file or stream of data. By default Cairo 
would only understand .png files (and probably a compilation switch to 
make it understand *no* files), and some source code would be provided 
to show how to add libjpeg as a new interpreter. This surface would keep 
track of the stream data and also a pointer to an interpreter object 
that decodes it into pixels. The creation api would be:

	cairo_image_surface_create_from_file(const char* filename);
	cairo_image_surface_create_from_stream(cairo_read_fuct_t func, void* 

There would also be some kind of access to the "stream" for these 
surfaces, so that a program can examine the bytes in the stream, and 
possibly copy them somewhere. It might also be nice to have an api to 
return the mime type as a string, the interpreter would provide this.

The interpreter choice must be by calling a "can_you_read_this()" 
function on the interpreter, not by some kind of 1:1 match between 
interpreters and file types. The reason is that it will allow an 
existing multi-image library such as ImageMagik to be registered as a 
single "interpreter".

The pdf writer would look at the stream and determine from the bytes 
whether the data is the subclass of jpeg it can write. In that case it 
can copy the stream to the output. Otherwise it just gets the pixels 
(and perhaps convert them to jpeg).

IMHO there does not need to be an equivalent for file output. People do 
not want to create a special object just to write a file. They want to 
get a pointer to the pixels from *any* cairo surface and then send that 
directly to libjpeg or whatever.

Bill Spitzak, Senior Software Engineer
The Foundry, 618 Hampton Drive, Venice, CA, 90291, USA
Tel: +1 310 399-4555 * Fax: +1 310 450-4516 * Web: www.thefoundry.co.uk
The Foundry Visionmongers Ltd * Registered in England and Wales No: 4642027

More information about the cairo mailing list