diff options
author | Caolán McNamara <caolanm@redhat.com> | 2023-01-05 16:41:17 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2023-01-06 08:47:52 +0000 |
commit | ded5e68a58ae4837918e1a381d0c46cd69f7a06a (patch) | |
tree | 0d8bd864c92fb9f18c28f4e942da0b9d74a07887 | |
parent | 1fd19c798243ee46606331ad96b9803b96581a2e (diff) |
move getPixel into CairoCommon and reuse from X11CairoSalGraphicsImpl
2nd attempt. This reverts commit 8d0b7bdb8c9ae8254e5b77b533a158734affc4f5.
Change-Id: I8901a1258e0b0d89170f4e056516c5211801456a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145109
Tested-by: Caolán McNamara <caolanm@redhat.com>
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 c45990b35263..2c85f690698d 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(mrParent.GetGeometryProvider()); + + 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 bec45a01dd31..14220f2e0e78 100644 --- a/vcl/unx/generic/gdi/gdiimpl.hxx +++ b/vcl/unx/generic/gdi/gdiimpl.hxx @@ -215,8 +215,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, |