vcl/source/filter/png/pngwrite.cxx | 68 ++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 23 deletions(-)
New commits: commit 86d44930eecb5e8933f6870684adbb5f9200d6f7 Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Fri Dec 20 19:40:00 2019 +0100 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Tue Jan 21 11:25:19 2020 +0100 avoid needless 32bpp->24+8bpp conversion in png writer Change-Id: Iaf03a23e75b0ce1ed8b4586f397ff90666469882 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86773 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lu...@collabora.com> diff --git a/vcl/source/filter/png/pngwrite.cxx b/vcl/source/filter/png/pngwrite.cxx index 8190c1efd38a..be1dac83d908 100644 --- a/vcl/source/filter/png/pngwrite.cxx +++ b/vcl/source/filter/png/pngwrite.cxx @@ -114,19 +114,7 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBitmapEx, { if (!rBitmapEx.IsEmpty()) { - BitmapEx aBitmapEx; - - if (rBitmapEx.GetBitmap().GetBitCount() == 32) - { - if (!vcl::bitmap::convertBitmap32To24Plus8(rBitmapEx, aBitmapEx)) - return; - } - else - { - aBitmapEx = rBitmapEx; - } - - Bitmap aBmp(aBitmapEx.GetBitmap()); + Bitmap aBmp(rBitmapEx.GetBitmap()); mnMaxChunkSize = std::numeric_limits<sal_uInt32>::max(); @@ -148,9 +136,26 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBitmapEx, } mnBitsPerPixel = static_cast<sal_uInt8>(aBmp.GetBitCount()); - if (aBitmapEx.IsTransparent()) + if (mnBitsPerPixel == 32) + { + mpAccess = Bitmap::ScopedReadAccess(aBmp); // RGBA + if (mpAccess) + { + if (ImplWriteHeader()) + { + ImplWritepHYs(rBitmapEx); + ImplWriteIDAT(); + } + mpAccess.reset(); + } + else + { + mbStatus = false; + } + } + else if (rBitmapEx.IsTransparent()) { - if (mnBitsPerPixel <= 8 && aBitmapEx.IsAlpha()) + if (mnBitsPerPixel <= 8 && rBitmapEx.IsAlpha()) { aBmp.Convert( BmpConversion::N24Bit ); mnBitsPerPixel = 24; @@ -159,14 +164,14 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBitmapEx, if (mnBitsPerPixel <= 8) // transparent palette { aBmp.Convert(BmpConversion::N8BitTrans); - aBmp.Replace(aBitmapEx.GetMask(), BMP_COL_TRANS); + aBmp.Replace(rBitmapEx.GetMask(), BMP_COL_TRANS); mnBitsPerPixel = 8; mpAccess = Bitmap::ScopedReadAccess(aBmp); if (mpAccess) { if (ImplWriteHeader()) { - ImplWritepHYs(aBitmapEx); + ImplWritepHYs(rBitmapEx); ImplWritePalette(); ImplWriteTransparent(); ImplWriteIDAT(); @@ -183,16 +188,16 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBitmapEx, mpAccess = Bitmap::ScopedReadAccess(aBmp); // true RGB with alphachannel if (mpAccess) { - mbTrueAlpha = aBitmapEx.IsAlpha(); + mbTrueAlpha = rBitmapEx.IsAlpha(); if (mbTrueAlpha) { - AlphaMask aMask(aBitmapEx.GetAlpha()); + AlphaMask aMask(rBitmapEx.GetAlpha()); mpMaskAccess = aMask.AcquireReadAccess(); if (mpMaskAccess) { if (ImplWriteHeader()) { - ImplWritepHYs(aBitmapEx); + ImplWritepHYs(rBitmapEx); ImplWriteIDAT(); } aMask.ReleaseAccess(mpMaskAccess); @@ -205,13 +210,13 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBitmapEx, } else { - Bitmap aMask(aBitmapEx.GetMask()); + Bitmap aMask(rBitmapEx.GetMask()); mpMaskAccess = aMask.AcquireReadAccess(); if (mpMaskAccess) { if (ImplWriteHeader()) { - ImplWritepHYs(aBitmapEx); + ImplWritepHYs(rBitmapEx); ImplWriteIDAT(); } Bitmap::ReleaseAccess(mpMaskAccess); @@ -237,7 +242,7 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBitmapEx, { if (ImplWriteHeader()) { - ImplWritepHYs(aBitmapEx); + ImplWritepHYs(rBitmapEx); if (mpAccess->HasPalette()) ImplWritePalette(); @@ -313,6 +318,11 @@ bool PNGWriterImpl::ImplWriteHeader() if (mpMaskAccess) nColorType |= 4; + if (mnBitsPerPixel == 32) + { + nBitDepth = mnBitsPerPixel / 4; + nColorType |= 4; + } ImplWriteChunk(nBitDepth); ImplWriteChunk(nColorType); // colortype @@ -585,6 +595,18 @@ sal_uLong PNGWriterImpl::ImplGetFilter (sal_uLong nY, sal_uLong nXStart, sal_uLo } } } + else if(mnBitsPerPixel == 32) // RGBA + { + Scanline pScanline = mpAccess->GetScanline( nY ); + for (sal_uLong nX = nXStart; nX < mnWidth; nX += nXAdd) + { + const BitmapColor& rColor = mpAccess->GetPixelFromData(pScanline, nX); + *pDest++ = rColor.GetRed(); + *pDest++ = rColor.GetGreen(); + *pDest++ = rColor.GetBlue(); + *pDest++ = 255 - rColor.GetTransparency(); + } + } else { Scanline pScanline = mpAccess->GetScanline( nY ); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits