void PLTestFilterResizeBilinear::createBmp(PLBmp& Bmp) { Bmp.Create (8, 8, PLPixelFormat::X8R8G8B8); int x,y; for (y=0; y<4; y++) for (x=0; x<4; x++) Bmp.SetPixel (x,y, PLPixel32 (255,0,0,0)); for (y=0; y<4; y++) for (x=4; x<8; x++) Bmp.SetPixel (x,y, PLPixel32 (0,255,0,0)); for (y=4; y<8; y++) for (x=0; x<4; x++) Bmp.SetPixel (x,y, PLPixel32 (0,0,255,0)); for (y=4; y<8; y++) for (x=4; x<8; x++) Bmp.SetPixel (x,y, PLPixel32 (255,255,255,0)); }
void PLPSDDecoder::readLayer(PLDataSource *pDataSrc, PLBmp &Bmp, int Mode) { m_LayersRead++; PLASSERT (m_LayersRead <= m_NumLayers); int CurLayer = m_LayersRead-1; PLPSDLayerInfo * pLayerInfo = m_pLayerInfo[CurLayer]; char sz[256]; sprintf (sz, "Reading Layer %i\n", CurLayer); Trace (2, sz); int Width = pLayerInfo->Right-pLayerInfo->Left; int Height = pLayerInfo->Bottom-pLayerInfo->Top; PLBmpInfo *pBmpInfo = createBmpInfo (Mode, Height, Width, pLayerInfo->NumChannels, m_Resolution); Bmp.Create (*pBmpInfo); delete pBmpInfo; int * pRowLengths = new int [Height]; for (int l=0; l<pLayerInfo->NumChannels; l++) { char sz[256]; sprintf (sz, "Reading Channel %i\n", l); Trace (2, sz); PLWORD CompressionMethod = ReadMWord (pDataSrc); traceCompressionMethod (CompressionMethod); if (CompressionMethod == 1) { for (int y=0; y<Height; y++) pRowLengths[y] = ReadMWord (pDataSrc); readRLEChannel (pDataSrc, &Bmp, Mode, Height, Width, l, pRowLengths); } else raiseError (PL_ERRFORMAT_UNKNOWN, "PSD decoder: Compression type not supported."); } delete[] pRowLengths; }
void gaussianblur(PLBmpBase * theSource, PLBmp * theDestination, const KernelVec & theKernel, double theRadius, unsigned theRealWidth, unsigned theRealHeight, double theSigma) { int myIntRadius = int(ceil(double(theRadius))); unsigned mySrcHeight = theSource->GetHeight(); unsigned mySrcWidth = theSource->GetWidth(); unsigned myDestWidth = mySrcWidth; unsigned myDestHeight = mySrcHeight; PLBmp * myTempBmp = new PLAnyBmp(); myTempBmp->Create(myDestWidth, mySrcHeight, theSource->GetPixelFormat()); theDestination->Create(myDestWidth, myDestHeight, theSource->GetPixelFormat()); // Convolve in x-direction int myOffset = myIntRadius - 1; { // pass 1: Glur in x direction for (unsigned y=0; y < mySrcHeight; ++y) { for(unsigned x=0; x<myDestWidth; ++x) { PIXELTYPE myColor; clearPixel(myColor); for(int w=0; w<myIntRadius; ++w) { int xs = x + w - myOffset; PIXELTYPE myKernelPixel; if (xs>=0 && static_cast<unsigned>(xs)<theRealWidth) { getPix<PIXELTYPE>(theSource, xs,y, myKernelPixel); } else { if (xs < 0) { getPix<PIXELTYPE>(theSource, 0,y, myKernelPixel); } else { getPix<PIXELTYPE>(theSource, theRealWidth-1,y, myKernelPixel); } } multAndStore(myColor, &myKernelPixel, theKernel[w]); xs = x + w; if (xs>=0 && static_cast<unsigned>(xs)<theRealWidth) { getPix<PIXELTYPE>(theSource, xs,y, myKernelPixel); } else { if (xs < 0) { getPix<PIXELTYPE>(theSource, 0,y, myKernelPixel); } else { getPix<PIXELTYPE>(theSource, theRealWidth-1,y, myKernelPixel); } } multAndStore(myColor, &myKernelPixel, theKernel[w+myIntRadius]); } myTempBmp->SetPixel(x,y,myColor); } } } for(unsigned x=0; x<myDestWidth; ++x) { for (unsigned y=0; y < myDestHeight; ++y) { PIXELTYPE myColor; clearPixel(myColor); for(int w=0; w<myIntRadius; ++w) { int ys = y + w - myOffset; PIXELTYPE myKernelPixel; if (ys>=0 && static_cast<unsigned>(ys)<theRealHeight) { getPix<PIXELTYPE>(myTempBmp, x,ys, myKernelPixel); } else { if (ys < 0) { getPix<PIXELTYPE>(myTempBmp, x,0, myKernelPixel); } else { getPix<PIXELTYPE>(myTempBmp, x,theRealHeight-1, myKernelPixel); } } multAndStore(myColor, &myKernelPixel, theKernel[w]); ys = y + w; if (ys>=0 && static_cast<unsigned>(ys)<theRealHeight) { getPix<PIXELTYPE>(myTempBmp, x,ys, myKernelPixel); } else { if (ys < 0) { getPix<PIXELTYPE>(myTempBmp, x,0, myKernelPixel); } else { getPix<PIXELTYPE>(myTempBmp, x,theRealHeight-1, myKernelPixel); } } multAndStore(myColor, &myKernelPixel, theKernel[w+myIntRadius]); } theDestination->SetPixel(x,y,myColor); } } delete myTempBmp; }