summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2016-01-13 10:49:55 +0000
committerCaolán McNamara <caolanm@redhat.com>2016-01-18 11:34:09 +0000
commitfece8dfb0669280f6d7ff754b63e56eaa452ce24 (patch)
treeac725ad2a2c0b59f12619b939871db555fe8cd94 /vcl
parent8e98c722e196801d7398c413f7156b5566b05161 (diff)
svp: implement getPixel via cairo
Change-Id: Idaf0c27e84d561fc6486bdf4e383de1dbdd615cc
Diffstat (limited to 'vcl')
-rw-r--r--vcl/headless/svpgdi.cxx34
1 files changed, 22 insertions, 12 deletions
diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx
index fbeea4e89d8d..cf861ffe8387 100644
--- a/vcl/headless/svpgdi.cxx
+++ b/vcl/headless/svpgdi.cxx
@@ -1277,10 +1277,30 @@ SalBitmap* SvpSalGraphics::getBitmap( long nX, long nY, long nWidth, long nHeigh
return pBitmap;
}
+static sal_uInt8 unpremultiply(sal_uInt8 c, sal_uInt8 a)
+{
+ return (a > 0) ? (c * 255 + a / 2) / a : 0;
+}
+
+static sal_uInt8 premultiply(sal_uInt8 c, sal_uInt8 a)
+{
+ return (c * a + 127) / 255;
+}
+
SalColor SvpSalGraphics::getPixel( long nX, long nY )
{
- basebmp::Color aColor( m_aOrigDevice->getPixel( basegfx::B2IPoint( nX, nY ) ) );
- return aColor.toInt32();
+ cairo_surface_t* surface = createCairoSurface(m_aOrigDevice);
+ unsigned char *surface_data = cairo_image_surface_get_data(surface);
+ cairo_format_t nFormat = getCairoFormat(m_aOrigDevice);
+ assert(nFormat == CAIRO_FORMAT_ARGB32 && "need to implement CAIRO_FORMAT_A1 after all here");
+ basegfx::B2IVector size = m_aOrigDevice->getSize();
+ sal_Int32 nStride = cairo_format_stride_for_width(nFormat, size.getX());
+ unsigned char *row = surface_data + (nStride*nY);
+ unsigned char *data = row + (nX * 4);
+ sal_uInt8 b = unpremultiply(data[0], data[3]);
+ sal_uInt8 g = unpremultiply(data[1], data[3]);
+ sal_uInt8 r = unpremultiply(data[2], data[3]);
+ return MAKE_SALCOLOR(r, g, b);
}
namespace
@@ -1448,16 +1468,6 @@ cairo_t* SvpSalGraphics::getCairoContext(bool bXorModeAllowed) const
return cr;
}
-static sal_uInt8 unpremultiply(sal_uInt8 c, sal_uInt8 a)
-{
- return (a > 0) ? (c * 255 + a / 2) / a : 0;
-}
-
-static sal_uInt8 premultiply(sal_uInt8 c, sal_uInt8 a)
-{
- return (c * a + 127) / 255;
-}
-
void SvpSalGraphics::releaseCairoContext(cairo_t* cr, bool bXorModeAllowed, const cairo_rectangle_int_t& extents) const
{
sal_Int32 nExtentsLeft(extents.x), nExtentsTop(extents.y);