Kaydet (Commit) 48d1df74 authored tarafından Caolán McNamara's avatar Caolán McNamara

use same [un]premultiply

Change-Id: Idd1ca1243b64a9ec606382a0895e11376a2ec186
Reviewed-on: https://gerrit.libreoffice.org/64406
Tested-by: Jenkins
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst cd5bef5e
......@@ -28,6 +28,11 @@ namespace com { namespace sun { namespace star { namespace geometry { struct Int
namespace vcl {
namespace bitmap {
typedef sal_uInt8 (*lookup_table)[256];
lookup_table VCL_DLLPUBLIC get_premultiply_table();
lookup_table VCL_DLLPUBLIC get_unpremultiply_table();
/**
* Intended to be used to feed into CreateFromData to create a BitmapEx. RGB data format.
*/
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment