From cff87aac4ec77957569377d690bc4aa8f7146e0d Mon Sep 17 00:00:00 2001 From: David Tardon Date: Mon, 27 Jun 2016 20:37:25 +0200 Subject: [PATCH 2/2] update other places that read data from cairo image surface Change-Id: Icb8761e5ff89e1c0e0e034a751fe9a50ad5ab90a --- canvas/source/cairo/cairo_canvasbitmap.cxx | 7 ++++++ vcl/headless/svpgdi.cxx | 36 +++++++++++++----------------- vcl/inc/headless/svpgdi.hxx | 12 ++++++++++ 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/canvas/source/cairo/cairo_canvasbitmap.cxx b/canvas/source/cairo/cairo_canvasbitmap.cxx index 37c8902..86020ac 100644 --- a/canvas/source/cairo/cairo_canvasbitmap.cxx +++ b/canvas/source/cairo/cairo_canvasbitmap.cxx @@ -152,10 +152,17 @@ namespace cairocanvas sal_uInt32 *pPix = reinterpret_cast(pSrc + nStride * y); for( unsigned long x = 0; x < (unsigned long) aSize.Width(); x++ ) { +#if defined OSL_BIGENDIAN + sal_uInt8 nB = (*pPix >> 24); + sal_uInt8 nG = (*pPix >> 16) & 0xff; + sal_uInt8 nR = (*pPix >> 8) & 0xff; + sal_uInt8 nAlpha = *pPix & 0xff; +#else sal_uInt8 nAlpha = (*pPix >> 24); sal_uInt8 nR = (*pPix >> 16) & 0xff; sal_uInt8 nG = (*pPix >> 8) & 0xff; sal_uInt8 nB = *pPix & 0xff; +#endif if( nAlpha != 0 && nAlpha != 255 ) { // Cairo uses pre-multiplied alpha - we do not => re-multiply diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx index 511a427..e9f761f 100644 --- a/vcl/headless/svpgdi.cxx +++ b/vcl/headless/svpgdi.cxx @@ -1059,9 +1059,9 @@ void SvpSalGraphics::drawMask( const SalTwoRect& rTR, unsigned char *data = row + (rTR.mnSrcX * 4); for (sal_Int32 x = rTR.mnSrcX; x < rTR.mnSrcX + rTR.mnSrcWidth; ++x) { - sal_uInt8 b = unpremultiply(data[0], data[3]); - sal_uInt8 g = unpremultiply(data[1], data[3]); - sal_uInt8 r = unpremultiply(data[2], data[3]); + sal_uInt8 b = unpremultiply(data[SVP_CAIRO_BLUE], data[SVP_CAIRO_ALPHA]); + sal_uInt8 g = unpremultiply(data[SVP_CAIRO_GREEN], data[SVP_CAIRO_ALPHA]); + sal_uInt8 r = unpremultiply(data[SVP_CAIRO_RED], data[SVP_CAIRO_ALPHA]); if (r == 0 && g == 0 && b == 0) { data[0] = SALCOLOR_BLUE(nMaskColor); @@ -1125,15 +1125,9 @@ SalColor SvpSalGraphics::getPixel( long nX, long nY ) unsigned char *surface_data = cairo_image_surface_get_data(m_pSurface); unsigned char *row = surface_data + (nStride*nY); unsigned char *data = row + (nX * 4); -# if defined OSL_BIGENDIAN - sal_uInt8 b = unpremultiply(data[3], data[0]); - sal_uInt8 g = unpremultiply(data[2], data[0]); - sal_uInt8 r = unpremultiply(data[1], data[0]); -#else - sal_uInt8 b = unpremultiply(data[0], data[3]); - sal_uInt8 g = unpremultiply(data[1], data[3]); - sal_uInt8 r = unpremultiply(data[2], data[3]); -#endif + sal_uInt8 b = unpremultiply(data[SVP_CAIRO_BLUE], data[SVP_CAIRO_ALPHA]); + sal_uInt8 g = unpremultiply(data[SVP_CAIRO_GREEN], data[SVP_CAIRO_ALPHA]); + sal_uInt8 r = unpremultiply(data[SVP_CAIRO_RED], data[SVP_CAIRO_ALPHA]); return MAKE_SALCOLOR(r, g, b); } @@ -1342,15 +1336,15 @@ void SvpSalGraphics::releaseCairoContext(cairo_t* cr, bool bXorModeAllowed, cons unsigned char *xor_data = xor_row + (nExtentsLeft * 4); for (sal_Int32 x = nExtentsLeft; x < nExtentsRight; ++x) { - sal_uInt8 b = unpremultiply(true_data[0], true_data[3]) ^ - unpremultiply(xor_data[0], xor_data[3]); - sal_uInt8 g = unpremultiply(true_data[1], true_data[3]) ^ - unpremultiply(xor_data[1], xor_data[3]); - sal_uInt8 r = unpremultiply(true_data[2], true_data[3]) ^ - unpremultiply(xor_data[2], xor_data[3]); - true_data[0] = premultiply(b, true_data[3]); - true_data[1] = premultiply(g, true_data[3]); - true_data[2] = premultiply(r, true_data[3]); + sal_uInt8 b = unpremultiply(true_data[SVP_CAIRO_BLUE], true_data[SVP_CAIRO_ALPHA]) ^ + unpremultiply(xor_data[SVP_CAIRO_BLUE], xor_data[SVP_CAIRO_ALPHA]); + sal_uInt8 g = unpremultiply(true_data[SVP_CAIRO_GREEN], true_data[SVP_CAIRO_ALPHA]) ^ + unpremultiply(xor_data[SVP_CAIRO_GREEN], xor_data[SVP_CAIRO_ALPHA]); + sal_uInt8 r = unpremultiply(true_data[SVP_CAIRO_RED], true_data[SVP_CAIRO_ALPHA]) ^ + unpremultiply(xor_data[SVP_CAIRO_RED], xor_data[SVP_CAIRO_ALPHA]); + true_data[0] = premultiply(b, true_data[SVP_CAIRO_ALPHA]); + true_data[1] = premultiply(g, true_data[SVP_CAIRO_ALPHA]); + true_data[2] = premultiply(r, true_data[SVP_CAIRO_ALPHA]); true_data+=4; xor_data+=4; } diff --git a/vcl/inc/headless/svpgdi.hxx b/vcl/inc/headless/svpgdi.hxx index 1bd4b65..76e4460 100644 --- a/vcl/inc/headless/svpgdi.hxx +++ b/vcl/inc/headless/svpgdi.hxx @@ -39,10 +39,22 @@ //where we don't have GL_BGRA support. #if defined ANDROID # define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcRgba | ScanlineFormat::TopDown) +# define SVP_CAIRO_BLUE 1 +# define SVP_CAIRO_GREEN 2 +# define SVP_CAIRO_RED 0 +# define SVP_CAIRO_ALPHA 3 #elif defined OSL_BIGENDIAN # define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcArgb | ScanlineFormat::TopDown) +# define SVP_CAIRO_BLUE 3 +# define SVP_CAIRO_GREEN 2 +# define SVP_CAIRO_RED 1 +# define SVP_CAIRO_ALPHA 0 #else # define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcBgra | ScanlineFormat::TopDown) +# define SVP_CAIRO_BLUE 0 +# define SVP_CAIRO_GREEN 1 +# define SVP_CAIRO_RED 2 +# define SVP_CAIRO_ALPHA 3 #endif struct BitmapBuffer; -- 2.7.4