From ba8a70365ef459c967cd8a71a6d48ca53dd341bd Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 20 Feb 2018 16:03:20 +0100 Subject: New loplugin:nestedunnamed Change-Id: Ifb434589ef08428ce609bc7a40b015d4df13224c Reviewed-on: https://gerrit.libreoffice.org/50048 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- vcl/source/gdi/dibtools.cxx | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'vcl/source/gdi/dibtools.cxx') diff --git a/vcl/source/gdi/dibtools.cxx b/vcl/source/gdi/dibtools.cxx index 61acb72dfcb2..95c07b589d8d 100644 --- a/vcl/source/gdi/dibtools.cxx +++ b/vcl/source/gdi/dibtools.cxx @@ -321,35 +321,31 @@ bool ImplReadDIBPalette(SvStream& rIStm, BitmapPalette& rPal, bool bQuad) return rIStm.GetError() == ERRCODE_NONE; } -namespace +BitmapColor SanitizePaletteIndex(sal_uInt8 nIndex, BitmapPalette& rPalette, bool bForceToMonoWhileReading) { - BitmapColor SanitizePaletteIndex(sal_uInt8 nIndex, BitmapPalette& rPalette, bool bForceToMonoWhileReading) + const sal_uInt16 nPaletteEntryCount = rPalette.GetEntryCount(); + if (nPaletteEntryCount && nIndex >= nPaletteEntryCount) { - const sal_uInt16 nPaletteEntryCount = rPalette.GetEntryCount(); - if (nPaletteEntryCount && nIndex >= nPaletteEntryCount) - { - auto nSanitizedIndex = nIndex % nPaletteEntryCount; - SAL_WARN_IF(nIndex != nSanitizedIndex, "vcl", "invalid colormap index: " - << static_cast(nIndex) << ", colormap len is: " - << nPaletteEntryCount); - nIndex = nSanitizedIndex; - } - - if (nPaletteEntryCount && bForceToMonoWhileReading) - { - return BitmapColor(static_cast(rPalette[nIndex].GetLuminance() >= 255)); - } - - return BitmapColor(nIndex); + auto nSanitizedIndex = nIndex % nPaletteEntryCount; + SAL_WARN_IF(nIndex != nSanitizedIndex, "vcl", "invalid colormap index: " + << static_cast(nIndex) << ", colormap len is: " + << nPaletteEntryCount); + nIndex = nSanitizedIndex; } - BitmapColor SanitizeColor(const BitmapColor &rColor, bool bForceToMonoWhileReading) + if (nPaletteEntryCount && bForceToMonoWhileReading) { - if (!bForceToMonoWhileReading) - return rColor; - return BitmapColor(static_cast(rColor.GetLuminance() >= 255)); + return BitmapColor(static_cast(rPalette[nIndex].GetLuminance() >= 255)); } + return BitmapColor(nIndex); +} + +BitmapColor SanitizeColor(const BitmapColor &rColor, bool bForceToMonoWhileReading) +{ + if (!bForceToMonoWhileReading) + return rColor; + return BitmapColor(static_cast(rColor.GetLuminance() >= 255)); } bool ImplDecodeRLE(sal_uInt8* pBuffer, DIBV5Header const & rHeader, BitmapWriteAccess& rAcc, BitmapPalette& rPalette, bool bForceToMonoWhileReading, bool bRLE4) -- cgit