From b5fc498c6f74469c5134cd5fd297ae9ee9772724 Mon Sep 17 00:00:00 2001 From: Matúš Kukan Date: Wed, 12 Nov 2014 21:25:55 +0100 Subject: package: Do not bother with deflating big jpeg images It takes a lot of time and we can save 1% of size if at all. Rather store them uncompressed in the zip file. Maybe we should not deflate jpeg files at all. For some small ones, about 100KB - 200KB, I've seen 2% savings. With png, we can save a bit more, although it's still only about 4% - 8%. Change-Id: I43a3e3812882e4ce85e7af9d0aaab454d98c4860 --- package/source/zippackage/ZipPackageStream.cxx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx index 5eaa6e951220..157a90591bde 100644 --- a/package/source/zippackage/ZipPackageStream.cxx +++ b/package/source/zippackage/ZipPackageStream.cxx @@ -772,6 +772,17 @@ bool ZipPackageStream::saveChild( pTempEntry->nCrc = -1; pTempEntry->nCompressedSize = pTempEntry->nSize = -1; } + uno::Reference< io::XSeekable > xSeek(xStream, uno::UNO_QUERY); + sal_Int32 nStreamLength = 0; + if (xSeek.is()) + nStreamLength = xSeek->getLength(); + + // It's not worth to deflate big jpegs to save ~1% in a slow process + if (msMediaType.endsWith("/jpeg") && nStreamLength && nStreamLength > 500000) + { + ImplSetStoredData(*pTempEntry, xStream); + xSeek->seek(0); + } try { @@ -799,8 +810,7 @@ bool ZipPackageStream::saveChild( { bParallelDeflate = true; // Do not deflate small streams in a thread - uno::Reference< io::XSeekable > xSeek( xStream, uno::UNO_QUERY ); - if (xSeek.is() && xSeek->getLength() < 100000) + if (nStreamLength && nStreamLength < 100000) bParallelDeflate = false; if (bParallelDeflate) -- cgit