39 std::unique_ptr<vcl::bitmap::RawBitmap>
mpBitmap;
40 std::vector<Color> mvPalette;
43 sal_uInt16 nBitsPerPlanePix;
45 sal_uInt16 nBytesPerPlaneLin;
47 sal_uInt32 nWidth, nHeight;
48 sal_uInt16 nResX, nResY;
49 sal_uInt16 nDestBitsPerPixel;
50 std::unique_ptr<sal_uInt8[]>
56 void ImplReadPalette(
unsigned int nCol );
57 void ImplReadHeader();
60 explicit PCXReader(
SvStream &rStream);
61 bool ReadPCX(
Graphic & rGraphic );
69PCXReader::PCXReader(
SvStream &rStream)
75 , nBytesPerPlaneLin(0)
80 , nDestBitsPerPixel(0)
86bool PCXReader::ReadPCX(
Graphic & rGraphic)
88 if ( m_rPCX.GetError() )
91 m_rPCX.SetEndian(SvStreamEndian::LITTLE);
100 if (bStatus && nBytesPerPlaneLin > m_rPCX.remainingSize() / nPlanes)
116 if ( nDestBitsPerPixel <= 8 )
118 sal_uInt16 nColors = 1 << nDestBitsPerPixel;
120 mvPalette.resize( nColors );
121 for ( sal_uInt16 i = 0;
i < nColors;
i++, pPal += 3 )
123 mvPalette[
i] =
Color( pPal[ 0 ], pPal[ 1 ], pPal[ 2 ] );
132 if ( nDestBitsPerPixel == 8 && bStatus )
136 ImplReadPalette(256);
137 mvPalette.resize( 256 );
138 for ( sal_uInt16 i = 0;
i < 256;
i++, pPal += 3 )
140 mvPalette[
i] =
Color( pPal[ 0 ], pPal[ 1 ], pPal[ 2 ] );
153void PCXReader::ImplReadHeader()
156 m_rPCX.ReadUChar( nbyte ).ReadUChar( nVersion ).ReadUChar( nEncoding );
157 if ( nbyte!=0x0a || (nVersion != 0 && nVersion != 2 && nVersion != 3 && nVersion != 5) || nEncoding > 1 )
164 m_rPCX.ReadUChar( nbyte ); nBitsPerPlanePix =
static_cast<sal_uInt16
>(nbyte);
165 sal_uInt16 nMinX(0),nMinY(0),nMaxX(0),nMaxY(0);
166 m_rPCX.ReadUInt16( nMinX ).ReadUInt16( nMinY ).ReadUInt16( nMaxX ).ReadUInt16( nMaxY );
168 if ((nMinX > nMaxX) || (nMinY > nMaxY))
174 nWidth = nMaxX-nMinX+1;
175 nHeight = nMaxY-nMinY+1;
177 m_rPCX.ReadUInt16( nResX );
178 m_rPCX.ReadUInt16( nResY );
179 if ( nResX >= nWidth || nResY >= nHeight || ( nResX != nResY ) )
182 ImplReadPalette( 16 );
186 m_rPCX.ReadUChar( nbyte ); nPlanes =
static_cast<sal_uInt16
>(nbyte);
187 sal_uInt16 nushort(0);
188 m_rPCX.ReadUInt16( nushort ); nBytesPerPlaneLin = nushort;
189 sal_uInt16 nPaletteInfo;
190 m_rPCX.ReadUInt16( nPaletteInfo );
192 m_rPCX.SeekRel( 58 );
194 nDestBitsPerPixel = nBitsPerPlanePix * nPlanes;
195 if (nDestBitsPerPixel == 2 || nDestBitsPerPixel == 3) nDestBitsPerPixel = 4;
197 if ( ( nDestBitsPerPixel != 1 && nDestBitsPerPixel != 4 && nDestBitsPerPixel != 8 && nDestBitsPerPixel != 24 )
198 || nPlanes > 4 || nBytesPerPlaneLin < ( ( nWidth * nBitsPerPlanePix+7 ) >> 3 ) )
206 if ( nPlanes == 1 && nBitsPerPlanePix == 1 )
208 pPalette[ 0 ] = pPalette[ 1 ] = pPalette[ 2 ] = 0x00;
209 pPalette[ 3 ] = pPalette[ 4 ] = pPalette[ 5 ] = 0xff;
213void PCXReader::ImplReadBody()
215 std::unique_ptr<sal_uInt8[]> pPlane[ 4 ];
217 sal_uInt32
i,
ny, nLastPercent = 0, nPercent;
221 for (sal_uInt16 np = 0; np < nPlanes; ++np)
222 pPlane[np].reset(
new sal_uInt8[nBytesPerPlaneLin]());
225 for ( ny = 0;
ny < nHeight;
ny++ )
232 nPercent =
ny * 60 / nHeight + 10;
233 if ( ny == 0 || nLastPercent + 4 <= nPercent )
235 nLastPercent = nPercent;
237 for (sal_uInt16 np = 0; np < nPlanes; ++np)
240 m_rPCX.ReadBytes(
static_cast<void *
>(pPlane[ np ].
get()), nBytesPerPlaneLin );
243 pDest = pPlane[ np ].get();
244 nx = nBytesPerPlaneLin;
245 while ( nCount > 0 && nx > 0)
251 while (nx > 0 && m_rPCX.good())
253 m_rPCX.ReadUChar( nDat );
254 if ( ( nDat & 0xc0 ) == 0xc0 )
256 nCount =
static_cast<sal_uInt64
>(nDat) & 0x003f;
257 m_rPCX.ReadUChar( nDat );
291 switch ( nBitsPerPlanePix + ( nPlanes << 8 ) )
295 for ( i = 0;
i < nWidth;
i++ )
297 sal_uInt32 nShift = (
i & 7 ) ^ 7;
299 mpBitmap->SetPixel( ny, i, mvPalette[*(pSource1++) & 1] );
301 mpBitmap->SetPixel( ny, i, mvPalette[(*pSource1 >> nShift ) & 1] );
306 for ( i = 0;
i < nWidth;
i++ )
311 nCol = *pSource1 >> 6;
314 nCol = ( *pSource1 >> 4 ) & 0x03 ;
317 nCol = ( *pSource1 >> 2 ) & 0x03;
320 nCol = ( *pSource1++ ) & 0x03;
323 mpBitmap->SetPixel( ny, i, mvPalette[nCol] );
328 for ( i = 0;
i < nWidth;
i++ )
330 mpBitmap->SetPixel( ny, i, mvPalette[*pSource1++] );
335 for ( i = 0;
i < nWidth;
i++ )
337 sal_uInt32 nShift = (
i & 7 ) ^ 7;
340 nCol = ( *pSource1++ & 1) + ( ( *pSource2++ << 1 ) & 2 ) + ( ( *pSource3++ << 2 ) & 4 );
341 mpBitmap->SetPixel( ny, i, mvPalette[nCol] );
345 nCol = sal::static_int_cast< sal_uInt8 >(
346 ( ( *pSource1 >> nShift ) & 1) + ( ( ( *pSource2 >> nShift ) << 1 ) & 2 ) +
347 ( ( ( *pSource3 >> nShift ) << 2 ) & 4 ));
348 mpBitmap->SetPixel( ny, i, mvPalette[nCol] );
354 for ( i = 0;
i < nWidth;
i++ )
356 sal_uInt32 nShift = (
i & 7 ) ^ 7;
359 nCol = ( *pSource1++ & 1) + ( ( *pSource2++ << 1 ) & 2 ) + ( ( *pSource3++ << 2 ) & 4 ) +
360 ( ( *pSource4++ << 3 ) & 8 );
361 mpBitmap->SetPixel( ny, i, mvPalette[nCol] );
365 nCol = sal::static_int_cast< sal_uInt8 >(
366 ( ( *pSource1 >> nShift ) & 1) + ( ( ( *pSource2 >> nShift ) << 1 ) & 2 ) +
367 ( ( ( *pSource3 >> nShift ) << 2 ) & 4 ) + ( ( ( *pSource4 >> nShift ) << 3 ) & 8 ));
368 mpBitmap->SetPixel( ny, i, mvPalette[nCol] );
374 for ( i = 0;
i < nWidth;
i++ )
376 mpBitmap->SetPixel( ny, i,
Color( *pSource1++, *pSource2++, *pSource3++ ) );
387void PCXReader::ImplReadPalette(
unsigned int nCol )
391 for (
unsigned int i = 0;
i < nCol;
i++ )
393 m_rPCX.ReadUChar( r ).ReadUChar( g ).ReadUChar( b );
404 PCXReader aPCXReader(rStream);
405 bool bRetValue = aPCXReader.ReadPCX(rGraphic);
void SetError(ErrCode nErrorCode)
Intended to be used to feed into CreateFromData to create a BitmapEx.
#define SVSTREAM_FILEFORMAT_ERROR
bool ImportPcxGraphic(SvStream &rStream, Graphic &rGraphic)
std::enable_if< std::is_signed< T >::value, bool >::type checked_multiply(T a, T b, T &result)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
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.