summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2017-04-03 10:12:22 +0100
committerCaolán McNamara <caolanm@redhat.com>2017-04-03 10:13:18 +0100
commitf2b52c8597b51813761048f43d60d94a661ca58d (patch)
tree9ebd1c4b2cb285156264c0df2e6f7a5b7d1963b8 /filter
parent92fbd5a325a462aadfefae2023e99712716de7db (diff)
coverity#1403736 Unintentional integer overflow
Change-Id: I3902dda8f7b420ea3f5e7e8c5d50a47b7e762918
Diffstat (limited to 'filter')
-rw-r--r--filter/source/graphicfilter/itiff/itiff.cxx224
1 files changed, 106 insertions, 118 deletions
diff --git a/filter/source/graphicfilter/itiff/itiff.cxx b/filter/source/graphicfilter/itiff/itiff.cxx
index b5c63d2c2adb..68d838482d67 100644
--- a/filter/source/graphicfilter/itiff/itiff.cxx
+++ b/filter/source/graphicfilter/itiff/itiff.cxx
@@ -56,52 +56,52 @@ private:
pAlphaMask;
BitmapWriteAccess* pMaskAcc;
- sal_uLong nOrigPos; // start position in pTIFF
- sal_uLong nEndOfFile; // end of file position in pTIFF
+ sal_uInt64 nOrigPos; // start position in pTIFF
+ sal_uInt64 nEndOfFile; // end of file position in pTIFF
sal_uInt16 nDataType;
// Data taken from the TIFF tags:
- bool bByteSwap; // sal_True if bits 0..7 -> 7..0 should get converted ( FILLORDER = 2 );
+ bool bByteSwap; // sal_True if bits 0..7 -> 7..0 should get converted ( FILLORDER = 2 );
- sal_uLong nNewSubFile;
- sal_uLong nSubFile;
+ sal_uInt32 nNewSubFile;
+ sal_uInt32 nSubFile;
sal_Int32 nImageWidth; // picture width in pixels
sal_Int32 nImageLength; // picture height in pixels
sal_uInt32 nBitsPerSample; // bits per pixel per layer
- sal_uLong nCompression; // kind of compression
- sal_uLong nPhotometricInterpretation;
- sal_uLong nThresholding;
- sal_uLong nCellWidth;
- sal_uLong nCellLength;
- sal_uLong nFillOrder;
- sal_uLong* pStripOffsets; // field of offsets to the Bitmap-Data-"Strips"
- sal_uLong nNumStripOffsets; // size of the field above
- sal_uLong nOrientation;
+ sal_uInt32 nCompression; // kind of compression
+ sal_uInt32 nPhotometricInterpretation;
+ sal_uInt32 nThresholding;
+ sal_uInt32 nCellWidth;
+ sal_uInt32 nCellLength;
+ sal_uInt32 nFillOrder;
+ sal_uInt64* pStripOffsets; // field of offsets to the Bitmap-Data-"Strips"
+ sal_uInt32 nNumStripOffsets; // size of the field above
+ sal_uInt32 nOrientation;
sal_uInt32 nSamplesPerPixel; // number of layers
- sal_uLong nRowsPerStrip; // if it's not compressed: number of rows per Strip
- sal_uLong* pStripByteCounts; // if compressed (in a certain way): size of the strips
- sal_uLong nNumStripByteCounts; // number of entries in the field above
- sal_uLong nMinSampleValue;
- sal_uLong nMaxSampleValue;
+ sal_uInt32 nRowsPerStrip; // if it's not compressed: number of rows per Strip
+ sal_uInt32* pStripByteCounts; // if compressed (in a certain way): size of the strips
+ sal_uInt32 nNumStripByteCounts; // number of entries in the field above
+ sal_uInt32 nMinSampleValue;
+ sal_uInt32 nMaxSampleValue;
double fXResolution; // X-resolution or 0.0
double fYResolution; // Y-resolution or 0.0
- sal_uLong nPlanarConfiguration;
- sal_uLong nGroup3Options;
- sal_uLong nGroup4Options;
- sal_uLong nResolutionUnit; // unit of fX/YResolution: 1=unknown, 2(default)=inch, 3=cm
- sal_uLong nPredictor;
+ sal_uInt32 nPlanarConfiguration;
+ sal_uInt32 nGroup3Options;
+ sal_uInt32 nGroup4Options;
+ sal_uInt32 nResolutionUnit; // unit of fX/YResolution: 1=unknown, 2(default)=inch, 3=cm
+ sal_uInt32 nPredictor;
std::unique_ptr<sal_uInt32[]> xColorMap; // color palette
- sal_uLong nNumColors; // number of colors within the color palette
+ sal_uInt32 nNumColors; // number of colors within the color palette
sal_uInt32 nPlanes; // number of layers within the Tiff file
- sal_uLong nStripsPerPlane; // number of Strips per layer
+ sal_uInt32 nStripsPerPlane; // number of Strips per layer
sal_uInt32 nBytesPerRow; // Bytes per line per Layer in the Tiff file ( uncompressed )
sal_uInt8* pMap[ 4 ]; // temporary Scanline
- sal_uLong DataTypeSize();
- sal_uLong ReadIntData();
+ sal_uInt32 DataTypeSize();
+ sal_uInt32 ReadIntData();
double ReadDoubleData();
void ReadHeader();
@@ -110,7 +110,7 @@ private:
bool ReadMap();
// reads/decompresses the bitmap data and fills pMap
- sal_uLong GetBits( const sal_uInt8 * pSrc, sal_uLong nBitsPos, sal_uLong nBitsCount );
+ sal_uInt32 GetBits(const sal_uInt8 * pSrc, sal_uInt32 nBitsPos, sal_uInt32 nBitsCount);
// fetches BitsCount bits from pSrc[..] at the position nBitsPos
void MakePalCol();
@@ -169,7 +169,7 @@ public:
pMap[ 0 ] = pMap[ 1 ] = pMap[ 2 ] = pMap[ 3 ] = nullptr;
}
- sal_uLong GetRowsPerStrip() const
+ sal_uInt32 GetRowsPerStrip() const
{
//Rows Per Strip:
//
@@ -187,9 +187,9 @@ public:
//=================== Methods of TIFFReader ==============================
-sal_uLong TIFFReader::DataTypeSize()
+sal_uInt32 TIFFReader::DataTypeSize()
{
- sal_uLong nSize;
+ sal_uInt32 nSize;
switch ( nDataType )
{
case 1 : // BYTE
@@ -219,7 +219,7 @@ sal_uLong TIFFReader::DataTypeSize()
return nSize;
}
-sal_uLong TIFFReader::ReadIntData()
+sal_uInt32 TIFFReader::ReadIntData()
{
double nDOUBLE(0.0);
float nFLOAT(0);
@@ -237,11 +237,11 @@ sal_uLong TIFFReader::ReadIntData()
case 2 :
case 7 :
pTIFF->ReadUChar( nBYTE );
- nUINT32a = (sal_uLong)nBYTE;
+ nUINT32a = nBYTE;
break;
case 3 :
pTIFF->ReadUInt16( nUINT16 );
- nUINT32a = (sal_uLong)nUINT16;
+ nUINT32a = nUINT16;
break;
case 9 :
case 4 :
@@ -362,11 +362,10 @@ void TIFFReader::ReadTagData( sal_uInt16 nTagType, sal_uInt32 nDataLen)
break;
case 0x0111: { // Strip Offset(s)
- sal_uLong nOldNumSO, i, * pOldSO;
- pOldSO = pStripOffsets;
+ sal_uInt64* pOldSO = pStripOffsets;
if ( pOldSO == nullptr )
nNumStripOffsets = 0;
- nOldNumSO = nNumStripOffsets;
+ sal_uInt32 nOldNumSO = nNumStripOffsets;
nDataLen += nOldNumSO;
size_t nMaxAllocAllowed = SAL_MAX_UINT32 / sizeof(sal_uInt32);
size_t nMaxRecordsAvailable = pTIFF->remainingSize() / DataTypeSize();
@@ -376,7 +375,7 @@ void TIFFReader::ReadTagData( sal_uInt16 nTagType, sal_uInt32 nDataLen)
nNumStripOffsets = nDataLen;
try
{
- pStripOffsets = new sal_uLong[ nNumStripOffsets ];
+ pStripOffsets = new sal_uInt64[nNumStripOffsets];
}
catch (const std::bad_alloc &)
{
@@ -385,9 +384,9 @@ void TIFFReader::ReadTagData( sal_uInt16 nTagType, sal_uInt32 nDataLen)
}
if ( pStripOffsets )
{
- for ( i = 0; i < nOldNumSO; i++ )
+ for (sal_uInt32 i = 0; i < nOldNumSO; ++i)
pStripOffsets[ i ] = pOldSO[ i ] + nOrigPos;
- for ( i = nOldNumSO; i < nNumStripOffsets; i++ )
+ for (sal_uInt32 i = nOldNumSO; i < nNumStripOffsets; ++i)
pStripOffsets[ i ] = ReadIntData() + nOrigPos;
}
delete[] pOldSO;
@@ -411,11 +410,10 @@ void TIFFReader::ReadTagData( sal_uInt16 nTagType, sal_uInt32 nDataLen)
break;
case 0x0117: { // Strip Byte Counts
- sal_uLong nOldNumSBC, i, * pOldSBC;
- pOldSBC = pStripByteCounts;
- if ( pOldSBC == nullptr )
+ sal_uInt32* pOldSBC = pStripByteCounts;
+ if (pOldSBC == nullptr)
nNumStripByteCounts = 0; // to be on the safe side
- nOldNumSBC = nNumStripByteCounts;
+ sal_uInt32 nOldNumSBC = nNumStripByteCounts;
nDataLen += nOldNumSBC;
size_t nMaxAllocAllowed = SAL_MAX_UINT32 / sizeof(sal_uInt32);
size_t nMaxRecordsAvailable = pTIFF->remainingSize() / DataTypeSize();
@@ -425,7 +423,7 @@ void TIFFReader::ReadTagData( sal_uInt16 nTagType, sal_uInt32 nDataLen)
nNumStripByteCounts = nDataLen;
try
{
- pStripByteCounts = new sal_uLong[ nNumStripByteCounts ];
+ pStripByteCounts = new sal_uInt32[nNumStripByteCounts];
}
catch (const std::bad_alloc &)
{
@@ -434,9 +432,9 @@ void TIFFReader::ReadTagData( sal_uInt16 nTagType, sal_uInt32 nDataLen)
}
if ( pStripByteCounts )
{
- for ( i = 0; i < nOldNumSBC; i++ )
+ for (sal_uInt32 i = 0; i < nOldNumSBC; ++i)
pStripByteCounts[ i ] = pOldSBC[ i ];
- for ( i = nOldNumSBC; i < nNumStripByteCounts; i++)
+ for (sal_uInt32 i = nOldNumSBC; i < nNumStripByteCounts; ++i)
pStripByteCounts[ i ] = ReadIntData();
}
delete[] pOldSBC;
@@ -488,24 +486,23 @@ void TIFFReader::ReadTagData( sal_uInt16 nTagType, sal_uInt32 nDataLen)
case 0x0140: { // Color Map
sal_uInt16 nVal;
- sal_uLong i;
- nNumColors= ( (sal_uLong)1 << nBitsPerSample );
+ nNumColors = ((sal_uInt32)1 << nBitsPerSample);
if ( nDataType == 3 && nNumColors <= 256)
{
xColorMap.reset(new sal_uInt32[256]);
- for ( i = 0; i < nNumColors; i++ )
+ for (sal_uInt32 i = 0; i < nNumColors; ++i)
xColorMap[i] = 0;
- for ( i = 0; i < nNumColors; i++ )
+ for (sal_uInt32 i = 0; i < nNumColors; ++i)
{
pTIFF->ReadUInt16( nVal );
xColorMap[i] |= ( ( (sal_uInt32)nVal ) << 8 ) & 0x00ff0000;
}
- for ( i = 0; i < nNumColors; i++ )
+ for (sal_uInt32 i = 0; i < nNumColors; ++i)
{
pTIFF->ReadUInt16( nVal );
xColorMap[i] |= ( (sal_uInt32)nVal ) & 0x0000ff00;
}
- for ( i = 0; i < nNumColors; i++ )
+ for (sal_uInt32 i = 0; i < nNumColors; ++i)
{
pTIFF->ReadUInt16( nVal );
xColorMap[i] |= ( ( (sal_uInt32)nVal ) >> 8 ) & 0x000000ff;
@@ -518,7 +515,7 @@ void TIFFReader::ReadTagData( sal_uInt16 nTagType, sal_uInt32 nDataLen)
}
case 0x0153: { // SampleFormat
- sal_uLong nSampleFormat = ReadIntData();
+ sal_uInt32 nSampleFormat = ReadIntData();
if ( nSampleFormat == 3 ) // IEEE floating point samples are not supported yet
bStatus = false;
break;
@@ -534,7 +531,7 @@ bool TIFFReader::ReadMap()
{
if ( nCompression == 1 || nCompression == 32771 )
{
- sal_uLong nStrip, nStripBytesPerRow;
+ sal_uInt32 nStrip, nStripBytesPerRow;
if ( nCompression == 1 )
nStripBytesPerRow = nBytesPerRow;
@@ -542,7 +539,7 @@ bool TIFFReader::ReadMap()
nStripBytesPerRow = ( nBytesPerRow + 1 ) & 0xfffffffe;
for (sal_Int32 ny = 0; ny < nImageLength; ++ny)
{
- for (sal_uLong np = 0; np < nPlanes; ++np)
+ for (sal_uInt32 np = 0; np < nPlanes; ++np)
{
nStrip = ny / GetRowsPerStrip() + np * nStripsPerPlane;
if ( nStrip >= nNumStripOffsets )
@@ -560,7 +557,7 @@ bool TIFFReader::ReadMap()
}
else if ( nCompression == 2 || nCompression == 3 || nCompression == 4 )
{
- sal_uLong nStrip, nOptions;
+ sal_uInt32 nStrip, nOptions;
if ( nCompression == 2 )
{
nOptions = CCI_OPTION_BYTEALIGNROW;
@@ -589,7 +586,7 @@ bool TIFFReader::ReadMap()
nStrip = 0;
if ( nStrip >= nNumStripOffsets )
return false;
- sal_uLong nOffset = pStripOffsets[nStrip];
+ sal_uInt64 nOffset = pStripOffsets[nStrip];
if (nOffset > nEndOfFile)
return false;
pTIFF->Seek(pStripOffsets[nStrip]);
@@ -602,7 +599,7 @@ bool TIFFReader::ReadMap()
for (sal_Int32 ny = 0; ny < nImageLength; ++ny)
{
bDifferentToPrev = ny == 0;
- for (sal_uLong np = 0; np < nPlanes; np++ )
+ for (sal_uInt32 np = 0; np < nPlanes; ++np)
{
if ( ny / GetRowsPerStrip() + np * nStripsPerPlane > nStrip )
{
@@ -643,15 +640,14 @@ bool TIFFReader::ReadMap()
else if ( nCompression == 5 )
{
LZWDecompressor aLZWDecom;
- sal_uLong nStrip;
- nStrip=0;
+ sal_uInt32 nStrip(0);
if ( nStrip >= nNumStripOffsets )
return false;
pTIFF->Seek(pStripOffsets[nStrip]);
aLZWDecom.StartDecompression(*pTIFF);
for (sal_Int32 ny = 0; ny < nImageLength; ++ny)
{
- for (sal_uLong np = 0; np < nPlanes; ++np)
+ for (sal_uInt32 np = 0; np < nPlanes; ++np)
{
if ( ny / GetRowsPerStrip() + np * nStripsPerPlane > nStrip )
{
@@ -672,15 +668,13 @@ bool TIFFReader::ReadMap()
}
else if ( nCompression == 32773 )
{
- sal_uLong nStrip,nRecCount,i;
- sal_uInt8 * pdst;
- nStrip = 0;
- if ( nStrip >= nNumStripOffsets )
+ sal_uInt32 nStrip(0);
+ if (nStrip >= nNumStripOffsets)
return false;
pTIFF->Seek(pStripOffsets[nStrip]);
for (sal_Int32 ny = 0; ny < nImageLength; ++ny)
{
- for (sal_uLong np = 0; np < nPlanes; ++np)
+ for (sal_uInt32 np = 0; np < nPlanes; ++np)
{
if ( ny / GetRowsPerStrip() + np * nStripsPerPlane > nStrip )
{
@@ -689,17 +683,18 @@ bool TIFFReader::ReadMap()
return false;
pTIFF->Seek(pStripOffsets[nStrip]);
}
- sal_uLong nRowBytesLeft = nBytesPerRow;
+ sal_uInt32 nRowBytesLeft = nBytesPerRow;
if (np >= SAL_N_ELEMENTS(pMap))
return false;
- pdst=pMap[ np ];
+ sal_uInt8* pdst = pMap[np];
do
{
sal_uInt8 nRecHeader(0);
- pTIFF->ReadUChar( nRecHeader );
+ pTIFF->ReadUChar(nRecHeader);
+ sal_uInt32 nRecCount;
if ((nRecHeader&0x80)==0)
{
- nRecCount=0x00000001+((sal_uLong)nRecHeader);
+ nRecCount=0x00000001 + ((sal_uInt32)nRecHeader);
if ( nRecCount > nRowBytesLeft )
return false;
pTIFF->ReadBytes(pdst, nRecCount);
@@ -710,18 +705,14 @@ bool TIFFReader::ReadMap()
}
else if ( nRecHeader != 0x80 )
{
- nRecCount = 0x000000101 - ( (sal_uLong)nRecHeader );
+ nRecCount = 0x000000101 - ((sal_uInt32)nRecHeader);
if ( nRecCount > nRowBytesLeft )
{
nRecCount = nRowBytesLeft;
-
-// bStatus = sal_False;
-// return;
-
}
sal_uInt8 nRecData(0);
pTIFF->ReadUChar( nRecData );
- for ( i = 0; i < nRecCount; i++ )
+ for (sal_uInt32 i = 0; i < nRecCount; ++i)
*(pdst++) = nRecData;
nRowBytesLeft -= nRecCount;
}
@@ -738,15 +729,15 @@ bool TIFFReader::ReadMap()
return true;
}
-sal_uLong TIFFReader::GetBits( const sal_uInt8 * pSrc, sal_uLong nBitsPos, sal_uLong nBitsCount )
+sal_uInt32 TIFFReader::GetBits( const sal_uInt8 * pSrc, sal_uInt32 nBitsPos, sal_uInt32 nBitsCount)
{
- sal_uLong nRes;
+ sal_uInt32 nRes;
if ( bByteSwap )
{
pSrc += ( nBitsPos >> 3 );
nBitsPos &= 7;
sal_uInt8 nDat = *pSrc;
- nRes = (sal_uLong)( BYTESWAP( nDat ) & ( 0xff >> nBitsPos ) );
+ nRes = (sal_uInt32)( BYTESWAP( nDat ) & ( 0xff >> nBitsPos ) );
if ( nBitsCount <= 8 - nBitsPos )
{
@@ -759,13 +750,13 @@ sal_uLong TIFFReader::GetBits( const sal_uInt8 * pSrc, sal_uLong nBitsPos, sal_u
while ( nBitsCount >= 8 )
{
nDat = *(pSrc++);
- nRes = ( nRes << 8 ) | ((sal_uLong)BYTESWAP( nDat ) );
+ nRes = ( nRes << 8 ) | ((sal_uInt32)BYTESWAP( nDat ) );
nBitsCount -= 8;
}
if ( nBitsCount > 0 )
{
nDat = *pSrc;
- nRes = ( nRes << nBitsCount ) | (((sal_uLong)BYTESWAP(nDat))>>(8-nBitsCount));
+ nRes = ( nRes << nBitsCount ) | (((sal_uInt32)BYTESWAP(nDat))>>(8-nBitsCount));
}
}
}
@@ -773,7 +764,7 @@ sal_uLong TIFFReader::GetBits( const sal_uInt8 * pSrc, sal_uLong nBitsPos, sal_u
{
pSrc += ( nBitsPos >> 3 );
nBitsPos &= 7;
- nRes = (sal_uLong)((*pSrc)&(0xff>>nBitsPos));
+ nRes = (sal_uInt32)((*pSrc)&(0xff>>nBitsPos));
if ( nBitsCount <= 8 - nBitsPos )
{
nRes >>= ( 8 - nBitsPos - nBitsCount );
@@ -784,11 +775,11 @@ sal_uLong TIFFReader::GetBits( const sal_uInt8 * pSrc, sal_uLong nBitsPos, sal_u
nBitsCount -= 8 - nBitsPos;
while ( nBitsCount >= 8 )
{
- nRes = ( nRes << 8 ) | ((sal_uLong)*(pSrc++));
+ nRes = ( nRes << 8 ) | ((sal_uInt32)*(pSrc++));
nBitsCount -= 8;
}
if ( nBitsCount > 0 )
- nRes = ( nRes << nBitsCount ) | (((sal_uLong)*pSrc)>>(8-nBitsCount));
+ nRes = ( nRes << nBitsCount ) | (((sal_uInt32)*pSrc)>>(8-nBitsCount));
}
}
return nRes;
@@ -844,7 +835,7 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY)
{
if ( nMaxSampleValue > nMinSampleValue )
{
- sal_uLong nMinMax = nMinSampleValue * 255 / ( nMaxSampleValue - nMinSampleValue );
+ sal_uInt32 nMinMax = nMinSampleValue * 255 / ( nMaxSampleValue - nMinSampleValue );
for (sal_Int32 nx = 0; nx < nImageWidth; ++nx)
{
if ( nPlanes < 3 )
@@ -867,7 +858,7 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY)
{
if ( nMaxSampleValue > nMinSampleValue )
{
- sal_uLong nMinMax = nMinSampleValue * 255 / ( nMaxSampleValue - nMinSampleValue );
+ sal_uInt32 nMinMax = nMinSampleValue * 255 / ( nMaxSampleValue - nMinSampleValue );
for (sal_Int32 nx = 0; nx < nImageWidth; ++nx)
{
if ( nPlanes < 3 )
@@ -921,12 +912,12 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY)
}
}
const long nBlack = nSamp[ 3 ];
- nRed = (sal_uInt8) std::max( 0L, 255L - ( ( (long) nSamp[ 0 ] + nBlack - ( ( (long) nMinSampleValue ) << 1 ) ) *
- 255L/(long)(nMaxSampleValue-nMinSampleValue) ) );
- nGreen = (sal_uInt8) std::max( 0L, 255L - ( ( (long) nSamp[ 1 ] + nBlack - ( ( (long) nMinSampleValue ) << 1 ) ) *
- 255L/(long)(nMaxSampleValue-nMinSampleValue) ) );
- nBlue = (sal_uInt8) std::max( 0L, 255L - ( ( (long) nSamp[ 2 ] + nBlack - ( ( (long) nMinSampleValue ) << 1 ) ) *
- 255L/(long)(nMaxSampleValue-nMinSampleValue) ) );
+ nRed = (sal_uInt8) std::max( 0L, 255L - ( ( (sal_Int32) nSamp[ 0 ] + nBlack - ( ( (sal_Int32) nMinSampleValue ) << 1 ) ) *
+ 255L/(sal_Int32)(nMaxSampleValue-nMinSampleValue) ) );
+ nGreen = (sal_uInt8) std::max( 0L, 255L - ( ( (sal_Int32) nSamp[ 1 ] + nBlack - ( ( (sal_Int32) nMinSampleValue ) << 1 ) ) *
+ 255L/(sal_Int32)(nMaxSampleValue-nMinSampleValue) ) );
+ nBlue = (sal_uInt8) std::max( 0L, 255L - ( ( (sal_Int32) nSamp[ 2 ] + nBlack - ( ( (sal_Int32) nMinSampleValue ) << 1 ) ) *
+ 255L/(sal_Int32)(nMaxSampleValue-nMinSampleValue) ) );
pAcc->SetPixel( nY, nx, Color ( (sal_uInt8)nRed, (sal_uInt8)nGreen, (sal_uInt8)nBlue ) );
}
}
@@ -936,7 +927,7 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY)
{
if ( nMaxSampleValue > nMinSampleValue )
{
- sal_uLong nMinMax = ( ( 1 << nDstBitsPerPixel ) - 1 ) / ( nMaxSampleValue - nMinSampleValue );
+ sal_uInt32 nMinMax = ( ( 1 << nDstBitsPerPixel ) - 1 ) / ( nMaxSampleValue - nMinSampleValue );
sal_uInt8* pt = pMap[ 0 ];
sal_uInt8* ptend = pt + nBytesPerRow;
sal_uInt8 nShift;
@@ -964,7 +955,7 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY)
for (sal_Int32 nx = 0; nx < nImageWidth; ++nx)
{
sal_uInt8 nLast = *pt++;
- pAcc->SetPixelIndex( nY, nx, static_cast<sal_uInt8>( (BYTESWAP((sal_uLong)nLast) - nMinSampleValue) * nMinMax ) );
+ pAcc->SetPixelIndex( nY, nx, static_cast<sal_uInt8>( (BYTESWAP((sal_uInt32)nLast) - nMinSampleValue) * nMinMax ) );
}
}
}
@@ -983,7 +974,7 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY)
{
for (sal_Int32 nx = 0; nx < nImageWidth; ++nx)
{
- pAcc->SetPixelIndex( nY, nx, static_cast<sal_uInt8>( ((sal_uLong)*pt++ - nMinSampleValue) * nMinMax ) );
+ pAcc->SetPixelIndex( nY, nx, static_cast<sal_uInt8>( ((sal_uInt32)*pt++ - nMinSampleValue) * nMinMax ) );
}
}
@@ -1095,11 +1086,11 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY)
{
if ( nMaxSampleValue > nMinSampleValue )
{
- sal_uLong nMinMax = ( ( 1 << 8 /*nDstBitsPerPixel*/ ) - 1 ) / ( nMaxSampleValue - nMinSampleValue );
+ sal_uInt32 nMinMax = ( ( 1 << 8 /*nDstBitsPerPixel*/ ) - 1 ) / ( nMaxSampleValue - nMinSampleValue );
sal_uInt8* pt = pMap[ 0 ];
for (sal_Int32 nx = 0; nx < nImageWidth; nx++, pt += 2 )
{
- pAcc->SetPixelIndex( nY, nx, static_cast<sal_uInt8>( ((sal_uLong)*pt - nMinSampleValue) * nMinMax) );
+ pAcc->SetPixelIndex( nY, nx, static_cast<sal_uInt8>( ((sal_uInt32)*pt - nMinSampleValue) * nMinMax) );
}
}
}
@@ -1113,18 +1104,17 @@ void TIFFReader::MakePalCol()
{
if ( nDstBitsPerPixel <= 8 )
{
- sal_uLong i, nVal;
if (!xColorMap)
xColorMap.reset(new sal_uInt32[256]);
if ( nPhotometricInterpretation <= 1 )
{
- nNumColors = (sal_uLong)1 << nBitsPerSample;
+ nNumColors = (sal_uInt32)1 << nBitsPerSample;
if ( nNumColors > 256 )
nNumColors = 256;
- pAcc->SetPaletteEntryCount( (sal_uInt16)nNumColors );
- for ( i = 0; i < nNumColors; i++ )
+ pAcc->SetPaletteEntryCount(nNumColors);
+ for (sal_uInt32 i = 0; i < nNumColors; ++i)
{
- nVal = ( i * 255 / ( nNumColors - 1 ) ) & 0xff;
+ sal_uInt32 nVal = ( i * 255 / ( nNumColors - 1 ) ) & 0xff;
sal_uInt32 n0RGB = nVal | ( nVal << 8 ) | ( nVal << 16 );
if ( nPhotometricInterpretation == 1 )
xColorMap[i] = n0RGB;
@@ -1132,25 +1122,25 @@ void TIFFReader::MakePalCol()
xColorMap[nNumColors - i - 1] = n0RGB;
}
}
- for ( i = 0; i < nNumColors; i++ )
+ for (sal_uInt32 i = 0; i < nNumColors; ++i)
{
- pAcc->SetPaletteColor( (sal_uInt16)i, BitmapColor( (sal_uInt8)( xColorMap[ i ] >> 16 ),
+ pAcc->SetPaletteColor(i, BitmapColor( (sal_uInt8)( xColorMap[ i ] >> 16 ),
(sal_uInt8)( xColorMap[ i ] >> 8 ), (sal_uInt8)xColorMap[ i ] ) );
}
}
if ( fXResolution > 1.0 && fYResolution > 1.0 && ( nResolutionUnit == 2 || nResolutionUnit == 3 ) )
{
- sal_uLong nRX,nRY;
+ sal_uInt32 nRX, nRY;
if (nResolutionUnit==2)
{
- nRX=(sal_uLong)(fXResolution+0.5);
- nRY=(sal_uLong)(fYResolution+0.5);
+ nRX=(sal_uInt32)(fXResolution+0.5);
+ nRY=(sal_uInt32)(fYResolution+0.5);
}
else
{
- nRX=(sal_uLong)(fXResolution*2.54+0.5);
- nRY=(sal_uLong)(fYResolution*2.54+0.5);
+ nRX=(sal_uInt32)(fXResolution*2.54+0.5);
+ nRY=(sal_uInt32)(fYResolution*2.54+0.5);
}
MapMode aMapMode(MapUnit::MapInch,Point(0,0),Fraction(1,nRX),Fraction(1,nRY));
aBitmap.SetPrefMapMode(aMapMode);
@@ -1191,14 +1181,12 @@ bool TIFFReader::HasAlphaChannel() const
bool TIFFReader::ReadTIFF(SvStream & rTIFF, Graphic & rGraphic )
{
sal_uInt16 i, nNumTags(0), nTagType(0);
- sal_uInt64 nMaxPos;
- sal_uLong nPos;
sal_uInt32 nFirstIfd(0), nDataLen;
bStatus = true;
pTIFF = &rTIFF;
- nMaxPos = nOrigPos = pTIFF->Tell();
+ sal_uInt64 nMaxPos = nOrigPos = pTIFF->Tell();
nEndOfFile = nOrigPos + pTIFF->remainingSize();
// number format of pTIFF at the beginning
SvStreamEndian nOrigNumberFormat = pTIFF->GetEndian();
@@ -1249,7 +1237,7 @@ bool TIFFReader::ReadTIFF(SvStream & rTIFF, Graphic & rGraphic )
pTIFF->ReadUInt16( nTagType ).ReadUInt16( nDataType ).ReadUInt32( nDataLen ).ReadUInt32( nOffset );
if( DataTypeSize() * nDataLen > 4 )
- nMaxPos = std::max( (sal_uInt64) nOrigPos + nOffset + DataTypeSize() * nDataLen, nMaxPos );
+ nMaxPos = std::max(nOrigPos + nOffset + DataTypeSize() * nDataLen, nMaxPos);
}
pTIFF->ReadUInt32( nOffset );
if ( pTIFF->IsEof() )
@@ -1310,7 +1298,7 @@ bool TIFFReader::ReadTIFF(SvStream & rTIFF, Graphic & rGraphic )
pMap[ 0 ] = pMap[ 1 ] = pMap[ 2 ] = pMap[ 3 ] = nullptr;
pTIFF->ReadUInt16( nNumTags );
- nPos = pTIFF->Tell();
+ sal_uInt64 nPos = pTIFF->Tell();
const size_t nMinRecordSize = 8;
const size_t nMaxRecords = pTIFF->remainingSize() / nMinRecordSize;
@@ -1328,7 +1316,7 @@ bool TIFFReader::ReadTIFF(SvStream & rTIFF, Graphic & rGraphic )
if( DataTypeSize() * nDataLen > 4 )
{
pTIFF->ReadUInt32( nOffset );
- pTIFF->Seek( nOrigPos + nOffset );
+ pTIFF->Seek(nOrigPos + nOffset);
}
ReadTagData( nTagType, nDataLen );
nPos += 12; pTIFF->Seek( nPos );
@@ -1465,7 +1453,7 @@ bool TIFFReader::ReadTIFF(SvStream & rTIFF, Graphic & rGraphic )
// seek to end of TIFF if succeeded
pTIFF->SetEndian( nOrigNumberFormat );
- pTIFF->Seek( bStatus ? nMaxPos : nOrigPos );
+ pTIFF->Seek(bStatus ? nMaxPos : nOrigPos);
if ( aAnimation.Count() )
{