It appears that our heuristics to avoid image de-compression and/or re-compression could use some improvement. The re-compression is particularly expensive since we not only jpeg but also png compress the result - cf. pdfwriter_impl2.cxx. Also it seems we re-compress jpegs we just de-compressed potentially at a higher 'quality' - thus carefully preserving any de-compression artifacts, but not adding quality; not ideal - and very slow with it.
Created attachment 122465 [details] sample document with low & high quality jpegs.
I've knocked up a quick band-aid here - it will make some PDFs both smaller and faster to export, and others somewhat larger but still faster to export; for this sample document of a highly quality JPEG and a low-quality JPEG we have (with default settings) libreoffice 5.0 2.543 Mb with the fix 1.861 Mb With some CPU saving too. Ideally we'd adapt to the DPI scaling too; and even more ideally - we'd expose the underlying Graphic from the PDFExtOutDevData to the pdfwriter_impl2.cxx's PDFWriterImpl::implWriteBitmapEx - to ensure that we never make the image larger even in that case. cf. https://gerrit.libreoffice.org/22219 tdf#97662 - Try to preserve original compressed JPEGs harder.
Michael Meeks committed a patch related to this issue. It has been pushed to "master": http://cgit.freedesktop.org/libreoffice/core/commit/?id=76ec54e8c9f3580450bca85236a4f5af0c328588 tdf#97662 - Try to preserve original compressed JPEGs harder. It will be available in 5.2.0. The patch should be included in the daily builds available at http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: http://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Mostly fixed ... =)
Marco Cecchetti committed a patch related to this issue. It has been pushed to "libreoffice-5-1": http://cgit.freedesktop.org/libreoffice/core/commit/?id=2ee228e179d98630bc69cef8b13a55c0edbe9e1b&h=libreoffice-5-1 tdf#97662 - Try to preserve original compressed JPEGs harder. It will be available in 5.1.2. The patch should be included in the daily builds available at http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: http://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Marco Cecchetti committed a patch related to this issue. It has been pushed to "master": http://cgit.freedesktop.org/libreoffice/core/commit/?id=8a039afb1f3f345c748b2e7cc9b76ca030c23abb tdf#97662 - Try to preserve original compressed JPEGs harder. It will be available in 5.2.0. The patch should be included in the daily builds available at http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: http://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Marco Cecchetti committed a patch related to this issue. It has been pushed to "master": http://cgit.freedesktop.org/libreoffice/core/commit/?id=eab3c3ab9da5f0282df43d2f4bfbf17f7a4f8fe3 tdf#97662 - Avoid JPEG compressing de-compressed PNG. It will be available in 5.2.0. The patch should be included in the daily builds available at http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: http://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.