PLPixel32 PLPPMDecoder::readASCIIPixel32( int MaxSampleValue, PLDataSource *pDataSrc) { skipPpmASCIISeparators(pDataSrc); PLBYTE r = readASCIIDecimal(pDataSrc); skipPpmASCIISeparators(pDataSrc); PLBYTE g = readASCIIDecimal(pDataSrc); skipPpmASCIISeparators(pDataSrc); PLBYTE b = readASCIIDecimal(pDataSrc); if(MaxSampleValue != 255) { r = (r * 255) / MaxSampleValue; g = (g * 255) / MaxSampleValue; b = (b * 255) / MaxSampleValue; } PLPixel32 Dest; Dest.Set(r, g, b, 0); return Dest; }
void clearPixel(PLPixel32& theResult ) { theResult.Set(0,0,0,0); }
void PLTIFFDecoder::doHiColor (TIFF * tif, PLBmpBase * pBmp, uint16 SamplePerPixel) { int ok; PLULONG x, y; TIFFRGBAImage img; char emsg[1024]; PLBYTE * pBits; ok = TIFFRGBAImageBegin(&img, tif, 0, emsg); if (ok == 0) { raiseError (PL_ERRWRONG_SIGNATURE, "TIFF subformat not supported."); } //bool bHasAlpha = pBmp->HasAlpha(); PLASSERT (int(img.width) == pBmp->GetWidth()); PLASSERT (int(img.height) == pBmp->GetHeight()); PLASSERT (pBmp->GetBitsPerPixel() == 32); pBits = new PLBYTE [img.width*img.height*4]; if (pBits == NULL) raiseError (PL_ERRNO_MEMORY, "Out of memory allocating TIFF buffer."); // Hack for photoshop alpha channel support if (SamplePerPixel == 4 && img.bitspersample == 8 && img.photometric == 2) { img.put.contig = putRGBAAcontig8bittile; } ok = TIFFRGBAImageGet(&img, (uint32 *) pBits, img.width, img.height); if (!ok) { TIFFRGBAImageEnd(&img); raiseError (PL_ERRWRONG_SIGNATURE, m_szLastErr); } PLPixel32 ** pLineArray = pBmp->GetLineArray32(); // Correct the byte ordering. This could be replaced by appropriate // putRGBAcontig... routines. for (y=0; y<img.height; y++) { PLBYTE * pSrc = pBits+(img.height-y-1)*img.width*4; PLPixel32 * pPixel = pLineArray[y]; for (x=0; x<img.width; x++) { #ifdef WORDS_BIGENDIAN pPixel->Set (*(pSrc+3), *(pSrc+2), *(pSrc+1), *(pSrc)); #else pPixel->Set (*pSrc, *(pSrc+1), *(pSrc+2), *(pSrc+3)); #endif pPixel++; pSrc += 4; } } // Clean up. delete [] pBits; TIFFRGBAImageEnd(&img); }