[Libreoffice-commits] core.git: vcl/source
LuboÅ¡ LuÅák (via logerrit)
logerrit at kemper.freedesktop.org
Mon Jan 27 14:59:23 UTC 2020
vcl/source/filter/png/pngwrite.cxx | 68 ++++++++++++-------------------------
1 file changed, 23 insertions(+), 45 deletions(-)
New commits:
commit 9bc731524b3c5cc809ca4573daa316173a5ec13a
Author: Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Fri Jan 24 10:45:57 2020 +0100
Commit: Luboš Luňák <l.lunak at collabora.com>
CommitDate: Mon Jan 27 15:58:51 2020 +0100
Revert "avoid needless 32bpp->24+8bpp conversion in png writer" (tdf#130128)
The separate alpha channel that VCL normally uses really messes up
trying to switch to 32bpp bitmaps all over the code. In the case of
tdf#130128 the bitmap has data as ScanlineFormat::N32BitTcMask,
and this uses class ColorMask, which handles only separate alpha
and drops it from the bitmap data itself. So I'm just giving up on the 32bpp
idea in Skia for somewhen later maybe.
This reverts commit 86d44930eecb5e8933f6870684adbb5f9200d6f7.
Change-Id: Iff419e8162c4e0f0680bf62d2b078f9ea809959e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87467
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak at collabora.com>
diff --git a/vcl/source/filter/png/pngwrite.cxx b/vcl/source/filter/png/pngwrite.cxx
index be1dac83d908..8190c1efd38a 100644
--- a/vcl/source/filter/png/pngwrite.cxx
+++ b/vcl/source/filter/png/pngwrite.cxx
@@ -114,7 +114,19 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBitmapEx,
{
if (!rBitmapEx.IsEmpty())
{
- Bitmap aBmp(rBitmapEx.GetBitmap());
+ BitmapEx aBitmapEx;
+
+ if (rBitmapEx.GetBitmap().GetBitCount() == 32)
+ {
+ if (!vcl::bitmap::convertBitmap32To24Plus8(rBitmapEx, aBitmapEx))
+ return;
+ }
+ else
+ {
+ aBitmapEx = rBitmapEx;
+ }
+
+ Bitmap aBmp(aBitmapEx.GetBitmap());
mnMaxChunkSize = std::numeric_limits<sal_uInt32>::max();
@@ -136,26 +148,9 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBitmapEx,
}
mnBitsPerPixel = static_cast<sal_uInt8>(aBmp.GetBitCount());
- 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 (aBitmapEx.IsTransparent())
{
- if (mnBitsPerPixel <= 8 && rBitmapEx.IsAlpha())
+ if (mnBitsPerPixel <= 8 && aBitmapEx.IsAlpha())
{
aBmp.Convert( BmpConversion::N24Bit );
mnBitsPerPixel = 24;
@@ -164,14 +159,14 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBitmapEx,
if (mnBitsPerPixel <= 8) // transparent palette
{
aBmp.Convert(BmpConversion::N8BitTrans);
- aBmp.Replace(rBitmapEx.GetMask(), BMP_COL_TRANS);
+ aBmp.Replace(aBitmapEx.GetMask(), BMP_COL_TRANS);
mnBitsPerPixel = 8;
mpAccess = Bitmap::ScopedReadAccess(aBmp);
if (mpAccess)
{
if (ImplWriteHeader())
{
- ImplWritepHYs(rBitmapEx);
+ ImplWritepHYs(aBitmapEx);
ImplWritePalette();
ImplWriteTransparent();
ImplWriteIDAT();
@@ -188,16 +183,16 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBitmapEx,
mpAccess = Bitmap::ScopedReadAccess(aBmp); // true RGB with alphachannel
if (mpAccess)
{
- mbTrueAlpha = rBitmapEx.IsAlpha();
+ mbTrueAlpha = aBitmapEx.IsAlpha();
if (mbTrueAlpha)
{
- AlphaMask aMask(rBitmapEx.GetAlpha());
+ AlphaMask aMask(aBitmapEx.GetAlpha());
mpMaskAccess = aMask.AcquireReadAccess();
if (mpMaskAccess)
{
if (ImplWriteHeader())
{
- ImplWritepHYs(rBitmapEx);
+ ImplWritepHYs(aBitmapEx);
ImplWriteIDAT();
}
aMask.ReleaseAccess(mpMaskAccess);
@@ -210,13 +205,13 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBitmapEx,
}
else
{
- Bitmap aMask(rBitmapEx.GetMask());
+ Bitmap aMask(aBitmapEx.GetMask());
mpMaskAccess = aMask.AcquireReadAccess();
if (mpMaskAccess)
{
if (ImplWriteHeader())
{
- ImplWritepHYs(rBitmapEx);
+ ImplWritepHYs(aBitmapEx);
ImplWriteIDAT();
}
Bitmap::ReleaseAccess(mpMaskAccess);
@@ -242,7 +237,7 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBitmapEx,
{
if (ImplWriteHeader())
{
- ImplWritepHYs(rBitmapEx);
+ ImplWritepHYs(aBitmapEx);
if (mpAccess->HasPalette())
ImplWritePalette();
@@ -318,11 +313,6 @@ bool PNGWriterImpl::ImplWriteHeader()
if (mpMaskAccess)
nColorType |= 4;
- if (mnBitsPerPixel == 32)
- {
- nBitDepth = mnBitsPerPixel / 4;
- nColorType |= 4;
- }
ImplWriteChunk(nBitDepth);
ImplWriteChunk(nColorType); // colortype
@@ -595,18 +585,6 @@ 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 );
More information about the Libreoffice-commits
mailing list