From 133010a0efc8715f95e0ea0f66c22352dd55654a Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Fri, 28 Jul 2017 10:07:50 +0100 Subject: ofz#2766 ensure palette is large enough for all colors Change-Id: I4669b473f5975ac74a37025f7c936f13bcfea420 Reviewed-on: https://gerrit.libreoffice.org/40513 Tested-by: Jenkins Reviewed-by: Michael Stahl --- filter/source/graphicfilter/itiff/itiff.cxx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/filter/source/graphicfilter/itiff/itiff.cxx b/filter/source/graphicfilter/itiff/itiff.cxx index db1ddccd1e64..7031d7daee30 100644 --- a/filter/source/graphicfilter/itiff/itiff.cxx +++ b/filter/source/graphicfilter/itiff/itiff.cxx @@ -1111,7 +1111,7 @@ void TIFFReader::MakePalCol() { if ( nDstBitsPerPixel <= 8 ) { - sal_uLong i, nVal, n0RGB; + sal_uLong nVal, n0RGB; if ( pColorMap == nullptr ) pColorMap = new sal_uLong[ 256 ]; if ( nPhotometricInterpretation <= 1 ) @@ -1124,8 +1124,8 @@ void TIFFReader::MakePalCol() SAL_WARN("filter.tiff", "palette has less entries that largest index used. Expanding palette to match"); nNumColors = nLargestPixelIndex + 1; } - pAcc->SetPaletteEntryCount( (sal_uInt16)nNumColors ); - for ( i = 0; i < nNumColors; i++ ) + + for (sal_uLong i = 0; i < nNumColors; ++i) { nVal = ( i * 255 / ( nNumColors - 1 ) ) & 0xff; n0RGB = nVal | ( nVal << 8 ) | ( nVal << 16 ); @@ -1135,7 +1135,8 @@ void TIFFReader::MakePalCol() pColorMap[ nNumColors - i - 1 ] = n0RGB; } } - for ( i = 0; i < nNumColors; i++ ) + pAcc->SetPaletteEntryCount(std::max(nNumColors, pAcc->GetPaletteEntryCount())); + for (sal_uLong i = 0; i < nNumColors; ++i) { pAcc->SetPaletteColor( (sal_uInt16)i, BitmapColor( (sal_uInt8)( pColorMap[ i ] >> 16 ), (sal_uInt8)( pColorMap[ i ] >> 8 ), (sal_uInt8)pColorMap[ i ] ) ); -- cgit v1.2.3