Use cairo mime data to allow reduce the file size of cairo output
This patch reduces the size of cairo PS/PDF/SVG output by ensuring that
- if the source image is JPEG, pass the JPEG data though to cairo to embed in the output instead of Flate compressing the image bitmap, and
- when an image is used multiple times, only one copy of the image data is embedded (PDF only).
For example using the following dot file:
graph {
a [shape="none", image="a.jpg", label=""];
b [shape="none", image="b.jpg", label=""];
c [shape="none", image="a.jpg", label=""];
a -- b;
b -- c;
}
And running pdfimages -list
(from poppler utils) on the PDF output:
page num type width height color comp bpc enc interp object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
1 0 image 128 128 rgb 3 8 image yes 6 0 95 95 14.1K 29%
1 1 image 128 128 rgb 3 8 image yes 7 0 95 95 10.6K 22%
1 2 image 128 128 rgb 3 8 image yes 8 0 95 95 16.1K 34%
shows three images. Each image is Flate compressed and there are three embedded image streams (object IDs 6, 7, 8). The PDF file size is 41,635 bytes.
With the patch applied the output is:
--------------------------------------------------------------------------------------------
1 0 image 128 128 rgb 3 8 jpeg yes 6 0 95 95 6330B 13%
1 1 image 128 128 rgb 3 8 jpeg yes 7 0 95 95 6176B 13%
1 2 image 128 128 rgb 3 8 jpeg yes 6 0 95 95 6330B 13%
Here there are three images all JPEG encoded. Two of the images share the same image stream (object ID 6) so the data for the two identical images is embedded only once. The PDF file size is 14,273 bytes.