diff options
author | Caolán McNamara <caolanm@redhat.com> | 2023-01-04 20:20:36 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2023-01-05 10:50:36 +0000 |
commit | 00b62877fa2f900d1c2dcf7b721f7a956408f8a0 (patch) | |
tree | 3748629ec0e7accd591825dd39c625ce220bc2a3 /vcl/headless | |
parent | 39038ed8dac3d896d261a76e11f9004f7d68f989 (diff) |
move getPixel into CairoCommon and reuse from X11CairoSalGraphicsImpl
Change-Id: I5401cc87ec228d52d98fc65840f875cfb55e30c5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145052
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/headless')
-rw-r--r-- | vcl/headless/CairoCommon.cxx | 33 | ||||
-rw-r--r-- | vcl/headless/SvpGraphicsBackend.cxx | 30 |
2 files changed, 34 insertions, 29 deletions
diff --git a/vcl/headless/CairoCommon.cxx b/vcl/headless/CairoCommon.cxx index 5781eff048e8..39538a9f9f40 100644 --- a/vcl/headless/CairoCommon.cxx +++ b/vcl/headless/CairoCommon.cxx @@ -623,6 +623,39 @@ void CairoCommon::drawPixel(cairo_t* cr, basegfx::B2DRange* pExtents, const Colo *pExtents = getClippedFillDamage(cr); } +Color CairoCommon::getPixel(cairo_surface_t* pSurface, tools::Long nX, tools::Long nY) +{ + cairo_surface_t* target + = cairo_surface_create_similar_image(pSurface, CAIRO_FORMAT_ARGB32, 1, 1); + + cairo_t* cr = cairo_create(target); + + cairo_rectangle(cr, 0, 0, 1, 1); + cairo_set_source_surface(cr, pSurface, -nX, -nY); + cairo_paint(cr); + cairo_destroy(cr); + + cairo_surface_flush(target); +#if !ENABLE_WASM_STRIP_PREMULTIPLY + vcl::bitmap::lookup_table const& unpremultiply_table = vcl::bitmap::get_unpremultiply_table(); +#endif + unsigned char* data = cairo_image_surface_get_data(target); + sal_uInt8 a = data[SVP_CAIRO_ALPHA]; +#if ENABLE_WASM_STRIP_PREMULTIPLY + sal_uInt8 b = vcl::bitmap::unpremultiply(a, data[SVP_CAIRO_BLUE]); + sal_uInt8 g = vcl::bitmap::unpremultiply(a, data[SVP_CAIRO_GREEN]); + sal_uInt8 r = vcl::bitmap::unpremultiply(a, data[SVP_CAIRO_RED]); +#else + sal_uInt8 b = unpremultiply_table[a][data[SVP_CAIRO_BLUE]]; + sal_uInt8 g = unpremultiply_table[a][data[SVP_CAIRO_GREEN]]; + sal_uInt8 r = unpremultiply_table[a][data[SVP_CAIRO_RED]]; +#endif + Color aColor(ColorAlpha, a, r, g, b); + cairo_surface_destroy(target); + + return aColor; +} + void CairoCommon::drawLine(cairo_t* cr, basegfx::B2DRange* pExtents, const Color& rLineColor, bool bAntiAlias, tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2) diff --git a/vcl/headless/SvpGraphicsBackend.cxx b/vcl/headless/SvpGraphicsBackend.cxx index 84d6aa1dcd09..efff52387575 100644 --- a/vcl/headless/SvpGraphicsBackend.cxx +++ b/vcl/headless/SvpGraphicsBackend.cxx @@ -566,35 +566,7 @@ void SvpGraphicsBackend::drawBitmapBuffer(const SalTwoRect& rTR, const BitmapBuf Color SvpGraphicsBackend::getPixel(tools::Long nX, tools::Long nY) { - cairo_surface_t* target - = cairo_surface_create_similar_image(m_rCairoCommon.m_pSurface, CAIRO_FORMAT_ARGB32, 1, 1); - - cairo_t* cr = cairo_create(target); - - cairo_rectangle(cr, 0, 0, 1, 1); - cairo_set_source_surface(cr, m_rCairoCommon.m_pSurface, -nX, -nY); - cairo_paint(cr); - cairo_destroy(cr); - - cairo_surface_flush(target); -#if !ENABLE_WASM_STRIP_PREMULTIPLY - vcl::bitmap::lookup_table const& unpremultiply_table = vcl::bitmap::get_unpremultiply_table(); -#endif - unsigned char* data = cairo_image_surface_get_data(target); - sal_uInt8 a = data[SVP_CAIRO_ALPHA]; -#if ENABLE_WASM_STRIP_PREMULTIPLY - sal_uInt8 b = vcl::bitmap::unpremultiply(a, data[SVP_CAIRO_BLUE]); - sal_uInt8 g = vcl::bitmap::unpremultiply(a, data[SVP_CAIRO_GREEN]); - sal_uInt8 r = vcl::bitmap::unpremultiply(a, data[SVP_CAIRO_RED]); -#else - sal_uInt8 b = unpremultiply_table[a][data[SVP_CAIRO_BLUE]]; - sal_uInt8 g = unpremultiply_table[a][data[SVP_CAIRO_GREEN]]; - sal_uInt8 r = unpremultiply_table[a][data[SVP_CAIRO_RED]]; -#endif - Color aColor(ColorAlpha, a, r, g, b); - cairo_surface_destroy(target); - - return aColor; + return CairoCommon::getPixel(m_rCairoCommon.m_pSurface, nX, nY); } void SvpGraphicsBackend::invert(tools::Long nX, tools::Long nY, tools::Long nWidth, |