29#define RAS_TYPE_OLD 0x00000000
30#define RAS_TYPE_STANDARD 0x00000001
31#define RAS_TYPE_BYTE_ENCODED 0x00000002
32#define RAS_TYPE_RGB_FORMAT 0x00000003
34#define RAS_COLOR_NO_MAP 0x00000000
35#define RAS_COLOR_RGB_MAP 0x00000001
36#define RAS_COLOR_RAW_MAP 0x00000002
38#define SUNRASTER_MAGICNUMBER 0x59a66a95
52 sal_uInt16 mnDstBitsPerPix;
53 sal_uInt16 mnDstColors;
55 sal_Int32 mnColorMapType, mnColorMapSize;
59 bool ImplReadHeader();
64 bool ReadRAS(
Graphic & rGraphic);
88bool RASReader::ReadRAS(
Graphic & rGraphic)
90 sal_uInt32 nMagicNumber;
92 if ( m_rRAS.GetError() )
95 m_rRAS.SetEndian( SvStreamEndian::BIG );
96 m_rRAS.ReadUInt32( nMagicNumber );
102 mbStatus = ImplReadHeader();
106 std::vector<Color> aPalette;
109 if ( mnDstBitsPerPix <= 8 )
111 bool bPalette(
false);
115 sal_uInt64 nCurPos = m_rRAS.Tell();
116 bOk =
checkSeek(m_rRAS, nCurPos + mnColorMapSize);
120 mnDstColors =
static_cast<sal_uInt16
>( mnColorMapSize / 3 );
122 if ( ( 1 << mnDstBitsPerPix ) < mnDstColors )
125 if ( ( mnDstColors >= 2 ) && ( ( mnColorMapSize % 3 ) == 0 ) )
127 aPalette.resize(mnDstColors);
129 sal_uInt8 nRed[256], nGreen[256], nBlue[256];
130 for ( i = 0;
i < mnDstColors;
i++ ) m_rRAS.ReadUChar( nRed[ i ] );
131 for ( i = 0;
i < mnDstColors;
i++ ) m_rRAS.ReadUChar( nGreen[ i ] );
132 for ( i = 0;
i < mnDstColors;
i++ ) m_rRAS.ReadUChar( nBlue[ i ] );
133 for ( i = 0;
i < mnDstColors;
i++ )
135 aPalette[
i] =
Color(nRed[ i ], nGreen[ i ], nBlue[ i ]);
148 mnDstColors = 1 << mnDstBitsPerPix;
149 aPalette.resize(mnDstColors);
150 for ( sal_uInt16 i = 0;
i < mnDstColors;
i++ )
153 aPalette[
i] =
Color(nCount, nCount, nCount);
161 sal_uInt64 nCurPos = m_rRAS.Tell();
162 bOk =
checkSeek(m_rRAS, nCurPos + mnColorMapSize);
178 if (o3tl::checked_multiply<sal_Int32>(mnWidth, mnHeight, nBitSize) || o3tl::checked_multiply<sal_Int32>(nBitSize, mnDepth, nBitSize))
180 if (m_rRAS.remainingSize() * nMaxCompression <
static_cast<sal_uInt32
>(nBitSize) / 8)
186 mbStatus = ImplReadBody(aBmp, aPalette);
194bool RASReader::ImplReadHeader()
196 m_rRAS.ReadInt32(mnWidth).ReadInt32(mnHeight).ReadInt32(mnDepth).ReadInt32(mnImageDatSize).ReadInt32(mnType).ReadInt32(mnColorMapType).ReadInt32(mnColorMapSize);
198 if (!m_rRAS.good() || mnWidth <= 0 || mnHeight <= 0 || mnImageDatSize <= 0)
206 mnDstBitsPerPix =
static_cast<sal_uInt16
>(
mnDepth);
209 mnDstBitsPerPix = 24;
232 const Color& SanitizePaletteIndex(std::vector<Color>
const & rvPalette,
sal_uInt8 nIndex)
234 if (nIndex >= rvPalette.size())
236 auto nSanitizedIndex =
nIndex % rvPalette.size();
237 SAL_WARN_IF(nIndex != nSanitizedIndex,
"filter.ras",
"invalid colormap index: "
238 <<
static_cast<unsigned int>(nIndex) <<
", colormap len is: "
239 << rvPalette.size());
250 switch ( mnDstBitsPerPix )
257 for (x = 0;
x <
mnWidth && mbStatus; ++
x)
261 nDat = ImplGetByte();
265 rBitmap.
SetPixel(y, x, SanitizePaletteIndex(rvPalette,
266 sal::static_int_cast< sal_uInt8 >(
267 nDat >> ( ( x & 7 ) ^ 7 ))));
269 if (!( ( x - 1 ) & 0x8 ) )
282 for (x = 0;
x <
mnWidth && mbStatus; ++
x)
285 rBitmap.
SetPixel(y, x, SanitizePaletteIndex(rvPalette, nDat));
305 for (x = 0;
x <
mnWidth && mbStatus; ++
x)
309 nRed = ImplGetByte();
310 nGreen = ImplGetByte();
311 nBlue = ImplGetByte();
315 nBlue = ImplGetByte();
316 nGreen = ImplGetByte();
317 nRed = ImplGetByte();
335 for (x = 0;
x <
mnWidth && mbStatus; ++
x)
340 nRed = ImplGetByte();
341 nGreen = ImplGetByte();
342 nBlue = ImplGetByte();
346 nBlue = ImplGetByte();
347 nGreen = ImplGetByte();
348 nRed = ImplGetByte();
371 m_rRAS.ReadUChar( nRetVal );
383 m_rRAS.ReadUChar( nRetVal );
384 if ( nRetVal != 0x80 )
386 m_rRAS.ReadUChar( nRetVal );
389 mnRepCount = nRetVal ;
390 m_rRAS.ReadUChar( mnRepVal );
404 RASReader aRASReader(rStream);
405 bRet = aRASReader.ReadRAS(rGraphic );
Intended to be used to feed into CreateFromData to create a BitmapEx.
void SetPixel(tools::Long nY, tools::Long nX, Color nColor)
#define RAS_TYPE_RGB_FORMAT
#define RAS_COLOR_RGB_MAP
bool ImportRasGraphic(SvStream &rStream, Graphic &rGraphic)
#define RAS_COLOR_RAW_MAP
#define SUNRASTER_MAGICNUMBER
#define RAS_TYPE_BYTE_ENCODED
#define RAS_TYPE_STANDARD
#define SAL_WARN_IF(condition, area, stream)
BitmapEx CreateFromData(sal_uInt8 const *pData, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int32 nStride, sal_Int8 nBitCount, bool bReversColors, bool bReverseAlpha)
Copy block of image data into the bitmap.
TOOLS_DLLPUBLIC bool checkSeek(SvStream &rSt, sal_uInt64 nOffset)