Esempio n. 1
0
void PLFilterSubtract::Apply(PLBmpBase * pBmpSource, PLBmp * pBmpDest) const
{
  // Calculate the size of the new bitmap
  pBmpDest->Create (pBmpSource->GetWidth(), pBmpSource->GetHeight(), pBmpSource->GetPixelFormat(),
                    NULL, 0, pBmpSource->GetResolution());
  for (int y = 0; y < pBmpSource->GetHeight(); ++y)
  {
    for (int x = 0; x < pBmpSource->GetWidth(); ++x)
    {
      PLPixel32 srcPixel = pBmpSource->GetPixel32(x,y);
      PLPixel32 differencePixel;

      if (x < m_pBmpSubtrahend->GetWidth() &&
          y < m_pBmpSubtrahend->GetHeight())
      {
        PLPixel32 substrahendPixel = m_pBmpSubtrahend->GetPixel32(x,y);
        differencePixel.SetR( static_cast<PLBYTE>(abs(srcPixel.GetR() - substrahendPixel.GetR())) );
        differencePixel.SetG( static_cast<PLBYTE>(abs(srcPixel.GetG() - substrahendPixel.GetG())) );
        differencePixel.SetB( static_cast<PLBYTE>(abs(srcPixel.GetB() - substrahendPixel.GetB())) );
        differencePixel.SetA( static_cast<PLBYTE>(abs(srcPixel.GetA() - substrahendPixel.GetA())) );
      } else {
        differencePixel = srcPixel;
      }
      pBmpDest->SetPixel(x,y,differencePixel);
    }
  }
}
Esempio n. 2
0
void
HeightToNormalMap::Apply(PLBmpBase * theSource, PLBmp * theDestination) const {
  theDestination->Create(theSource->GetWidth(), theSource->GetHeight(), PLPixelFormat::A8R8G8B8);
    //theDestination->SetHasAlpha(true);
    PLPixel8 ** mySourceLines = (PLPixel8**)theSource->GetLineArray();
    PLPixel32 ** myDestinationLines = (PLPixel32**)theDestination->GetLineArray();

    for (int y = 0; y < theSource->GetHeight(); ++y) {
        PLPixel8  * mySourceLine = mySourceLines[y];
        PLPixel32 * myDestinationLine = myDestinationLines[y];

        PLPixel8 * myNextLine;
        if (y + 1 == theSource->GetHeight()) {
            myNextLine = mySourceLines[y];
        } else {
            myNextLine = mySourceLines[y + 1];
        }
        for (int x = 0; x < theSource->GetWidth(); ++x) {
            float myHeight = mySourceLine->Get();
            float aboveNeighbourHeight = myNextLine->Get();
            float rightNeighbourHeight;
            if (x + 1 == theSource->GetWidth()) {
                rightNeighbourHeight = mySourceLine->Get();
            } else {
                rightNeighbourHeight = (mySourceLine + 1)->Get();
            }
            myHeight /= 255;
            aboveNeighbourHeight /= 255;
            rightNeighbourHeight /= 255;
            float myZ = 1.0f / float((sqrt(pow(myHeight - aboveNeighbourHeight, 2) +
                                    pow(myHeight - rightNeighbourHeight, 2) + 1)));
            float myX = (myHeight - rightNeighbourHeight) * myZ;
            float myY = (myHeight - aboveNeighbourHeight) * myZ;

            myDestinationLine->SetR((PLBYTE)minimum(128.0 * myX + 128, 255.0));
            myDestinationLine->SetG((PLBYTE)minimum(128.0 * -myY + 128, 255.0));
            myDestinationLine->SetB((PLBYTE)minimum(128.0 * myZ + 128, 255.0));
            myDestinationLine->SetA(255);

            mySourceLine++;
            myDestinationLine++;
            myNextLine++;
        }
    }
}
Esempio n. 3
0
void multAndStore(PLPixel32 & theResult, PLPixel32 * theSource, int theScale ) {
    theResult.SetR( static_cast<PLBYTE>(minimum(theResult.GetR() + (((theSource->GetR() * theScale)+128) / 256), 255)) );
    theResult.SetG( static_cast<PLBYTE>(minimum(theResult.GetG() + (((theSource->GetG() * theScale)+128) / 256), 255)) );
    theResult.SetB( static_cast<PLBYTE>(minimum(theResult.GetB() + (((theSource->GetB() * theScale)+128) / 256), 255)) );
    theResult.SetA( static_cast<PLBYTE>(minimum(theResult.GetA() + (((theSource->GetA() * theScale)+128) / 256), 255)) );
}