sd/qa/unit/PNGExportTests.cxx      |   12 ++++--------
 vcl/source/filter/igif/gifread.cxx |   36 ++++++++++++++++++++----------------
 2 files changed, 24 insertions(+), 24 deletions(-)

New commits:
commit 2a9eb581f0edfae8123018006df5cc9de1e1fd45
Author:     Patrick Luby <[email protected]>
AuthorDate: Sun May 12 14:04:30 2024 -0400
Commit:     Patrick Luby <[email protected]>
CommitDate: Wed May 15 18:04:35 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 <[email protected]>
    Tested-by: Jenkins

diff --git a/sd/qa/unit/PNGExportTests.cxx b/sd/qa/unit/PNGExportTests.cxx
index 8c28a1951f7c..d99955a923ae 100644
--- a/sd/qa/unit/PNGExportTests.cxx
+++ b/sd/qa/unit/PNGExportTests.cxx
@@ -536,25 +536,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;
         }
     }
 
-    // FIXME this still has some issues with skia
-    if (SkiaHelper::isVCLSkiaEnabled())
-        return;
-
     // 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 c3151f3274d0..443eb05c045a 100644
--- a/vcl/source/filter/igif/gifread.cxx
+++ b/vcl/source/filter/igif/gifread.cxx
@@ -97,7 +97,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();
@@ -155,7 +155,7 @@ GIFReader::GIFReader( SvStream& rStm )
     , nGCTransparentIndex ( 0 )
     , cTransIndex1 ( 0 )
     , cNonTransIndex1 ( 0 )
-    , bEnhance( false )
+    , nPaletteSize( 0 )
 {
     maUpperName = "SVIGIF";
     aSrcBuf.resize(256);    // Memory buffer for ReadNextBlock
@@ -330,12 +330,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()
@@ -677,16 +672,25 @@ void GIFReader::CreateNewBitmaps()
         // aBmp1 is already inverted
         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 );

Reply via email to