vcl/source/bitmap/BitmapTools.cxx | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-)
New commits: commit ff9362ea961e4783707871cc60b72e602952fe05 Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Mon Apr 19 16:38:18 2021 +0200 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Tue Apr 20 11:04:32 2021 +0200 fake 1bpp 2-color pattern bitmap if loaded as RGB (tdf#141612) The new PNG loader no longer loads 1bpp bitmaps as 1bpp, which breaks the reliance of this old code on detecting pattern bitmaps by being 1bpp. Count instead the number of colors and pretend the bitmap is a 2-color bitmap if that's the case. The commit fixing tdf#119282 says that doesn't work, but I do not see any problem, any 2-color 8x8 bitmap is essentially a pattern. Change-Id: Iea1bb2e2a2c06404e2ebdbdd6a899b1ab1e1afae Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114295 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lu...@collabora.com> diff --git a/vcl/source/bitmap/BitmapTools.cxx b/vcl/source/bitmap/BitmapTools.cxx index d963bb3bb85b..168cf95fb9e0 100644 --- a/vcl/source/bitmap/BitmapTools.cxx +++ b/vcl/source/bitmap/BitmapTools.cxx @@ -1022,9 +1022,6 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un if(pRead->HasPalette() && 2 == pRead->GetPaletteEntryCount()) { const BitmapPalette& rPalette = pRead->GetPalette(); - - // #i123564# background and foreground were exchanged; of course - // rPalette[0] is the background color o_rFront = rPalette[1]; o_rBack = rPalette[0]; @@ -1034,6 +1031,40 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, Bitmap & aBitmap, un Bitmap::ReleaseAccess(pRead); } } + else + { + // Historical 1bpp images are getting really historical, + // even to the point that e.g. the png loader actually loads + // them as RGB. But the pattern code in svx relies on this + // assumption that any 2-color 1bpp bitmap is a pattern, and so it would + // get confused by RGB. Try to detect if this image is really + // just two colors and say it's a pattern bitmap if so. + Bitmap::ScopedReadAccess access(aBitmap); + o_rBack = access->GetColor(0,0); + bool foundSecondColor = false;; + for(tools::Long y = 0; y < access->Height(); ++y) + for(tools::Long x = 0; x < access->Width(); ++x) + { + if(!foundSecondColor) + { + if( access->GetColor(y,x) != o_rBack ) + { + o_rFront = access->GetColor(y,x); + foundSecondColor = true; + // Hard to know which of the two colors is the background, + // select the lighter one. + if( o_rFront.GetLuminance() > o_rBack.GetLuminance()) + std::swap( o_rFront, o_rBack ); + } + } + else + { + if( access->GetColor(y,x) != o_rBack && access->GetColor(y,x) != o_rFront) + return false; + } + } + return true; + } } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits