GNOME Bugzilla – Bug 721354
Suggestion to invoke cairo_surface_set_mime_data() to embed JPEG images
Last modified: 2014-08-17 16:45:39 UTC
Created attachment 265176 [details] [review] patch making rsvg_cairo_surface_new_from_href() to invoke cairo_surface_set_mime_data() Current rsvg_cairo_surface_new_from_href() creates a cairo surface from pixbuf data. When href-ed data is JPEG, the pixbuf data is quite bigger than the source JPEG data. Cairo avoids lossy reencodin, thus PDF generated by rsvg from a SVG including JPEG image is very big, in comparison with the total size of the original SVG. Because PDF can include JPEG images as they are, cairo has a function to put JPEG image data to the surface without decoding it; cairo_surface_set_mime_data(). Attached patch modifies rsvg_cairo_surface_new_from_href() to invoke it. If the function works without error, the surface originally filled by pixbuf data is refilled by un-decoded JPEG data. If failed, pixbuf data is reused to refill the surface as fallback. Testing the modified rsvg-convert, the converted pdf of tests/svg1.1/svg/struct-image-01-t.svg becomes smaller, from 140kb (including decoded JPEG) to 7.5kb (including un-decoded JPEG). Please review.
Created attachment 265178 [details] test SVG including 796KB JPEG image ah, tests/svg1.1/svg/struct-image-01-t.svg was not good benchmark. here I attach a SVG file including 796KB JPEG image. My patch reduces its PDF output size from 3.2MB to 800KB.
I committed a patch based on this, but making it controlled by a flag (so as to not inflate memory use when this feature is not needed).