diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2021-04-19 16:38:18 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2021-04-20 11:04:32 +0200 |
commit | ff9362ea961e4783707871cc60b72e602952fe05 (patch) | |
tree | 01924a4510bf41846d961d4eca499b4a819a6512 /vcl | |
parent | f6ebc30cdc3fb5673beec61c1325c3831adb4886 (diff) |
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.lunak@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/bitmap/BitmapTools.cxx | 37 |
1 files changed, 34 insertions, 3 deletions
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; + } } } |