Bug 160690 - Animated GIF completely invisible in Edit mode (GIF has alpha-transparency)
Summary: Animated GIF completely invisible in Edit mode (GIF has alpha-transparency)
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Impress (show other bugs)
Version:
(earliest affected)
24.2.0.0 alpha0+
Hardware: All All
: medium normal
Assignee: Patrick (volunteer)
URL:
Whiteboard: target:24.8.0 target:24.2.4
Keywords: bibisected, bisected, regression
Depends on:
Blocks: Impress-Images
  Show dependency treegraph
 
Reported: 2024-04-16 10:13 UTC by Gerald Pfeifer
Modified: 2024-05-30 04:16 UTC (History)
9 users (show)

See Also:
Crash report or crash signature:


Attachments
GIF image that make CppunitTest_sw_tiledrendering evaluates (41 bytes, image/gif)
2024-05-14 12:58 UTC, Patrick (volunteer)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gerald Pfeifer 2024-04-16 10:13:32 UTC
1. Open attachment #170672 [details] from bug #141213
2. In the center of the slide there is an animated GIF
   which is completely invisible in edit mode.
3. Enter presentation mode and you'll see the animated GIF
   (with 24.2 and 24.8).

Version: 24.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 1dc92b9e9951ef118d2d823d54f9a022c2e41a27
CPU threads: 12; OS: Linux 6.8; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US


This is a regression, the GIF is shown in edit mode in

  Version: 7.6.7.0.0+ (X86_64) / LibreOffice Community
  Build ID: 88f6a250076eb2a825084c84193b84f3b94ce112
  CPU threads: 12; OS: Linux 6.8; UI render: default; VCL: gtk3
  Locale: en-US (en_US.UTF-8); UI: en-US


(Between 7.6 and 24.2 there was a transition 

  commit 81994cb2b8b32453a92bcb011830fcb884f22ff3
  Date:   Fri Apr 16 20:33:10 2021 +0200

    Convert internal vcl bitmap formats transparency->alpha (II)

which caused half a dozen or so regressions; maybe it fixed bug #141213
while also being responsible for this regression?)
Comment 1 m_a_riosv 2024-04-16 20:30:09 UTC
Reproducible
Version: 24.2.2.2 (X86_64) / LibreOffice Community
Build ID: d56cc158d8a96260b836f100ef4b4ef25d6f1a01
CPU threads: 16; OS: Windows 10.0 Build 22631; UI render: Skia/Raster; VCL: win
Locale: es-ES (es_ES); UI: en-US
Calc: CL threaded
and
Version: 24.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: faadf7c15593521c0ebceb043f82f916ee5ccf9d
CPU threads: 16; OS: Windows 10.0 Build 22631; UI render: default; VCL: win
Locale: es-ES (es_ES); UI: en-US
Calc: CL threaded
Comment 2 gladys 2024-05-09 15:06:19 UTC Comment hidden (obsolete)
Comment 3 gladys 2024-05-09 15:08:00 UTC Comment hidden (obsolete)
Comment 4 gladys 2024-05-11 06:57:25 UTC Comment hidden (obsolete)
Comment 5 Noel Grandin 2024-05-11 20:56:08 UTC Comment hidden (obsolete)
Comment 6 gladys 2024-05-12 05:32:36 UTC Comment hidden (obsolete)
Comment 7 raal 2024-05-12 06:16:17 UTC
This seems to have begun at the below commit in bibisect repository/OS linux-64-24.2.
Adding Cc: to Patrick Luby ; Could you possibly take a look at this one?
Thanks
 42ed678aa24ff8e4283998ae38662842452e9df2 is the first bad commit
commit 42ed678aa24ff8e4283998ae38662842452e9df2
Author: Jenkins Build User <tdf@pollux.tdf>
Date:   Thu Aug 10 14:04:04 2023 +0200

    source 12fd870113a663dde5ceb38c61f1986a34095d0e

155429: tdf#156630 eliminate opaque parts when drawing animated PNG images | https://gerrit.libreoffice.org/c/core/+/155429
Comment 8 Patrick (volunteer) 2024-05-12 14:34:49 UTC
If I apply the following debug patch, on macOS this bug no longer occurs in the document window, printing, or export to PDF. Unfortunately, this swapping of code that create alpha masks cause tdf#156630 to reoccur so there must to something different between the animated images. I will continue debugging and post again when I have some news:

diff --git a/drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx b/drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx
index d756e6e3b74f..03cecb5c6a7e 100644
--- a/drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx
+++ b/drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx
@@ -180,12 +180,12 @@ namespace drawinglayer::primitive2d
                 BitmapEx bitmap;
                 if( useAlphaMask )
                 {
-                    const AlphaMask aMaskBitmap(maVirtualDeviceMask->GetBitmap(Point(), maVirtualDeviceMask->GetOutputSizePixel()));
+                    const Bitmap aMaskBitmap(maVirtualDeviceMask->GetBitmap(Point(), maVirtualDeviceMask->GetOutputSizePixel()));
                     bitmap = BitmapEx(aMainBitmap, aMaskBitmap);
                 }
                 else
                 {
-                    Bitmap aMaskBitmap(maVirtualDeviceMask->GetBitmap(Point(), maVirtualDeviceMask->GetOutputSizePixel()));
+                    AlphaMask aMaskBitmap(maVirtualDeviceMask->GetBitmap(Point(), maVirtualDeviceMask->GetOutputSizePixel()));
                     // tdf#156630 invert the alpha mask
                     aMaskBitmap.Invert(); // convert from transparency to alpha
                     bitmap = BitmapEx(aMainBitmap, aMaskBitmap);
Comment 9 Patrick (volunteer) 2024-05-12 15:31:18 UTC
I think I found the cause: GIF images with color palettes of 16 colors or less need additional handling. I have a fix (see following debug patch) but I need to do more testing before I submit it to make sure it doesn't cause tdf#157635 or tdf#157793 to reoccur:

diff --git a/vcl/source/filter/igif/gifread.cxx b/vcl/source/filter/igif/gifread.cxx
index c3151f3274d0..6c3deb4da3d0 100644
--- a/vcl/source/filter/igif/gifread.cxx
+++ b/vcl/source/filter/igif/gifread.cxx
@@ -683,10 +683,10 @@ void GIFReader::CreateNewBitmaps()
         // 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 );
+        Bitmap aAlphaMask( aBmp8 );
+        if (!bEnhance)
+            aAlphaMask.Invert();
+        aAnimationFrame.maBitmapEx = BitmapEx( aBmp8, aAlphaMask );
     }
 
     aAnimationFrame.maPositionPixel = Point( nImagePosX, nImagePosY );
Comment 10 Patrick (volunteer) 2024-05-13 13:48:17 UTC
(In reply to Patrick Luby (volunteer) from comment #9)
> I think I found the cause: GIF images with color palettes of 16 colors or
> less need additional handling. I have a fix (see following debug patch) but
> I need to do more testing before I submit it to make sure it doesn't cause
> tdf#157635 or tdf#157793 to reoccur:

Update: I submitted the following fix but found it causes a unit test to fail. The unit test code looks fine so it is clear to me that my fix will cause some unexpected bugs:

https://gerrit.libreoffice.org/c/core/+/167563

So, I think I need to rework the section of code that my fix modifies to avoid inverting the bitmap.

I will post again when I have more news to report.
Comment 11 Patrick (volunteer) 2024-05-14 12:58:01 UTC
Created attachment 194114 [details]
GIF image that make CppunitTest_sw_tiledrendering evaluates
Comment 12 Commit Notification 2024-05-15 16:05:27 UTC
Patrick Luby committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/2a9eb581f0edfae8123018006df5cc9de1e1fd45

tdf#160690 set an opaque alpha mask for non-transparent frames

It will be available in 24.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 13 Patrick (volunteer) 2024-05-15 16:07:29 UTC
I have committed a fix this bug. The fix should be in tomorrow's (15 May 2024) nightly master builds:

https://dev-builds.libreoffice.org/daily/master/current.html

Note for macOS testers: the nightly master builds install in /Applications/LibreOfficeDev.app. These builds are not codesigned like regular LibreOffice releases so you will need to execute the following Terminal command after installation but before you launch /Applications/LibreOfficeDev:

xattr -d com.apple.quarantine /Applications/LibreOfficeDev.app
Comment 14 Commit Notification 2024-05-15 17:54:47 UTC
Patrick Luby committed a patch related to this issue.
It has been pushed to "libreoffice-24-2":

https://git.libreoffice.org/core/commit/73b552139906e10f004bd56e53684cceed071bd6

tdf#160690 set an opaque alpha mask for non-transparent frames

It will be available in 24.2.4.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 15 Gerald Pfeifer 2024-05-16 22:39:25 UTC
Happy to verify this as fixed with the last nightly snapshot:

  Version: 24.8.0.0.alpha1+ (X86_64) / LibreOffice Community
  Build ID: 1b45ca1aa7d7cb8e7adcc07f8c60e26a413eca8c
  CPU threads: 12; OS: Linux 6.8; UI render: default; VCL: gtk3
  Locale: en-US (en_US.UTF-8); UI: en-US