Ejemplo 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);
    }
  }
}
Ejemplo n.º 2
0
void CPalViewDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
  int x,y;
  CRect Rect;
  CBrush Brush;
  for (x = 0; x < 16; x++)
    for (y = 0; y < 16; y++)
    {
      Rect = CRect (x*12, y*13, x*12+11, y*13+12);
      Rect.OffsetRect (14, 14);
      PLPixel32 Col = m_pPal[x*8+y];
      Brush.CreateSolidBrush (RGB (Col.GetR(), Col.GetG(), Col.GetB ()));
      dc.FillRect (Rect, &Brush);
      Brush.DeleteObject();
    }
}
Ejemplo 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)) );
}
Ejemplo n.º 4
0
void PLTIFFEncoder::DoTiffEncode (PLBmpBase* pBmp, TIFF* tif)
{
  uint32 l, c, image_length, image_width;
  // iterate over data
  PLBYTE **pla = pBmp->GetLineArray();
  PLASSERT( pla );

  image_length = (uint32) pBmp->GetHeight();
  image_width  = (uint32) pBmp->GetWidth();
  switch (pBmp->GetBitsPerPixel())
  {
    case 8:
      {
        // first, save the colormap
        uint16 red[256];
        uint16 green[256];
        uint16 blue[256];

        PLPixel32 * pPal = pBmp->GetPalette();
        PLASSERT( pPal );
        for (int i = 0; i < pBmp->GetNumColors(); i++, pPal++)
        {
          red[i]   = pPal->GetR ();
          green[i] = pPal->GetG ();
          blue[i]  = pPal->GetB ();
        }
        SetField( tif, TIFFTAG_COLORMAP, red, green, blue );
      }
      // fall-through

    case 1:  // TODO: a bit of error checking
      for (l = 0; l < image_length; l++)
        if(TIFFWriteScanline( tif, pla[l], l, 0 ) < 1) {
            throw PLTextException(PL_ERRINTERNAL, "TIFFWriteScanline failed");
        }
      break;

    case 24:
      {
        // TODO: check whether (r,g,b) components come in the correct order here...
        PLBYTE* pBuf = new PLBYTE[3*image_width];
        for (l = 0; l < image_length; l++)
        {
          for (c = 0; c < image_width; c++)
          {
            pBuf[c*3 + 0] = pla[l][c*sizeof(PLPixel24) + PL_RGBA_RED];
            pBuf[c*3 + 1] = pla[l][c*sizeof(PLPixel24) + PL_RGBA_GREEN];
            pBuf[c*3 + 2] = pla[l][c*sizeof(PLPixel24) + PL_RGBA_BLUE];
          }
          if(TIFFWriteScanline( tif, pBuf, l, 0 ) < 1) {
              throw PLTextException(PL_ERRINTERNAL, "TIFFWriteScanline failed");
          }
        }
        delete [] pBuf;
      }
      break;
    case 32:
      {
        // TODO: check whether (r,g,b) components come in the correct order here...
        if (pBmp->HasAlpha())
        {
          uint32 *plBuf = new uint32[image_width];
          for (l = 0; l < image_length; l++)
          {
            for (c = 0; c < image_width; c++)
            {
                // For 32 bit, TIFFLIB wants abgr long word packed...
                plBuf[c] = 
                    ((uint32)(pla[l][c*sizeof(PLPixel32) + PL_RGBA_ALPHA]) << 24) |
                    ((uint32)(pla[l][c*sizeof(PLPixel32) + PL_RGBA_BLUE])  << 16) |
                    ((uint32)(pla[l][c*sizeof(PLPixel32) + PL_RGBA_GREEN]) << 8 ) |
                    ((uint32)(pla[l][c*sizeof(PLPixel32) + PL_RGBA_RED]));
            }
            if(TIFFWriteScanline( tif, plBuf, l, 0 ) < 1) {
                throw PLTextException(PL_ERRINTERNAL, "TIFFWriteScanline failed");
            }
          }
          delete [] plBuf;
        }
        else
        {
          PLBYTE* pBuf = new PLBYTE[3*image_width];
          for (l = 0; l < image_length; l++)
          {
            for (c = 0; c < image_width; c++)
            {
              pBuf[c*3 + 0] = pla[l][c*sizeof(PLPixel32) + PL_RGBA_RED];
              pBuf[c*3 + 1] = pla[l][c*sizeof(PLPixel32) + PL_RGBA_GREEN];
              pBuf[c*3 + 2] = pla[l][c*sizeof(PLPixel32) + PL_RGBA_BLUE];
            }
            if(TIFFWriteScanline( tif, pBuf, l, 0 ) < 1) {
                throw PLTextException(PL_ERRINTERNAL, "TIFFWriteScanline failed");
            }
          }
          delete [] pBuf;
        }
      }
      break;

    default:
      PLASSERT(false);
      throw PLTextException(PL_ERRFORMAT_NOT_SUPPORTED, "unsupported bitsPerPixel");
  }
  // we could flush at this point, but TIFFClose will do it anyway
}