vcl/source/filter/igif/gifread.cxx |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

New commits:
commit 110eb4f6f8ed43faf7d2a4e74bfdcb93934f6439
Author:     Attila Szűcs <attila.sz...@collabora.com>
AuthorDate: Mon Mar 25 01:04:14 2024 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Thu Mar 28 10:19:23 2024 +0100

    tdf#153162 Gif load transparency optimization
    
    Converting a bitmap from transparency to alpha can be very slow.
    fortunately it can be avoided.
    Inverted the transparency colors (cTransIndex1, cNonTransIndex1)
    that are used to create aBmp1 in GIFReader::FillImages.
    It create the transparency bitmap inverted, so no need to invert it.
    
    Change-Id: I14714fe4b8bbcd7849db57b2824a7077dda40f81
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165261
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/vcl/source/filter/igif/gifread.cxx 
b/vcl/source/filter/igif/gifread.cxx
index 8f56edaee77f..cfb4e84f2363 100644
--- a/vcl/source/filter/igif/gifread.cxx
+++ b/vcl/source/filter/igif/gifread.cxx
@@ -220,18 +220,22 @@ void GIFReader::CreateBitmaps(tools::Long nWidth, 
tools::Long nHeight, BitmapPal
     if (bGCTransparent)
     {
         const Color aWhite(COL_WHITE);
+        const Color aBlack(COL_BLACK);
 
         aBmp1 = Bitmap(aSize, vcl::PixelFormat::N8_BPP, 
&Bitmap::GetGreyPalette(256));
 
         if (!aAnimation.Count())
-            aBmp1.Erase(aWhite);
+            aBmp1.Erase(aBlack);
 
         pAcc1 = aBmp1;
 
         if (pAcc1)
         {
-            cTransIndex1 = 
static_cast<sal_uInt8>(pAcc1->GetBestPaletteIndex(aWhite));
-            cNonTransIndex1 = cTransIndex1 ? 0 : 1;
+            // We have to make an AlphaMask from it, that needs to be inverted 
from transparency.
+            // It is faster to invert it here.
+            // So Non-Transparent color should be 0xff , and Transparent 
should be 0.
+            cNonTransIndex1 = 
static_cast<sal_uInt8>(pAcc1->GetBestPaletteIndex(aWhite));
+            cTransIndex1 = 
static_cast<sal_uInt8>(pAcc1->GetBestPaletteIndex(aBlack));
         }
         else
         {
@@ -671,7 +675,8 @@ void GIFReader::CreateNewBitmaps()
     {
         pAcc1.reset();
         AlphaMask aAlphaMask(aBmp1);
-        aAlphaMask.Invert(); // convert from transparency to alpha
+        // No need to convert from transparency to alpha
+        // aBmp1 is already inverted
         aAnimationFrame.maBitmapEx = BitmapEx( aBmp8, aAlphaMask );
     }
     else

Reply via email to