49 std::unique_ptr<vcl::bitmap::RawBitmap>
mpBitmap;
65 sal_uInt32 nBMPHeight;
67 void CheckPCDImagePacFile();
70 void ReadOrientation();
77 explicit PCDReader(
SvStream &rStream)
81 , eResolution(PCDRES_BASE16)
102 CheckPCDImagePacFile();
108 eResolution = PCDRES_BASE;
111 sal_Int32 nResolution = pConfigItem->
ReadInt32(
"Resolution", 2 );
112 if ( nResolution == 1 )
113 eResolution = PCDRES_BASE4;
114 else if ( nResolution == 0 )
115 eResolution = PCDRES_BASE16;
143 if ( ( nOrientation & 0x01 ) == 0 )
146 nBMPHeight = nHeight;
163 void PCDReader::CheckPCDImagePacFile()
168 m_rPCD.ReadBytes(Buf, 7);
170 if (OString(Buf) !=
"PCD_IPI")
175 void PCDReader::ReadOrientation()
179 m_rPCD.Seek( 194635 );
180 m_rPCD.ReadUChar( nOrientation );
181 nOrientation &= 0x03;
185 void PCDReader::ReadImage()
187 sal_uInt32
nx,
ny,nW2,nH2,nYPair,ndy,nXPair;
194 sal_uInt8 * pL0N, * pL1N, * pCbN, * pCrN;
202 pL0 =
static_cast<sal_uInt8*
>(std::malloc( nWidth ));
203 pL1 =
static_cast<sal_uInt8*
>(std::malloc( nWidth ));
204 pCb =
static_cast<sal_uInt8*
>(std::malloc( nW2+1 ));
205 pCr =
static_cast<sal_uInt8*
>(std::malloc( nW2+1 ));
206 pL0N=
static_cast<sal_uInt8*
>(std::malloc( nWidth ));
207 pL1N=
static_cast<sal_uInt8*
>(std::malloc( nWidth ));
208 pCbN=
static_cast<sal_uInt8*
>(std::malloc( nW2+1 ));
209 pCrN=
static_cast<sal_uInt8*
>(std::malloc( nW2+1 ));
211 if ( pL0 ==
nullptr || pL1 ==
nullptr || pCb ==
nullptr || pCr ==
nullptr ||
212 pL0N ==
nullptr || pL1N ==
nullptr || pCbN ==
nullptr || pCrN ==
nullptr)
214 std::free(static_cast<void*>(pL0) );
215 std::free(static_cast<void*>(pL1) );
216 std::free(static_cast<void*>(pCb) );
217 std::free(static_cast<void*>(pCr) );
218 std::free(static_cast<void*>(pL0N));
219 std::free(static_cast<void*>(pL1N));
220 std::free(static_cast<void*>(pCbN));
221 std::free(static_cast<void*>(pCrN));
226 m_rPCD.Seek( nImagePos );
229 m_rPCD.ReadBytes( pL0N, nWidth );
230 m_rPCD.ReadBytes( pL1N, nWidth );
231 m_rPCD.ReadBytes( pCbN, nW2 );
232 m_rPCD.ReadBytes( pCrN, nW2 );
233 pCbN[ nW2 ] = pCbN[ nW2 - 1 ];
234 pCrN[ nW2 ] = pCrN[ nW2 - 1 ];
236 for ( nYPair = 0; nYPair < nH2; nYPair++ )
239 pt=pL0; pL0=pL0N; pL0N=pt;
240 pt=pL1; pL1=pL1N; pL1N=pt;
241 pt=pCb; pCb=pCbN; pCbN=pt;
242 pt=pCr; pCr=pCrN; pCrN=pt;
245 if ( nYPair < nH2 - 1 )
247 m_rPCD.ReadBytes( pL0N, nWidth );
248 m_rPCD.ReadBytes( pL1N, nWidth );
249 m_rPCD.ReadBytes( pCbN, nW2 );
250 m_rPCD.ReadBytes( pCrN, nW2 );
251 pCbN[nW2]=pCbN[ nW2 - 1 ];
252 pCrN[nW2]=pCrN[ nW2 - 1 ];
256 for ( nXPair = 0; nXPair < nW2; nXPair++ )
258 pCbN[ nXPair ] = pCb[ nXPair ];
259 pCrN[ nXPair ] = pCr[ nXPair ];
264 for ( ndy = 0; ndy < 2; ndy++ )
266 ny = ( nYPair << 1 ) + ndy;
269 for ( nx = 0; nx < nWidth; nx++ )
276 if (( nx & 1 ) == 0 )
283 nCb = (
static_cast<tools::Long>(pCb[ nXPair ]) + static_cast<tools::Long>(pCb[ nXPair + 1 ]) ) >> 1;
284 nCr = (
static_cast<tools::Long>(pCr[ nXPair ]) + static_cast<tools::Long>(pCr[ nXPair + 1 ]) ) >> 1;
289 if ( ( nx & 1 ) == 0 )
291 nCb = (
static_cast<tools::Long>(pCb[ nXPair ]) + static_cast<tools::Long>(pCbN[ nXPair ]) ) >> 1;
292 nCr = (
static_cast<tools::Long>(pCr[ nXPair ]) + static_cast<tools::Long>(pCrN[ nXPair ]) ) >> 1;
296 nCb = (
static_cast<tools::Long>(pCb[ nXPair ]) + static_cast<tools::Long>(pCb[ nXPair + 1 ]) +
297 static_cast<tools::Long>(pCbN[ nXPair ]) + static_cast<tools::Long>(pCbN[ nXPair + 1 ]) ) >> 2;
298 nCr = (
static_cast<tools::Long>(pCr[ nXPair ]) + static_cast<tools::Long>(pCr[ nXPair + 1]) +
299 static_cast<tools::Long>(pCrN[ nXPair ]) + static_cast<tools::Long>(pCrN[ nXPair + 1 ]) ) >> 2;
306 nRed = ( nL + nCr * 119374 + 0x8000 ) >> 16;
311 nGreen = ( nL - nCb * 28198 - nCr * 60761 + 0x8000 ) >> 16;
316 nBlue = ( nL + nCb * 145352 + 0x8000 ) >> 16;
323 if ( nOrientation < 2 )
325 if ( nOrientation == 0 )
326 mpBitmap->SetPixel( ny, nx,
Color( static_cast<sal_uInt8>(nRed), static_cast<sal_uInt8>(nGreen), static_cast<sal_uInt8>(nBlue) ) );
328 mpBitmap->SetPixel( nWidth - 1 - nx, ny,
Color( static_cast<sal_uInt8>(nRed), static_cast<sal_uInt8>(nGreen), static_cast<sal_uInt8>(nBlue) ) );
332 if ( nOrientation == 2 )
333 mpBitmap->SetPixel( nHeight - 1 - ny, ( nWidth - 1 - nx ),
Color( static_cast<sal_uInt8>(nRed), static_cast<sal_uInt8>(nGreen), static_cast<sal_uInt8>(nBlue) ) );
335 mpBitmap->SetPixel( nx, ( nHeight - 1 - ny ),
Color( static_cast<sal_uInt8>(nRed), static_cast<sal_uInt8>(nGreen), static_cast<sal_uInt8>(nBlue) ) );
340 if ( m_rPCD.GetError() )
345 std::free(static_cast<void*>(pL0) );
346 std::free(static_cast<void*>(pL1) );
347 std::free(static_cast<void*>(pCb) );
348 std::free(static_cast<void*>(pCr) );
349 std::free(static_cast<void*>(pL0N));
350 std::free(static_cast<void*>(pL1N));
351 std::free(static_cast<void*>(pCbN));
352 std::free(static_cast<void*>(pCrN));
359 PCDReader aPCDReader(rStream);
360 return aPCDReader.ReadPCD(rGraphic, pConfigItem);
bool ImportPcdGraphic(SvStream &rStream, Graphic &rGraphic, FilterConfigItem *pConfigItem)
BitmapEx CreateFromData(sal_uInt8 const *pData, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int32 nStride, vcl::PixelFormat ePixelFormat)
Copy block of image data into the bitmap.
sal_Int32 ReadInt32(const OUString &rKey, sal_Int32 nDefault)
Intended to be used to feed into CreateFromData to create a BitmapEx.