[Libreoffice-commits] core.git: Branch 'feature/wasm' - config_host.mk.in include/vcl solenv/gbuild vcl/headless vcl/source

Armin Le Grand (Allotropia) (via logerrit) logerrit at kemper.freedesktop.org
Fri May 21 09:09:36 UTC 2021


 config_host.mk.in                        |    1 
 include/vcl/BitmapTools.hxx              |    2 
 solenv/gbuild/gbuild.mk                  |    1 
 vcl/headless/svpgdi.cxx                  |   30 +++++++++
 vcl/source/bitmap/BitmapTools.cxx        |   96 ++++++++++++++++++++++++++++++-
 vcl/source/filter/png/PngImageReader.cxx |   14 ++++
 6 files changed, 143 insertions(+), 1 deletion(-)

New commits:
commit fac2aeca4010cb5dc0de39557d51aa94ad0df091
Author:     Armin Le Grand (Allotropia) <Armin.Le.Grand at me.com>
AuthorDate: Fri May 21 11:08:44 2021 +0200
Commit:     Armin Le Grand (Allotropia) <Armin.Le.Grand at me.com>
CommitDate: Fri May 21 11:08:44 2021 +0200

    Wasm optional premultiply table replace
    
    Change-Id: I69f4aab802a935d6e850a7705d38f3e378cd5fce

diff --git a/config_host.mk.in b/config_host.mk.in
index b7075e473c60..5a17772744d4 100644
--- a/config_host.mk.in
+++ b/config_host.mk.in
@@ -216,6 +216,7 @@ export ENABLE_WASM_STRIP_EPUB=@ENABLE_WASM_STRIP@
 export ENABLE_WASM_STRIP_LOCALES=@ENABLE_WASM_STRIP@
 export ENABLE_WASM_STRIP_GUESSLANG=@ENABLE_WASM_STRIP@
 export ENABLE_WASM_STRIP_HUNSPELL=@ENABLE_WASM_STRIP@
+export ENABLE_WASM_STRIP_PREMULTIPLY=@ENABLE_WASM_STRIP@
 export ENABLE_WERROR=@ENABLE_WERROR@
 export ENDIANNESS=@ENDIANNESS@
 export EPM=@EPM@
diff --git a/include/vcl/BitmapTools.hxx b/include/vcl/BitmapTools.hxx
index fa7a43bc99a6..c9bc9bdc3beb 100644
--- a/include/vcl/BitmapTools.hxx
+++ b/include/vcl/BitmapTools.hxx
@@ -26,10 +26,12 @@ namespace com::sun::star::geometry { struct IntegerRectangle2D; }
 
 namespace vcl::bitmap {
 
+#ifndef ENABLE_WASM_STRIP_PREMULTIPLY
 typedef std::array<std::array<sal_uInt8, 256>, 256> lookup_table;
 
 VCL_DLLPUBLIC lookup_table const & get_premultiply_table();
 VCL_DLLPUBLIC lookup_table const & get_unpremultiply_table();
+#endif
 
 sal_uInt8 unpremultiply(sal_uInt8 c, sal_uInt8 a);
 sal_uInt8 premultiply(sal_uInt8 c, sal_uInt8 a);
diff --git a/solenv/gbuild/gbuild.mk b/solenv/gbuild/gbuild.mk
index 34ce4023441c..2acbc0e73d07 100644
--- a/solenv/gbuild/gbuild.mk
+++ b/solenv/gbuild/gbuild.mk
@@ -237,6 +237,7 @@ gb_GLOBALDEFS += -DENABLE_WASM_STRIP_EPUB
 gb_GLOBALDEFS += -DENABLE_WASM_STRIP_LOCALES
 gb_GLOBALDEFS += -DENABLE_WASM_STRIP_GUESSLANG
 gb_GLOBALDEFS += -DENABLE_WASM_STRIP_HUNSPELL
+gb_GLOBALDEFS += -DENABLE_WASM_STRIP_PREMULTIPLY
 endif
 
 ifeq ($(gb_ENABLE_DBGUTIL),$(true))
diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx
index 84d0d3b02d2c..2ce1718e0873 100644
--- a/vcl/headless/svpgdi.cxx
+++ b/vcl/headless/svpgdi.cxx
@@ -2203,7 +2203,9 @@ void SvpSalGraphics::drawMask( const SalTwoRect& rTR,
     }
     sal_Int32 nStride;
     unsigned char *mask_data = aSurface.getBits(nStride);
+#ifndef ENABLE_WASM_STRIP_PREMULTIPLY
     vcl::bitmap::lookup_table const & unpremultiply_table = vcl::bitmap::get_unpremultiply_table();
+#endif
     for (tools::Long y = rTR.mnSrcY ; y < rTR.mnSrcY + rTR.mnSrcHeight; ++y)
     {
         unsigned char *row = mask_data + (nStride*y);
@@ -2211,9 +2213,15 @@ void SvpSalGraphics::drawMask( const SalTwoRect& rTR,
         for (tools::Long x = rTR.mnSrcX; x < rTR.mnSrcX + rTR.mnSrcWidth; ++x)
         {
             sal_uInt8 a = data[SVP_CAIRO_ALPHA];
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+            sal_uInt8 b = vcl::bitmap::unpremultiply(a, data[SVP_CAIRO_BLUE]);
+            sal_uInt8 g = vcl::bitmap::unpremultiply(a, data[SVP_CAIRO_GREEN]);
+            sal_uInt8 r = vcl::bitmap::unpremultiply(a, data[SVP_CAIRO_RED]);
+#else
             sal_uInt8 b = unpremultiply_table[a][data[SVP_CAIRO_BLUE]];
             sal_uInt8 g = unpremultiply_table[a][data[SVP_CAIRO_GREEN]];
             sal_uInt8 r = unpremultiply_table[a][data[SVP_CAIRO_RED]];
+#endif
             if (r == 0 && g == 0 && b == 0)
             {
                 data[0] = nMaskColor.GetBlue();
@@ -2316,12 +2324,20 @@ Color SvpSalGraphics::getPixel( tools::Long nX, tools::Long nY )
     cairo_destroy(cr);
 
     cairo_surface_flush(target);
+#ifndef ENABLE_WASM_STRIP_PREMULTIPLY
     vcl::bitmap::lookup_table const & unpremultiply_table = vcl::bitmap::get_unpremultiply_table();
+#endif
     unsigned char *data = cairo_image_surface_get_data(target);
     sal_uInt8 a = data[SVP_CAIRO_ALPHA];
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+    sal_uInt8 b = vcl::bitmap::unpremultiply(a, data[SVP_CAIRO_BLUE]);
+    sal_uInt8 g = vcl::bitmap::unpremultiply(a, data[SVP_CAIRO_GREEN]);
+    sal_uInt8 r = vcl::bitmap::unpremultiply(a, data[SVP_CAIRO_RED]);
+#else
     sal_uInt8 b = unpremultiply_table[a][data[SVP_CAIRO_BLUE]];
     sal_uInt8 g = unpremultiply_table[a][data[SVP_CAIRO_GREEN]];
     sal_uInt8 r = unpremultiply_table[a][data[SVP_CAIRO_RED]];
+#endif
     Color aColor(ColorAlpha, a, r, g, b);
     cairo_surface_destroy(target);
 
@@ -2583,9 +2599,11 @@ void SvpSalGraphics::releaseCairoContext(cairo_t* cr, bool bXorModeAllowed, cons
         sal_Int32 nUnscaledExtentsRight = nExtentsRight * m_fScale;
         sal_Int32 nUnscaledExtentsTop = nExtentsTop * m_fScale;
         sal_Int32 nUnscaledExtentsBottom = nExtentsBottom * m_fScale;
+#ifndef ENABLE_WASM_STRIP_PREMULTIPLY
         vcl::bitmap::lookup_table const & unpremultiply_table
             = vcl::bitmap::get_unpremultiply_table();
         vcl::bitmap::lookup_table const & premultiply_table = vcl::bitmap::get_premultiply_table();
+#endif
         for (sal_Int32 y = nUnscaledExtentsTop; y < nUnscaledExtentsBottom; ++y)
         {
             unsigned char *true_row = target_surface_data + (nStride*y);
@@ -2596,6 +2614,17 @@ void SvpSalGraphics::releaseCairoContext(cairo_t* cr, bool bXorModeAllowed, cons
             {
                 sal_uInt8 a = true_data[SVP_CAIRO_ALPHA];
                 sal_uInt8 xor_a = xor_data[SVP_CAIRO_ALPHA];
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+                sal_uInt8 b = vcl::bitmap::unpremultiply(a, true_data[SVP_CAIRO_BLUE]) ^
+                              vcl::bitmap::unpremultiply(xor_a, xor_data[SVP_CAIRO_BLUE]);
+                sal_uInt8 g = vcl::bitmap::unpremultiply(a, true_data[SVP_CAIRO_GREEN]) ^
+                              vcl::bitmap::unpremultiply(xor_a, xor_data[SVP_CAIRO_GREEN]);
+                sal_uInt8 r = vcl::bitmap::unpremultiply(a, true_data[SVP_CAIRO_RED]) ^
+                              vcl::bitmap::unpremultiply(xor_a, xor_data[SVP_CAIRO_RED]);
+                true_data[SVP_CAIRO_BLUE] = vcl::bitmap::premultiply(a, b);
+                true_data[SVP_CAIRO_GREEN] = vcl::bitmap::premultiply(a, g);
+                true_data[SVP_CAIRO_RED] = vcl::bitmap::premultiply(a, r);
+#else
                 sal_uInt8 b = unpremultiply_table[a][true_data[SVP_CAIRO_BLUE]] ^
                               unpremultiply_table[xor_a][xor_data[SVP_CAIRO_BLUE]];
                 sal_uInt8 g = unpremultiply_table[a][true_data[SVP_CAIRO_GREEN]] ^
@@ -2605,6 +2634,7 @@ void SvpSalGraphics::releaseCairoContext(cairo_t* cr, bool bXorModeAllowed, cons
                 true_data[SVP_CAIRO_BLUE] = premultiply_table[a][b];
                 true_data[SVP_CAIRO_GREEN] = premultiply_table[a][g];
                 true_data[SVP_CAIRO_RED] = premultiply_table[a][r];
+#endif
                 true_data+=4;
                 xor_data+=4;
             }
diff --git a/vcl/source/bitmap/BitmapTools.cxx b/vcl/source/bitmap/BitmapTools.cxx
index d963bb3bb85b..52df5a7e19f2 100644
--- a/vcl/source/bitmap/BitmapTools.cxx
+++ b/vcl/source/bitmap/BitmapTools.cxx
@@ -289,7 +289,9 @@ BitmapEx* CreateFromCairoSurface(Size aSize, cairo_surface_t * pSurface)
     cairo_surface_flush(pPixels);
     unsigned char *pSrc = cairo_image_surface_get_data( pPixels );
     unsigned int nStride = cairo_image_surface_get_stride( pPixels );
+#ifndef ENABLE_WASM_STRIP_PREMULTIPLY
     vcl::bitmap::lookup_table const & unpremultiply_table = vcl::bitmap::get_unpremultiply_table();
+#endif
     for( tools::Long y = 0; y < aSize.Height(); y++ )
     {
         sal_uInt32 *pPix = reinterpret_cast<sal_uInt32 *>(pSrc + nStride * y);
@@ -309,9 +311,15 @@ BitmapEx* CreateFromCairoSurface(Size aSize, cairo_surface_t * pSurface)
             if( nAlpha != 0 && nAlpha != 255 )
             {
                 // Cairo uses pre-multiplied alpha - we do not => re-multiply
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+                nR = vcl::bitmap::unpremultiply(nAlpha, nR);
+                nG = vcl::bitmap::unpremultiply(nAlpha, nG);
+                nB = vcl::bitmap::unpremultiply(nAlpha, nB);
+#else
                 nR = unpremultiply_table[nAlpha][nR];
                 nG = unpremultiply_table[nAlpha][nG];
                 nB = unpremultiply_table[nAlpha][nB];
+#endif
             }
             pRGBWrite->SetPixel( y, x, BitmapColor( nR, nG, nB ) );
             pMaskWrite->SetPixelIndex( y, x, 255 - nAlpha );
@@ -721,7 +729,9 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un
     ::Color aColor;
     unsigned int nAlpha = 255;
 
+#ifndef ENABLE_WASM_STRIP_PREMULTIPLY
     vcl::bitmap::lookup_table const & premultiply_table = vcl::bitmap::get_premultiply_table();
+#endif
     for( nY = 0; nY < nHeight; nY++ )
     {
         ::Scanline pReadScan;
@@ -750,16 +760,28 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un
                 aColor = pBitmapReadAcc->GetPaletteColor(*pReadScan++);
 
 #ifdef OSL_BIGENDIAN
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, aColor.GetRed());
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, aColor.GetGreen());
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, aColor.GetBlue());
+#else
                 data[ nOff++ ] = premultiply_table[nAlpha][aColor.GetRed()];
                 data[ nOff++ ] = premultiply_table[nAlpha][aColor.GetGreen()];
                 data[ nOff++ ] = premultiply_table[nAlpha][aColor.GetBlue()];
+#endif
+#else
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, aColor.GetBlue());
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, aColor.GetGreen());
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, aColor.GetRed());
 #else
                 data[ nOff++ ] = premultiply_table[nAlpha][aColor.GetBlue()];
                 data[ nOff++ ] = premultiply_table[nAlpha][aColor.GetGreen()];
                 data[ nOff++ ] = premultiply_table[nAlpha][aColor.GetRed()];
+#endif
                 nOff++;
 #endif
-            }
+        }
             break;
         case ScanlineFormat::N24BitTcBgr:
             pReadScan = pBitmapReadAcc->GetScanline( nY );
@@ -774,18 +796,30 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un
                     nAlpha = data[ nOff ];
                 else
                     nAlpha = data[ nOff ] = 255;
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+                data[ nOff + 3 ] = vcl::bitmap::premultiply(nAlpha, *pReadScan++);
+                data[ nOff + 2 ] = vcl::bitmap::premultiply(nAlpha, *pReadScan++);
+                data[ nOff + 1 ] = vcl::bitmap::premultiply(nAlpha, *pReadScan++);
+#else
                 data[ nOff + 3 ] = premultiply_table[nAlpha][*pReadScan++];
                 data[ nOff + 2 ] = premultiply_table[nAlpha][*pReadScan++];
                 data[ nOff + 1 ] = premultiply_table[nAlpha][*pReadScan++];
+#endif
                 nOff += 4;
 #else
                 if( pAlphaReadAcc )
                     nAlpha = data[ nOff + 3 ];
                 else
                     nAlpha = data[ nOff + 3 ] = 255;
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, *pReadScan++);
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, *pReadScan++);
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, *pReadScan++);
+#else
                 data[ nOff++ ] = premultiply_table[nAlpha][*pReadScan++];
                 data[ nOff++ ] = premultiply_table[nAlpha][*pReadScan++];
                 data[ nOff++ ] = premultiply_table[nAlpha][*pReadScan++];
+#endif
                 nOff++;
 #endif
             }
@@ -803,17 +837,29 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un
                     nAlpha = data[ nOff++ ];
                 else
                     nAlpha = data[ nOff++ ] = 255;
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, *pReadScan++);
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, *pReadScan++);
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, *pReadScan++);
+#else
                 data[ nOff++ ] = premultiply_table[nAlpha][*pReadScan++];
                 data[ nOff++ ] = premultiply_table[nAlpha][*pReadScan++];
                 data[ nOff++ ] = premultiply_table[nAlpha][*pReadScan++];
+#endif
 #else
                 if( pAlphaReadAcc )
                     nAlpha = data[ nOff + 3 ];
                 else
                     nAlpha = data[ nOff + 3 ] = 255;
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, pReadScan[ 2 ]);
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, pReadScan[ 1 ]);
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, pReadScan[ 0 ]);
+#else
                 data[ nOff++ ] = premultiply_table[nAlpha][pReadScan[ 2 ]];
                 data[ nOff++ ] = premultiply_table[nAlpha][pReadScan[ 1 ]];
                 data[ nOff++ ] = premultiply_table[nAlpha][pReadScan[ 0 ]];
+#endif
                 pReadScan += 3;
                 nOff++;
 #endif
@@ -832,18 +878,30 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un
                     nAlpha = data[ nOff++ ];
                 else
                     nAlpha = data[ nOff++ ] = 255;
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, pReadScan[ 2 ]);
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, pReadScan[ 1 ]);
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, pReadScan[ 0 ]);
+#else
                 data[ nOff++ ] = premultiply_table[nAlpha][pReadScan[ 2 ]];
                 data[ nOff++ ] = premultiply_table[nAlpha][pReadScan[ 1 ]];
                 data[ nOff++ ] = premultiply_table[nAlpha][pReadScan[ 0 ]];
+#endif
                 pReadScan += 4;
 #else
                 if( pAlphaReadAcc )
                     nAlpha = data[ nOff + 3 ];
                 else
                     nAlpha = data[ nOff + 3 ] = 255;
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, *pReadScan++);
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, *pReadScan++);
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, *pReadScan++);
+#else
                 data[ nOff++ ] = premultiply_table[nAlpha][*pReadScan++];
                 data[ nOff++ ] = premultiply_table[nAlpha][*pReadScan++];
                 data[ nOff++ ] = premultiply_table[nAlpha][*pReadScan++];
+#endif
                 pReadScan++;
                 nOff++;
 #endif
@@ -862,18 +920,30 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un
                     nAlpha = data[ nOff ++ ];
                 else
                     nAlpha = data[ nOff ++ ] = 255;
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, *pReadScan++);
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, *pReadScan++);
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, *pReadScan++);
+#else
                 data[ nOff++ ] = premultiply_table[nAlpha][*pReadScan++];
                 data[ nOff++ ] = premultiply_table[nAlpha][*pReadScan++];
                 data[ nOff++ ] = premultiply_table[nAlpha][*pReadScan++];
+#endif
                 pReadScan++;
 #else
                 if( pAlphaReadAcc )
                     nAlpha = data[ nOff + 3 ];
                 else
                     nAlpha = data[ nOff + 3 ] = 255;
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, pReadScan[ 2 ]);
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, pReadScan[ 1 ]);
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, pReadScan[ 0 ]);
+#else
                 data[ nOff++ ] = premultiply_table[nAlpha][pReadScan[ 2 ]];
                 data[ nOff++ ] = premultiply_table[nAlpha][pReadScan[ 1 ]];
                 data[ nOff++ ] = premultiply_table[nAlpha][pReadScan[ 0 ]];
+#endif
                 pReadScan += 4;
                 nOff++;
 #endif
@@ -897,17 +967,29 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un
                     nAlpha = data[ nOff++ ];
                 else
                     nAlpha = data[ nOff++ ] = 255;
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, aColor.GetRed());
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, aColor.GetGreen());
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, aColor.GetBlue());
+#else
                 data[ nOff++ ] = premultiply_table[nAlpha][aColor.GetRed()];
                 data[ nOff++ ] = premultiply_table[nAlpha][aColor.GetGreen()];
                 data[ nOff++ ] = premultiply_table[nAlpha][aColor.GetBlue()];
+#endif
 #else
                 if( pAlphaReadAcc )
                     nAlpha = data[ nOff + 3 ];
                 else
                     nAlpha = data[ nOff + 3 ] = 255;
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, aColor.GetBlue());
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, aColor.GetGreen());
+                data[ nOff++ ] = vcl::bitmap::premultiply(nAlpha, aColor.GetRed());
+#else
                 data[ nOff++ ] = premultiply_table[nAlpha][aColor.GetBlue()];
                 data[ nOff++ ] = premultiply_table[nAlpha][aColor.GetGreen()];
                 data[ nOff++ ] = premultiply_table[nAlpha][aColor.GetRed()];
+#endif
                 nOff ++;
 #endif
             }
@@ -1040,6 +1122,17 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un
         return bRet;
     }
 
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+    sal_uInt8 unpremultiply(sal_uInt8 c, sal_uInt8 a)
+    {
+        return (a == 0) ? 0 : (c * 255 + a / 2) / a;
+    }
+
+    sal_uInt8 premultiply(sal_uInt8 c, sal_uInt8 a)
+    {
+        return (c * a + 127) / 255;
+    }
+#else
     sal_uInt8 unpremultiply(sal_uInt8 c, sal_uInt8 a)
     {
         return get_unpremultiply_table()[a][c];
@@ -1097,6 +1190,7 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un
             std::make_integer_sequence<int, 256>{});
         return premultiply_table;
     }
+#endif
 
 bool convertBitmap32To24Plus8(BitmapEx const & rInput, BitmapEx & rResult)
 {
diff --git a/vcl/source/filter/png/PngImageReader.cxx b/vcl/source/filter/png/PngImageReader.cxx
index ff2d8b0a47a0..f0f9cfb89040 100644
--- a/vcl/source/filter/png/PngImageReader.cxx
+++ b/vcl/source/filter/png/PngImageReader.cxx
@@ -287,7 +287,9 @@ bool reader(SvStream& rStream, BitmapEx& rBitmapEx,
                     png_read_row(pPng, pScanline, nullptr);
                 }
             }
+#ifndef ENABLE_WASM_STRIP_PREMULTIPLY
             const vcl::bitmap::lookup_table& premultiply = vcl::bitmap::get_premultiply_table();
+#endif
             if (eFormat == ScanlineFormat::N32BitTcAbgr || eFormat == ScanlineFormat::N32BitTcArgb)
             { // alpha first and premultiply
                 for (png_uint_32 y = 0; y < height; y++)
@@ -296,9 +298,15 @@ bool reader(SvStream& rStream, BitmapEx& rBitmapEx,
                     for (size_t i = 0; i < aRowSizeBytes; i += 4)
                     {
                         const sal_uInt8 alpha = pScanline[i + 3];
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+                        pScanline[i + 3] = vcl::bitmap::premultiply(alpha, pScanline[i + 2]);
+                        pScanline[i + 2] = vcl::bitmap::premultiply(alpha, pScanline[i + 1]);
+                        pScanline[i + 1] = vcl::bitmap::premultiply(alpha, pScanline[i]);
+#else
                         pScanline[i + 3] = premultiply[alpha][pScanline[i + 2]];
                         pScanline[i + 2] = premultiply[alpha][pScanline[i + 1]];
                         pScanline[i + 1] = premultiply[alpha][pScanline[i]];
+#endif
                         pScanline[i] = alpha;
                     }
                 }
@@ -311,9 +319,15 @@ bool reader(SvStream& rStream, BitmapEx& rBitmapEx,
                     for (size_t i = 0; i < aRowSizeBytes; i += 4)
                     {
                         const sal_uInt8 alpha = pScanline[i + 3];
+#ifdef ENABLE_WASM_STRIP_PREMULTIPLY
+                        pScanline[i] = vcl::bitmap::premultiply(alpha, pScanline[i]);
+                        pScanline[i + 1] = vcl::bitmap::premultiply(alpha, pScanline[i + 1]);
+                        pScanline[i + 2] = vcl::bitmap::premultiply(alpha, pScanline[i + 2]);
+#else
                         pScanline[i] = premultiply[alpha][pScanline[i]];
                         pScanline[i + 1] = premultiply[alpha][pScanline[i + 1]];
                         pScanline[i + 2] = premultiply[alpha][pScanline[i + 2]];
+#endif
                     }
                 }
             }


More information about the Libreoffice-commits mailing list