diff options
author | Armin Le Grand (Allotropia) <Armin.Le.Grand@me.com> | 2021-04-30 17:26:41 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2022-01-20 12:28:54 +0100 |
commit | 02140554ee1d70b219a42546191e2219d58be4b0 (patch) | |
tree | 3dd419dbdd0c23676c7f749bd8a83d09ad26c8bd /vcl/source | |
parent | 02634fb7c7e8dc613ffc3717bb244f85cf81a7c6 (diff) |
WASM --enable-wasm-strip now skips lots of LO code
... resulting in a stripped-down, Writer-only build to decrease
the resulting WASM bytecode size.
It removes the following code from the build:
* All other major modules: Base, Calc, Chart, Draw, Impress and
Math and related writerperfect filters
* The premultiply tables
* The (auto-)recovery functionality
* All accessibility (but not the accessibility document checker)
* The LanguageGuess component
* EPUB support
* The start center / BackingWindow
* The TipOfTheDay functionality
* The splash screen communication
Currently crashs with anything different then soffice --writer.
Closing the document also still crashes.
FYI: many of these features are now behind ENABLE_WASM_STRIP_*
defines, but they normally don't work on their own, globally!
That's because we started with stripping the main components.
Change-Id: Ib9c0f9452815910c0a2aceaf142ba1ad4a9cb0d7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126182
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/bitmap/BitmapTools.cxx | 94 | ||||
-rw-r--r-- | vcl/source/filter/png/PngImageReader.cxx | 14 | ||||
-rw-r--r-- | vcl/source/helper/svtaccessiblefactory.cxx | 7 |
3 files changed, 115 insertions, 0 deletions
diff --git a/vcl/source/bitmap/BitmapTools.cxx b/vcl/source/bitmap/BitmapTools.cxx index b22661c628d7..da9a88bf67c9 100644 --- a/vcl/source/bitmap/BitmapTools.cxx +++ b/vcl/source/bitmap/BitmapTools.cxx @@ -300,7 +300,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 ); +#if !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); @@ -320,9 +322,15 @@ BitmapEx* CreateFromCairoSurface(Size aSize, cairo_surface_t * pSurface) if( nAlpha != 0 && nAlpha != 255 ) { // Cairo uses pre-multiplied alpha - we do not => re-multiply +#if 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 ); @@ -693,7 +701,9 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un ::Color aColor; unsigned int nAlpha = 255; +#if !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; @@ -722,13 +732,25 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un aColor = pBitmapReadAcc->GetPaletteColor(*pReadScan++); #ifdef OSL_BIGENDIAN +#if 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 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 } @@ -746,18 +768,30 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un nAlpha = data[ nOff ]; else nAlpha = data[ nOff ] = 255; +#if 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; +#if 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 } @@ -775,17 +809,29 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un nAlpha = data[ nOff++ ]; else nAlpha = data[ nOff++ ] = 255; +#if 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; +#if 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 @@ -804,18 +850,30 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un nAlpha = data[ nOff++ ]; else nAlpha = data[ nOff++ ] = 255; +#if 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; +#if 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 @@ -834,18 +892,30 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un nAlpha = data[ nOff ++ ]; else nAlpha = data[ nOff ++ ] = 255; +#if 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; +#if 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 @@ -869,17 +939,29 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un nAlpha = data[ nOff++ ]; else nAlpha = data[ nOff++ ] = 255; +#if 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; +#if 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 } @@ -1043,6 +1125,17 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un return bRet; } +#if 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]; @@ -1100,6 +1193,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 13c19feaf1ad..70ae63240227 100644 --- a/vcl/source/filter/png/PngImageReader.cxx +++ b/vcl/source/filter/png/PngImageReader.cxx @@ -291,7 +291,9 @@ bool reader(SvStream& rStream, BitmapEx& rBitmapEx, png_read_row(pPng, pScanline, nullptr); } } +#if !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++) @@ -300,9 +302,15 @@ bool reader(SvStream& rStream, BitmapEx& rBitmapEx, for (size_t i = 0; i < aRowSizeBytes; i += 4) { const sal_uInt8 alpha = pScanline[i + 3]; +#if 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; } } @@ -315,9 +323,15 @@ bool reader(SvStream& rStream, BitmapEx& rBitmapEx, for (size_t i = 0; i < aRowSizeBytes; i += 4) { const sal_uInt8 alpha = pScanline[i + 3]; +#if 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 } } } diff --git a/vcl/source/helper/svtaccessiblefactory.cxx b/vcl/source/helper/svtaccessiblefactory.cxx index 9e9404da7417..82845ec041d9 100644 --- a/vcl/source/helper/svtaccessiblefactory.cxx +++ b/vcl/source/helper/svtaccessiblefactory.cxx @@ -18,6 +18,7 @@ */ #include <config_feature_desktop.h> +#include <config_wasm_strip.h> #include <vcl/svtaccessiblefactory.hxx> #include <vcl/accessiblefactory.hxx> @@ -41,8 +42,10 @@ namespace vcl oslModule s_hAccessibleImplementationModule = nullptr; #endif #if HAVE_FEATURE_DESKTOP +#if !ENABLE_WASM_STRIP_ACCESSIBILITY GetSvtAccessibilityComponentFactory s_pAccessibleFactoryFunc = nullptr; #endif +#endif ::rtl::Reference< IAccessibleFactory > s_pFactory; @@ -206,6 +209,7 @@ namespace vcl { } +#if !ENABLE_WASM_STRIP_ACCESSIBILITY #if HAVE_FEATURE_DESKTOP #ifndef DISABLE_DYNLOADING extern "C" { static void thisModule() {} } @@ -213,6 +217,7 @@ namespace vcl extern "C" void* getSvtAccessibilityComponentFactory(); #endif #endif // HAVE_FEATURE_DESKTOP +#endif // ENABLE_WASM_STRIP_ACCESSIBILITY void AccessibleFactoryAccess::ensureInitialized() { @@ -221,6 +226,7 @@ namespace vcl ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); +#if !ENABLE_WASM_STRIP_ACCESSIBILITY #if HAVE_FEATURE_DESKTOP // load the library implementing the factory if (!s_pFactory) @@ -252,6 +258,7 @@ namespace vcl } } #endif // HAVE_FEATURE_DESKTOP +#endif // ENABLE_WASM_STRIP_ACCESSIBILITY if (!s_pFactory) // the attempt to load the lib, or to create the factory, failed |