prevent SkiaSalBitmap::Scale() from breaking indexed bitmaps (tdf#134574)

Since the actual scaling is done later at some unknown time,
the palette mustn't change, but scaling can change colors.

Change-Id: Ie254c8b31993d9d509c32a730dd8c8b5d3cb2256
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98258
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
This commit is contained in:
Luboš Luňák 2020-07-07 12:15:20 +00:00 committed by Luboš Luňák
parent 843e30dc23
commit 3769d01791

View file

@ -296,8 +296,8 @@ bool SkiaSalBitmap::Scale(const double& rScaleX, const double& rScaleY, BmpScale
if (mSize == newSize)
return true;
SAL_INFO("vcl.skia.trace", "scale(" << this << "): " << mSize << "->" << newSize << ":"
<< static_cast<int>(nScaleFlag));
SAL_INFO("vcl.skia.trace", "scale(" << this << "): " << mSize << "/" << mBitCount << "->"
<< newSize << ":" << static_cast<int>(nScaleFlag));
// The idea here is that the actual scaling will be delayed until the result
// is actually needed. Usually the scaled bitmap will be drawn somewhere,
@ -319,8 +319,18 @@ bool SkiaSalBitmap::Scale(const double& rScaleX, const double& rScaleY, BmpScale
currentQuality = kHigh_SkFilterQuality;
break;
default:
SAL_INFO("vcl.skia.trace", "scale(" << this << "): unsupported scale algorithm");
return false;
}
if (mBitCount < 24 && !mPalette.IsGreyPalette8Bit())
{
// Scaling can introduce additional colors not present in the original
// bitmap (e.g. when smoothing). If the bitmap is indexed (has non-trivial palette),
// this would break the bitmap, because the actual scaling is done only somewhen later.
// Linear 8bit palette (grey) is ok, since there we use directly the values as colors.
SAL_INFO("vcl.skia.trace", "scale(" << this << "): indexed bitmap");
return false;
}
// if there is already one scale() pending, use the lowest quality of all requested
static_assert(kMedium_SkFilterQuality < kHigh_SkFilterQuality);
mScaleQuality = std::min(mScaleQuality, currentQuality);