示例#1
0
    void generateMultiplicationMap (const PLBmp & lightMap, PLBmp & destMap) {
        assert(lightMap.GetWidth() == destMap.GetWidth() );
        assert(lightMap.GetHeight() == destMap.GetHeight() );
        assert(lightMap.GetBitsPerPixel() == 8);
        assert(destMap.GetBitsPerPixel() == 8);

        PLBYTE ** myLightMapLines   = lightMap.GetLineArray();
        PLBYTE ** myDestMapLines = destMap.GetLineArray();

        PLBYTE myScale;
        for (int y=0;y<lightMap.GetHeight(); y++) {
            for (int x=0;x<lightMap.GetWidth(); x++) {
                PLBYTE& col = myDestMapLines[y][x];
                myScale =  PLBYTE(myLightMapLines[y][x]);
                int tempInt = (col*myScale)/255;
                col = static_cast<PLBYTE>(min(tempInt, 255));
            }
        }
    }
示例#2
0
 void
 applyCustomFilter(PLBmp & theBitmap, const std::string & theFilterName, const VectorOfFloat & theFilterparams) {
     asl::Ptr<PLFilter> myPaintLibFilter = y60::PaintLibFilterFactory::get().createFilter(theFilterName,
                                                                                          theFilterparams);
     if (myPaintLibFilter) {
         theBitmap.ApplyFilter(*myPaintLibFilter);
     } else {
         ImageFilter myFilter = ImageFilter(getEnumFromString(theFilterName, ImageFilterStrings));
         applyCustomFilter(theBitmap, myFilter, theFilterparams);
     }
 }
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));
}
示例#4
0
 void
 applyCustomFilter(PLBmp & theBitmap, ImageFilter theFilter, const std::vector<float> &  theFilterparams) {
     switch (theFilter) {
        /* case WINDOW_CW: {
             float myCenter = theFilterparams[0];
             float myWidth = theFilterparams[1];
             ApplyFilter(PLFilterWindowCW(myCenter, myWidth));
             break; }*/
         case HEIGHT_TO_NORMALMAP:
             theBitmap.ApplyFilter(HeightToNormalMap());
             break;
         default:
             break;
     }
 }
示例#5
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;
}
示例#6
0
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;
}
示例#7
0
    void applyMultiplicationMap (PLBmp & textureBmp, const PLBmp & attnBmp,
            const PLRect & srcRect, double myLightingFactor)
    {
        assert(attnBmp.GetBitsPerPixel() == 8);
        assert(textureBmp.GetBitsPerPixel() == 32);
        assert (srcRect.Width() > 0 && srcRect.Height() > 0);

        double Scale = double(srcRect.Width())/textureBmp.GetWidth();
        double YScale = double(srcRect.Height())/textureBmp.GetHeight();
        assert (Scale == YScale); (void)YScale;

        PLBYTE ** myAttnBmpLines   = attnBmp.GetLineArray();
        PLPixel32 ** myTextureBmpLines = (PLPixel32**)textureBmp.GetLineArray();

        if (Scale > 0.99) {
            for (int y=0;y<textureBmp.GetHeight(); y++) {
                for (int x=0;x<textureBmp.GetWidth(); x++) {
                    PLPixel32& col = myTextureBmpLines[y][x];

                    PLBYTE myScale;
                    myScale =  PLBYTE(myAttnBmpLines[int(Scale*y+srcRect.tl.y)]
                                        [int(Scale*x+srcRect.tl.x)]);
                    int tempIntR = int((myLightingFactor * col.GetR() * myScale)/256);
                    int tempIntG = int((myLightingFactor * col.GetG() * myScale)/256);
                    int tempIntB = int((myLightingFactor * col.GetB() * myScale)/256);
                    col.Set( static_cast<PLBYTE>(min(tempIntR,255)),
                             static_cast<PLBYTE>(min(tempIntG,255)),
                             static_cast<PLBYTE>(min(tempIntB,255)), 255 );
                }
            }
        } else {
            int MaxY = attnBmp.GetHeight()-1;
            int MaxX = attnBmp.GetWidth()-1;
            for (int y=0;y<textureBmp.GetHeight(); y++) {
                double ySrcPos = Scale*y+srcRect.tl.y;
                int yLightPos = int (ySrcPos);
                double yLightFade = fmod (ySrcPos, 1);
                if (yLightPos >= MaxY) {
                    yLightPos = MaxY - 1;
                    yLightFade = 1;
                }
                for (int x=0;x<textureBmp.GetWidth(); x++) {
                    PLPixel32& col = myTextureBmpLines[y][x];
                    double xSrcPos = Scale*x+srcRect.tl.x;
                    int xLightPos = int (xSrcPos);
                    double xLightFade = fmod (xSrcPos, 1);
                    if (xLightPos >= MaxX) {
                        xLightPos = MaxX - 1;
                        xLightFade = 1;
                    }

                    double myScale = double(myAttnBmpLines[yLightPos][xLightPos])*
                                      (1-xLightFade)*(1-yLightFade) +
                                  double(myAttnBmpLines[yLightPos][xLightPos+1])*
                                      xLightFade*(1-yLightFade) +
                                  double(myAttnBmpLines[yLightPos+1][xLightPos])*
                                      (1-xLightFade)*yLightFade +
                                  double(myAttnBmpLines[yLightPos+1][xLightPos+1])*
                                      xLightFade*yLightFade;

                    int tempIntR = int((myLightingFactor * col.GetR() * myScale) /256);
                    int tempIntG = int((myLightingFactor * col.GetG() * myScale) /256);
                    int tempIntB = int((myLightingFactor * col.GetB() * myScale) /256);
                    col.Set( static_cast<PLBYTE>(min(tempIntR,255)),
                             static_cast<PLBYTE>(min(tempIntG,255)),
                             static_cast<PLBYTE>(min(tempIntB,255)),
                             255);
                }
            }
        }
    }