diff options
author | Patrick Luby <guibmacdev@gmail.com> | 2024-06-28 18:31:14 -0400 |
---|---|---|
committer | Patrick Luby <guibomacdev@gmail.com> | 2024-07-04 13:50:16 +0200 |
commit | 3da1d8a791cff6cf2dad29b64c9ad15b1a65d5b3 (patch) | |
tree | 12e688274ee8af2455bc4a16f78314c0ddaa49d0 | |
parent | d9dcada2ed467cd4b892388c9c57ac795cc4c3fb (diff) |
tdf#161833 treat semi-transparent pixels as opaque
Limiting the contour wrapping polygon to only opaque pixels
causes clipping of any shadows or other semi-transaprent
areas in the image. So, instead of testing for fully opaque
pixels, treat pixels that are not fully transparent as opaque.
Also, tdf#161833 would cause semi-transparent pixels to be
treated as fully transparent pixels when calculating the wrap
contour for an image. To force the correct contour when loading
a document, force the contour to be recalculated by ignoring
the saved polygon if the contour is set to "recreate on edit".
Change-Id: Ibe256f54e1c82de30c2b7d5b92a69344b4a7ba10
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169745
Reviewed-by: Patrick Luby <guibomacdev@gmail.com>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins
-rw-r--r-- | vcl/source/bitmap/BitmapEx.cxx | 15 | ||||
-rw-r--r-- | xmloff/source/text/XMLTextFrameContext.cxx | 27 |
2 files changed, 26 insertions, 16 deletions
diff --git a/vcl/source/bitmap/BitmapEx.cxx b/vcl/source/bitmap/BitmapEx.cxx index ebcb7aa1cb9a..c541579744b0 100644 --- a/vcl/source/bitmap/BitmapEx.cxx +++ b/vcl/source/bitmap/BitmapEx.cxx @@ -1286,11 +1286,12 @@ tools::Polygon BitmapEx::GetContour( bool bContourEdgeDetect, std::unique_ptr<Point[]> pPoints2; tools::Long nX, nY; sal_uInt16 nPolyPos = 0; - // tdf#161498 use COL_ALPHA_OPAQUE for finding opaque pixels - // Starting with commit 81994cb2b8b32453a92bcb011830fcb884f22ff3, - // pixels now contain an alpha value instead of a transparency - // value. - const BitmapColor aTransparencyOpaque = pAcc->GetBestMatchingColor( COL_ALPHA_OPAQUE ); + // tdf#161833 treat semi-transparent pixels as opaque + // Limiting the contour wrapping polygon to only opaque pixels + // causes clipping of any shadows or other semi-transaprent + // areas in the image. So, instead of testing for fully opaque + // pixels, treat pixels that are not fully transparent as opaque. + const BitmapColor aTransparent = pAcc->GetBestMatchingColor( COL_ALPHA_TRANSPARENT ); pPoints1.reset(new Point[ nHeight ]); pPoints2.reset(new Point[ nHeight ]); @@ -1303,7 +1304,7 @@ tools::Polygon BitmapEx::GetContour( bool bContourEdgeDetect, // scan row from left to right while( nX < nEndX1 ) { - if( aTransparencyOpaque == pAcc->GetPixelFromData( pScanline, nX ) ) + if( aTransparent != pAcc->GetPixelFromData( pScanline, nX ) ) { pPoints1[ nPolyPos ] = Point( nX, nY ); nX = nStartX2; @@ -1311,7 +1312,7 @@ tools::Polygon BitmapEx::GetContour( bool bContourEdgeDetect, // this loop always breaks eventually as there is at least one pixel while( true ) { - if( aTransparencyOpaque == pAcc->GetPixelFromData( pScanline, nX ) ) + if( aTransparent != pAcc->GetPixelFromData( pScanline, nX ) ) { pPoints2[ nPolyPos ] = Point( nX, nY ); break; diff --git a/xmloff/source/text/XMLTextFrameContext.cxx b/xmloff/source/text/XMLTextFrameContext.cxx index 87752f73b199..5c293c7670c2 100644 --- a/xmloff/source/text/XMLTextFrameContext.cxx +++ b/xmloff/source/text/XMLTextFrameContext.cxx @@ -271,17 +271,26 @@ XMLTextFrameContourContext_Impl::XMLTextFrameContourContext_Impl( const SdXMLImExViewBox aViewBox( sViewBox, GetImport().GetMM100UnitConverter()); basegfx::B2DPolyPolygon aPolyPolygon; - if( bPath ) + // Related tdf#161833: ignore saved polygon for "recreate on edit" contours + // tdf#161833 would cause semi-transparent pixels to be treated as fully + // transparent pixels when calculating the wrap contour for an image. To + // force the correct contour when loading a document, force the contour + // to be recalculated by ignoring the saved polygon if the contour is set + // to "recreate on edit". + if( !bAuto ) { - basegfx::utils::importFromSvgD(aPolyPolygon, sD, GetImport().needFixPositionAfterZ(), nullptr); - } - else - { - basegfx::B2DPolygon aPolygon; - - if(basegfx::utils::importFromSvgPoints(aPolygon, sPoints)) + if( bPath ) { - aPolyPolygon = basegfx::B2DPolyPolygon(aPolygon); + basegfx::utils::importFromSvgD(aPolyPolygon, sD, GetImport().needFixPositionAfterZ(), nullptr); + } + else + { + basegfx::B2DPolygon aPolygon; + + if(basegfx::utils::importFromSvgPoints(aPolygon, sPoints)) + { + aPolyPolygon = basegfx::B2DPolyPolygon(aPolygon); + } } } |