From 12fd870113a663dde5ceb38c61f1986a34095d0e Mon Sep 17 00:00:00 2001 From: Patrick Luby Date: Mon, 7 Aug 2023 12:17:36 -0400 Subject: tdf#156630 eliminate opaque parts when drawing animated PNG images Due to the switch from transparency to alpha in commit 81994cb2b8b32453a92bcb011830fcb884f22ff3, flip the background colors for the VirtualDevices and invert an alpha mask. On macOS, with Skia/Raster with a Retina display (i.e. 2.0 window scale), the alpha mask gets upscaled. Also, when Skia is enabled, the alpha mask gets inverted in the first export to PDF after launching the application. These two bugs appear to be caused by asynchronous rendering of the returned bitmap. So, we force a copy of the alpha mask in case it changes before the bitmap is actually drawn. Lastly, respect system animation settings when determining if the image should be animated. Change-Id: I8144691a6c99bf8361b301b88d22172991463f26 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155429 Tested-by: Jenkins Reviewed-by: Patrick Luby --- slideshow/source/engine/shapes/gdimtftools.cxx | 57 ++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 9 deletions(-) (limited to 'slideshow') diff --git a/slideshow/source/engine/shapes/gdimtftools.cxx b/slideshow/source/engine/shapes/gdimtftools.cxx index c5a215eefbc4..1928052b9260 100644 --- a/slideshow/source/engine/shapes/gdimtftools.cxx +++ b/slideshow/source/engine/shapes/gdimtftools.cxx @@ -37,6 +37,7 @@ #include #include #include +#include #include @@ -272,6 +273,10 @@ bool getAnimationFromGraphic( VectorOfMtfAnimationFrames& o_rFrames, pVDevMask->SetOutputSizePixel( aAnimSize ); pVDevMask->EnableMapMode( false ); + // tdf#156630 make erase calls fill with transparency + pVDev->SetBackground( Wallpaper( COL_BLACK ) ); + pVDevMask->SetBackground( Wallpaper( COL_ALPHA_TRANSPARENT ) ); + o_rLoopCount = aAnimation.GetLoopCount(); for( sal_uInt16 i=0, nCount=aAnimation.Count(); i(); - Bitmap aAlphaMask = pVDevMask->GetBitmap(aEmptyPoint, aAnimSize); - aAlphaMask.Invert(); // convert from transparency to alpha - pMtf->AddAction( - new MetaBmpExAction( aEmptyPoint, - BitmapEx( - pVDev->GetBitmap( - aEmptyPoint, - aAnimSize ), - aAlphaMask))); + bool useAlphaMask = false; +#if defined(MACOSX) || defined(IOS) + useAlphaMask = true; +#else + // GetBitmap()-> AlphaMask is optimized with SkiaSalBitmap::InterpretAs8Bit(), 1bpp mask is not. + if( SkiaHelper::isVCLSkiaEnabled()) + useAlphaMask = true; +#endif + if( useAlphaMask ) + { + AlphaMask aAlphaMask(pVDevMask->GetBitmap(aEmptyPoint, aAnimSize)); + + // Related tdf#156630 force snapshot of alpha mask + // On macOS, with Skia/Raster with a Retina display (i.e. + // 2.0 window scale), the alpha mask gets upscaled. Also, + // when Skia is enabled, the alpha mask gets inverted in + // the first export to PDF after launching the application. + // These two bugs appear to be caused by asynchronous + // rendering of the returned bitmap. So, we force a copy + // of the alpha mask in case it changes before the bitmap + // is actually drawn. + AlphaMask::ScopedReadAccess pAccessAlpha(aAlphaMask); + + pMtf->AddAction( + new MetaBmpExAction( aEmptyPoint, + BitmapEx( + pVDev->GetBitmap( + aEmptyPoint, + aAnimSize ), + aAlphaMask))); + } + else + { + Bitmap aAlphaMask = pVDevMask->GetBitmap(aEmptyPoint, aAnimSize); + aAlphaMask.Invert(); // convert from transparency to alpha + pMtf->AddAction( + new MetaBmpExAction( aEmptyPoint, + BitmapEx( + pVDev->GetBitmap( + aEmptyPoint, + aAnimSize ), + aAlphaMask))); + } // setup mtf dimensions and pref map mode (for // simplicity, keep it all in pixel. the metafile -- cgit