summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-04-05 00:06:02 +0300
committerStephan Bergmann <sbergman@redhat.com>2021-04-08 08:17:49 +0200
commit0766f7a6a976ec23c4aa0ab9dc9207e441b71be1 (patch)
treea05ee6ca91c8802449bd06e5e0b349b4308390b4
parent4f3b811d6249af4bfec2a0cb07fce9928baf07cd (diff)
Revert "Revert "Compute (un-)premultiply_table at compile time""
This reverts commit c2374d702b0e4b7a1828964faa528344a5a9ee17, since VS 2019 is now the baseline. Change-Id: I3790ba3046910de2fffd7584a589c70cee56de0f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113569 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r--include/vcl/BitmapTools.hxx6
-rw-r--r--vcl/headless/svpgdi.cxx9
-rw-r--r--vcl/source/bitmap/BitmapTools.cxx65
3 files changed, 51 insertions, 29 deletions
diff --git a/include/vcl/BitmapTools.hxx b/include/vcl/BitmapTools.hxx
index d7ce4be9e90f..fa7a43bc99a6 100644
--- a/include/vcl/BitmapTools.hxx
+++ b/include/vcl/BitmapTools.hxx
@@ -26,10 +26,10 @@ namespace com::sun::star::geometry { struct IntegerRectangle2D; }
namespace vcl::bitmap {
-typedef sal_uInt8 (*lookup_table)[256];
+typedef std::array<std::array<sal_uInt8, 256>, 256> lookup_table;
-lookup_table VCL_DLLPUBLIC get_premultiply_table();
-lookup_table VCL_DLLPUBLIC get_unpremultiply_table();
+VCL_DLLPUBLIC lookup_table const & get_premultiply_table();
+VCL_DLLPUBLIC lookup_table const & get_unpremultiply_table();
sal_uInt8 unpremultiply(sal_uInt8 c, sal_uInt8 a);
sal_uInt8 premultiply(sal_uInt8 c, sal_uInt8 a);
diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx
index 9995d5a3b916..24eb3c9af741 100644
--- a/vcl/headless/svpgdi.cxx
+++ b/vcl/headless/svpgdi.cxx
@@ -2202,7 +2202,7 @@ void SvpSalGraphics::drawMask( const SalTwoRect& rTR,
}
sal_Int32 nStride;
unsigned char *mask_data = aSurface.getBits(nStride);
- vcl::bitmap::lookup_table unpremultiply_table = vcl::bitmap::get_unpremultiply_table();
+ vcl::bitmap::lookup_table const & unpremultiply_table = vcl::bitmap::get_unpremultiply_table();
for (tools::Long y = rTR.mnSrcY ; y < rTR.mnSrcY + rTR.mnSrcHeight; ++y)
{
unsigned char *row = mask_data + (nStride*y);
@@ -2315,7 +2315,7 @@ Color SvpSalGraphics::getPixel( tools::Long nX, tools::Long nY )
cairo_destroy(cr);
cairo_surface_flush(target);
- vcl::bitmap::lookup_table unpremultiply_table = vcl::bitmap::get_unpremultiply_table();
+ vcl::bitmap::lookup_table const & unpremultiply_table = vcl::bitmap::get_unpremultiply_table();
unsigned char *data = cairo_image_surface_get_data(target);
sal_uInt8 a = data[SVP_CAIRO_ALPHA];
sal_uInt8 b = unpremultiply_table[a][data[SVP_CAIRO_BLUE]];
@@ -2582,8 +2582,9 @@ 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;
- vcl::bitmap::lookup_table unpremultiply_table = vcl::bitmap::get_unpremultiply_table();
- vcl::bitmap::lookup_table premultiply_table = vcl::bitmap::get_premultiply_table();
+ vcl::bitmap::lookup_table const & unpremultiply_table
+ = vcl::bitmap::get_unpremultiply_table();
+ vcl::bitmap::lookup_table const & premultiply_table = vcl::bitmap::get_premultiply_table();
for (sal_Int32 y = nUnscaledExtentsTop; y < nUnscaledExtentsBottom; ++y)
{
unsigned char *true_row = target_surface_data + (nStride*y);
diff --git a/vcl/source/bitmap/BitmapTools.cxx b/vcl/source/bitmap/BitmapTools.cxx
index 8bd24f1d5706..d963bb3bb85b 100644
--- a/vcl/source/bitmap/BitmapTools.cxx
+++ b/vcl/source/bitmap/BitmapTools.cxx
@@ -8,6 +8,11 @@
*
*/
+#include <sal/config.h>
+
+#include <array>
+#include <utility>
+
#include <vcl/BitmapTools.hxx>
#include <sal/log.hxx>
@@ -284,7 +289,7 @@ 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 );
- vcl::bitmap::lookup_table unpremultiply_table = vcl::bitmap::get_unpremultiply_table();
+ vcl::bitmap::lookup_table const & unpremultiply_table = vcl::bitmap::get_unpremultiply_table();
for( tools::Long y = 0; y < aSize.Height(); y++ )
{
sal_uInt32 *pPix = reinterpret_cast<sal_uInt32 *>(pSrc + nStride * y);
@@ -716,7 +721,7 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un
::Color aColor;
unsigned int nAlpha = 255;
- vcl::bitmap::lookup_table premultiply_table = vcl::bitmap::get_premultiply_table();
+ vcl::bitmap::lookup_table const & premultiply_table = vcl::bitmap::get_premultiply_table();
for( nY = 0; nY < nHeight; nY++ )
{
::Scanline pReadScan;
@@ -1037,43 +1042,59 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un
sal_uInt8 unpremultiply(sal_uInt8 c, sal_uInt8 a)
{
+ return get_unpremultiply_table()[a][c];
+ }
+
+ static constexpr sal_uInt8 unpremultiplyImpl(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 get_premultiply_table()[a][c];
+ }
+
+ static constexpr sal_uInt8 premultiplyImpl(sal_uInt8 c, sal_uInt8 a)
+ {
return (c * a + 127) / 255;
}
- lookup_table get_unpremultiply_table()
+ template<int... Is> static constexpr std::array<sal_uInt8, 256> make_unpremultiply_table_row_(
+ int a, std::integer_sequence<int, Is...>)
{
- static bool inited;
- static sal_uInt8 unpremultiply_table[256][256];
+ return {unpremultiplyImpl(Is, a)...};
+ }
- if (!inited)
- {
- for (int a = 0; a < 256; ++a)
- for (int c = 0; c < 256; ++c)
- unpremultiply_table[a][c] = unpremultiply(c, a);
- inited = true;
- }
+ template<int... Is> static constexpr lookup_table make_unpremultiply_table_(
+ std::integer_sequence<int, Is...>)
+ {
+ return {make_unpremultiply_table_row_(Is, std::make_integer_sequence<int, 256>{})...};
+ }
+ lookup_table const & get_unpremultiply_table()
+ {
+ static constexpr auto unpremultiply_table = make_unpremultiply_table_(
+ std::make_integer_sequence<int, 256>{});
return unpremultiply_table;
}
- lookup_table get_premultiply_table()
+ template<int... Is> static constexpr std::array<sal_uInt8, 256> make_premultiply_table_row_(
+ int a, std::integer_sequence<int, Is...>)
{
- static bool inited;
- static sal_uInt8 premultiply_table[256][256];
+ return {premultiplyImpl(Is, a)...};
+ }
- if (!inited)
- {
- for (int a = 0; a < 256; ++a)
- for (int c = 0; c < 256; ++c)
- premultiply_table[a][c] = premultiply(c, a);
- inited = true;
- }
+ template<int... Is> static constexpr lookup_table make_premultiply_table_(
+ std::integer_sequence<int, Is...>)
+ {
+ return {make_premultiply_table_row_(Is, std::make_integer_sequence<int, 256>{})...};
+ }
+ lookup_table const & get_premultiply_table()
+ {
+ static constexpr auto premultiply_table = make_premultiply_table_(
+ std::make_integer_sequence<int, 256>{});
return premultiply_table;
}