summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2014-06-25 16:36:28 +0100
committerCaolán McNamara <caolanm@redhat.com>2014-06-26 16:43:24 +0100
commitdb298f22a04e409a555d7c3ccec4c1dae91a6e1b (patch)
tree2f09557dc33941a9e77bf73e0e583fc5642a2b5f
parentf0c2bb87122307cd7462a84a5196ec24dbfd3fb6 (diff)
Related: fdo#33455 retain color on scaling of 1 bit depth pngs
Change-Id: I445ce672742ddb6d6592ef419bf5e14c5f09a5b5 (cherry picked from commit be9d65bb5f5a83c19eec02a037b8f808de70ecb8)
-rw-r--r--vcl/source/gdi/bitmap3.cxx28
1 files changed, 18 insertions, 10 deletions
diff --git a/vcl/source/gdi/bitmap3.cxx b/vcl/source/gdi/bitmap3.cxx
index 7ee6405a4a6d..0384e0005fa1 100644
--- a/vcl/source/gdi/bitmap3.cxx
+++ b/vcl/source/gdi/bitmap3.cxx
@@ -859,9 +859,7 @@ bool Bitmap::Scale( const double& rScaleX, const double& rScaleY, sal_uInt32 nSc
{
bool bRetval(false);
-#ifdef DBG_UTIL
const sal_uInt16 nStartCount(GetBitCount());
-#endif
if(basegfx::fTools::equalZero(rScaleX) || basegfx::fTools::equalZero(rScaleY))
{
@@ -875,6 +873,22 @@ bool Bitmap::Scale( const double& rScaleX, const double& rScaleY, sal_uInt32 nSc
bRetval = true;
}
+ //fdo#33455
+ //
+ //If we start with a 1 bit image, then after scaling it in any mode except
+ //BMP_SCALE_FAST we have a a 24bit image which is perfectly correct, but we
+ //are going to down-shift it to mono again and Bitmap::ImplMakeMono just
+ //has "Bitmap aNewBmp( GetSizePixel(), 1 );" to create a 1 bit bitmap which
+ //will default to black/white and the colors mapped to which ever is closer
+ //to black/white
+ //
+ //So the easiest thing to do to retain the colors of 1 bit bitmaps is to
+ //just use the fast scale rather than attempting to count unique colors in
+ //the other converters and pass all the info down through
+ //Bitmap::ImplMakeMono
+ if (nStartCount == 1 && nScaleFlag != BMP_SCALE_NONE)
+ nScaleFlag = BMP_SCALE_FAST;
+
switch(nScaleFlag)
{
case BMP_SCALE_NONE :
@@ -894,7 +908,7 @@ bool Bitmap::Scale( const double& rScaleX, const double& rScaleY, sal_uInt32 nSc
}
case BMP_SCALE_SUPER :
{
- if(GetSizePixel().Width() < 2 || GetSizePixel().Height() < 2)
+ if (GetSizePixel().Width() < 2 || GetSizePixel().Height() < 2)
{
// fallback to ImplScaleFast
bRetval = ImplScaleFast( rScaleX, rScaleY );
@@ -936,13 +950,7 @@ bool Bitmap::Scale( const double& rScaleX, const double& rScaleY, sal_uInt32 nSc
}
}
-#ifdef DBG_UTIL
- if(bRetval && nStartCount != GetBitCount())
- {
- OSL_ENSURE(false, "Bitmap::Scale has changed the ColorDepth, this should *not* happen (!)");
- }
-#endif
-
+ OSL_ENSURE(!bRetval || nStartCount == GetBitCount(), "Bitmap::Scale has changed the ColorDepth, this should *not* happen (!)");
return bRetval;
}