sd/qa/unit/PNGExportTests.cxx | 8 ++++---- vcl/source/filter/igif/gifread.cxx | 36 ++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 20 deletions(-)
New commits: commit 73b552139906e10f004bd56e53684cceed071bd6 Author: Patrick Luby <guibmac...@gmail.com> AuthorDate: Sun May 12 14:04:30 2024 -0400 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed May 15 19:54:38 2024 +0200 tdf#160690 set an opaque alpha mask for non-transparent frames Due to the switch from transparency to alpha in commit 81994cb2b8b32453a92bcb011830fcb884f22ff3, an empty alpha mask is treated as a completely transparent bitmap. So revert all of the previous commits for tdf#157576, tdf#157635, and tdf#157793 and create a completely opaque bitmap instead. Note: this fix also fixes tdf#157576, tdf#157635, and tdf#157793. Change-Id: Ic2ccad6ab94e4d43b1b66013f85955d474dc0151 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167563 Reviewed-by: Patrick Luby <guibomac...@gmail.com> Tested-by: Jenkins (cherry picked from commit 2a9eb581f0edfae8123018006df5cc9de1e1fd45) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167674 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sd/qa/unit/PNGExportTests.cxx b/sd/qa/unit/PNGExportTests.cxx index 855c3becfd47..69343b8b208d 100644 --- a/sd/qa/unit/PNGExportTests.cxx +++ b/sd/qa/unit/PNGExportTests.cxx @@ -483,21 +483,21 @@ CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf157793) CPPUNIT_ASSERT_EQUAL(Size(100, 100), aSize); Bitmap aBMP = aBMPEx.GetBitmap(); BitmapScopedReadAccess pReadAccess(aBMP); - int nLightGrayCount = 0; + int nWhiteCount = 0; for (tools::Long nX = 1; nX < aSize.Width() - 1; ++nX) { for (tools::Long nY = 1; nY < aSize.Height() - 1; ++nY) { const Color aColor = pReadAccess->GetColor(nY, nX); - if (aColor == 0xfefefe) - ++nLightGrayCount; + if (aColor == 0xffffff) + ++nWhiteCount; } } // Without the fix in place, this test would have failed with // - Expected greater than: 7800 // - Actual : 0 - CPPUNIT_ASSERT_GREATER(7800, nLightGrayCount); + CPPUNIT_ASSERT_GREATER(7800, nWhiteCount); } CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf157635) diff --git a/vcl/source/filter/igif/gifread.cxx b/vcl/source/filter/igif/gifread.cxx index 8f56edaee77f..95b70568d9c7 100644 --- a/vcl/source/filter/igif/gifread.cxx +++ b/vcl/source/filter/igif/gifread.cxx @@ -99,7 +99,7 @@ class GIFReader : public GraphicReader sal_uInt8 nGCDisposalMethod; // 'Disposal Method' (see GIF docs) sal_uInt8 cTransIndex1; sal_uInt8 cNonTransIndex1; - bool bEnhance; + sal_uLong nPaletteSize; void ReadPaletteEntries( BitmapPalette* pPal, sal_uLong nCount ); void ClearImageExtensions(); @@ -157,7 +157,7 @@ GIFReader::GIFReader( SvStream& rStm ) , nGCTransparentIndex ( 0 ) , cTransIndex1 ( 0 ) , cNonTransIndex1 ( 0 ) - , bEnhance( false ) + , nPaletteSize( 0 ) { maUpperName = "SVIGIF"; aSrcBuf.resize(256); // Memory buffer for ReadNextBlock @@ -328,12 +328,7 @@ void GIFReader::ReadPaletteEntries( BitmapPalette* pPal, sal_uLong nCount ) (*pPal)[ 254UL ] = COL_BLACK; } - // tdf#157793 limit tdf#157635 fix to only larger palettes - // I don't know why, but the fix for tdf#157635 causes - // images with a palette of 16 entries to be inverted. - // Also, fix tdf#158047 by allowing the tdf#157635 fix for - // palettes with 64 entries. - bEnhance = (nCount > 16); + nPaletteSize = nCount; } bool GIFReader::ReadExtension() @@ -674,16 +669,25 @@ void GIFReader::CreateNewBitmaps() aAlphaMask.Invert(); // convert from transparency to alpha aAnimationFrame.maBitmapEx = BitmapEx( aBmp8, aAlphaMask ); } - else + else if( nPaletteSize > 2 ) { - // tdf#157576 and tdf#157635 mask out black pixels + // tdf#160690 set an opaque alpha mask for non-transparent frames // Due to the switch from transparency to alpha in commit - // 81994cb2b8b32453a92bcb011830fcb884f22ff3, mask out black - // pixels in bitmap. - if (bEnhance) - aAnimationFrame.maBitmapEx = BitmapEx( aBmp8, aBmp8 ); - else - aAnimationFrame.maBitmapEx = BitmapEx( aBmp8 ); + // 81994cb2b8b32453a92bcb011830fcb884f22ff3, an empty alpha mask + // is treated as a completely transparent bitmap. So revert all + // of the previous commits for tdf#157576, tdf#157635, and tdf#157793 + // and create a completely opaque bitmap instead. + // Note: this fix also fixes tdf#157576, tdf#157635, and tdf#157793. + AlphaMask aAlphaMask(aBmp8.GetSizePixel()); + aAnimationFrame.maBitmapEx = BitmapEx( aBmp8, aAlphaMask ); + } + else + { + // Don't apply the fix for tdf#160690 as it will cause 1 bit bitmaps + // in Word documents like the following test document to fail to be + // parsed correctly: + // sw/qa/extras/tiledrendering/data/tdf159626_yellowPatternFill.docx + aAnimationFrame.maBitmapEx = BitmapEx( aBmp8 ); } aAnimationFrame.maPositionPixel = Point( nImagePosX, nImagePosY );