diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-12-01 19:41:15 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-12-02 11:10:45 +0100 |
commit | 48d1df74036386ce19cfabd64d90afcd1532d5c9 (patch) | |
tree | 580e29dec6b1d8f56b90f8862b994f3946ac048c /vcl/headless/svpgdi.cxx | |
parent | cd5bef5e19c2812386ab6afee4b3bc43fe5541b9 (diff) |
use same [un]premultiply
Change-Id: Idd1ca1243b64a9ec606382a0895e11376a2ec186
Reviewed-on: https://gerrit.libreoffice.org/64406
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/headless/svpgdi.cxx')
-rw-r--r-- | vcl/headless/svpgdi.cxx | 53 |
1 files changed, 5 insertions, 48 deletions
diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx index ec01ec520a86..c936b0e1cbbe 100644 --- a/vcl/headless/svpgdi.cxx +++ b/vcl/headless/svpgdi.cxx @@ -29,6 +29,7 @@ #include <sal/log.hxx> #include <o3tl/safeint.hxx> +#include <vcl/BitmapTools.hxx> #include <vcl/sysdata.hxx> #include <config_cairo_canvas.h> #include <basegfx/numeric/ftools.hxx> @@ -1639,50 +1640,6 @@ void SvpSalGraphics::drawBitmap( const SalTwoRect& rTR, drawAlphaBitmap(rTR, rSourceBitmap, rTransparentBitmap); } -static sal_uInt8 unpremultiply(sal_uInt8 c, sal_uInt8 a) -{ - return (a == 0) ? 0 : (c * 255 + a / 2) / a; -} - -static sal_uInt8 premultiply(sal_uInt8 c, sal_uInt8 a) -{ - return (c * a + 127) / 255; -} - -typedef sal_uInt8 (*lookup_table)[256]; - -static lookup_table get_unpremultiply_table() -{ - static bool inited; - static sal_uInt8 unpremultiply_table[256][256]; - - 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; - } - - return unpremultiply_table; -} - -static lookup_table get_premultiply_table() -{ - static bool inited; - static sal_uInt8 premultiply_table[256][256]; - - 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; - } - - return premultiply_table; -} - void SvpSalGraphics::drawMask( const SalTwoRect& rTR, const SalBitmap& rSalBitmap, Color nMaskColor ) @@ -1697,7 +1654,7 @@ void SvpSalGraphics::drawMask( const SalTwoRect& rTR, } sal_Int32 nStride; unsigned char *mask_data = aSurface.getBits(nStride); - lookup_table unpremultiply_table = get_unpremultiply_table(); + vcl::bitmap::lookup_table unpremultiply_table = vcl::bitmap::get_unpremultiply_table(); for (long y = rTR.mnSrcY ; y < rTR.mnSrcY + rTR.mnSrcHeight; ++y) { unsigned char *row = mask_data + (nStride*y); @@ -1805,7 +1762,7 @@ Color SvpSalGraphics::getPixel( long nX, long nY ) cairo_destroy(cr); cairo_surface_flush(target); - lookup_table unpremultiply_table = get_unpremultiply_table(); + vcl::bitmap::lookup_table 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]]; @@ -2139,8 +2096,8 @@ 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; - lookup_table unpremultiply_table = get_unpremultiply_table(); - lookup_table premultiply_table = get_premultiply_table(); + vcl::bitmap::lookup_table unpremultiply_table = vcl::bitmap::get_unpremultiply_table(); + vcl::bitmap::lookup_table premultiply_table = vcl::bitmap::get_premultiply_table(); for (sal_Int32 y = nUnscaledExtentsTop; y < nUnscaledExtentsBottom; ++y) { unsigned char *true_row = target_surface_data + (nStride*y); |