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 | |
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>
-rw-r--r-- | vcl/headless/CairoCommon.cxx | 33 | ||||
-rw-r--r-- | vcl/headless/SvpGraphicsBackend.cxx | 30 | ||||
-rw-r--r-- | vcl/inc/headless/CairoCommon.hxx | 2 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx | 11 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.hxx | 1 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/gdiimpl.cxx | 34 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/gdiimpl.hxx | 2 |
7 files changed, 48 insertions, 65 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, diff --git a/vcl/inc/headless/CairoCommon.hxx b/vcl/inc/headless/CairoCommon.hxx index 743c962c9423..3e78b435dbc5 100644 --- a/vcl/inc/headless/CairoCommon.hxx +++ b/vcl/inc/headless/CairoCommon.hxx @@ -155,6 +155,8 @@ struct VCL_DLLPUBLIC CairoCommon static void drawPixel(cairo_t* cr, basegfx::B2DRange* pExtents, const Color& rLineColor, tools::Long nX, tools::Long nY); + static Color getPixel(cairo_surface_t* pSurface, tools::Long nX, tools::Long nY); + static void 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/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx b/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx index f1b7f172150b..b8cf58b16125 100644 --- a/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx +++ b/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx @@ -140,6 +140,17 @@ void X11CairoSalGraphicsImpl::drawPixel(tools::Long nX, tools::Long nY, Color nC X11Common::releaseCairoContext(cr); } +Color X11CairoSalGraphicsImpl::getPixel(tools::Long nX, tools::Long nY) +{ + cairo_t* cr = mrX11Common.getCairoContext(); + + Color aRet = CairoCommon::getPixel(cairo_get_target(cr), nX, nY); + + X11Common::releaseCairoContext(cr); + + return aRet; +} + void X11CairoSalGraphicsImpl::drawLine(tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2) { diff --git a/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.hxx b/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.hxx index 7462089ab29f..314e441aaac6 100644 --- a/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.hxx +++ b/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.hxx @@ -78,6 +78,7 @@ public: void drawPixel(tools::Long nX, tools::Long nY) override; void drawPixel(tools::Long nX, tools::Long nY, Color nColor) override; + Color getPixel(tools::Long nX, tools::Long nY) override; void drawLine(tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2) override; diff --git a/vcl/unx/generic/gdi/gdiimpl.cxx b/vcl/unx/generic/gdi/gdiimpl.cxx index 68d44afdb684..9f9f45afb4ad 100644 --- a/vcl/unx/generic/gdi/gdiimpl.cxx +++ b/vcl/unx/generic/gdi/gdiimpl.cxx @@ -1789,40 +1789,6 @@ bool X11SalGraphicsImpl::drawPolyLine( return bDrawnOk; } -Color X11SalGraphicsImpl::getPixel( tools::Long nX, tools::Long nY ) -{ - if( mrParent.bWindow_ && !mrParent.bVirDev_ ) - { - XWindowAttributes aAttrib; - - XGetWindowAttributes( mrParent.GetXDisplay(), mrParent.GetDrawable(), &aAttrib ); - if( aAttrib.map_state != IsViewable ) - { - SAL_WARN( "vcl", "X11SalGraphics::GetPixel drawable not viewable" ); - return 0; - } - } - - XImage *pXImage = XGetImage( mrParent.GetXDisplay(), - mrParent.GetDrawable(), - nX, nY, - 1, 1, - AllPlanes, - ZPixmap ); - if( !pXImage ) - { - SAL_WARN( "vcl", "X11SalGraphics::GetPixel !XGetImage()" ); - return 0; - } - - XColor aXColor; - - aXColor.pixel = XGetPixel( pXImage, 0, 0 ); - XDestroyImage( pXImage ); - - return mrParent.GetColormap().GetColor( aXColor.pixel ); -} - std::shared_ptr<SalBitmap> X11SalGraphicsImpl::getBitmap( tools::Long nX, tools::Long nY, tools::Long nDX, tools::Long nDY ) { bool bFakeWindowBG = false; diff --git a/vcl/unx/generic/gdi/gdiimpl.hxx b/vcl/unx/generic/gdi/gdiimpl.hxx index 0963a85892cd..4f9a96d7177a 100644 --- a/vcl/unx/generic/gdi/gdiimpl.hxx +++ b/vcl/unx/generic/gdi/gdiimpl.hxx @@ -214,8 +214,6 @@ public: virtual std::shared_ptr<SalBitmap> getBitmap( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight ) override; - virtual Color getPixel( tools::Long nX, tools::Long nY ) override; - // invert --> ClipRegion (only Windows or VirDevs) virtual void invert( tools::Long nX, tools::Long nY, |