[cairo] Re: Embeding JPG in PDF
Pierre
pierre.php at gmail.com
Fri Jan 12 15:07:28 PST 2007
Hello Bill,
On 1/12/07, Bill Spitzak <spitzak at d2.com> wrote:
> However the original problem is not solved. Even with the above, a
> program reading a jpeg in and drawing it on a pdf surface using cairo
> will result in the jpeg being decompressed and then recompressed. This
> is lossy and slow. The only way it will happen is if the pdf surface can
> look at the surface it is copying from and identify that it can get raw
> jpeg data from it.
My last reply was certainly unclear, let me try to explain it again.
PDF can embed images (like jpeg) without uncompressing it and without
doing anything but embed the full jpeg file in an object. All you have
to do is to detect the format, the color scheme, bpp and dimensions.
With these informations you can create a XObject and embed the
_complete_ jpeg file in a stream element without uncompressing it.
I began to work on a patch/hack to show the idea. It is available here
(I already show it to Behdad on IRC):
http://blog.thepimp.net/misc/cairopatches/
The cairo_pdf_add_image function is a quick hack but it needs some
work, I only checked that the image was really embedded. I did not add
the catalog, ID mgt or any other things that may be needed.
The concept of embedding images in PDF is possible relatively easily
and is already implemented in nearly all PDF library out there. It
does not have to be in cairo as long as cairo provide a function to
add a custom XObject+stream and another to add custom element to the
current position or page (like "q 93.54 0 0 93.54 283.46 720.00 cm /I1
Do Q" to display the embedded image 1).
I can try to finish the cairo part of the patch if cairo likes to have
something like that. Or to provide an external set of functions to
deal with images if Cairo provides a kind of add_xobject/add_element
functions.
Cheers,
--Pierre
More information about the cairo
mailing list