void PLFilterThreshold::Apply(PLBmpBase * pBmpSource, PLBmp * pBmpDest) const
{

  int threshold_min = m_threshold_min;
  int threshold_max = m_threshold_max;
  int channel = m_channel;

  // Only works for 32 bpp bitmaps at the moment.
  PLASSERT (pBmpSource->GetBitsPerPixel() == 32);

  pBmpDest->Create (pBmpSource->GetWidth(), pBmpSource->GetHeight(), 
            PLPixelFormat::L8, NULL, 0, pBmpSource->GetResolution());
  PLBYTE ** pSrcLines = pBmpSource->GetLineArray();
  PLBYTE ** pDstLines = pBmpDest->GetLineArray();

  for (int y = 0; y<pBmpDest->GetHeight(); ++y)
  { // For each line
    PLBYTE * pSrcPixel = pSrcLines[y];
    PLBYTE * pDstPixel = pDstLines[y];

    for (int x = 0; x < pBmpDest->GetWidth(); ++x)
    { // For each pixel
      if ((PLBYTE (pSrcPixel[channel]) <= PLBYTE (threshold_min)) ||
          (PLBYTE (pSrcPixel[channel]) >= PLBYTE(threshold_max)))
        *pDstPixel = 0;
      else
        *pDstPixel = pSrcPixel[channel];
      pSrcPixel += sizeof(PLPixel32);
      ++pDstPixel;
    }
  }
}
예제 #2
0
PLPixel24 hls2rgb (double h, double l, double s)
{
  double m1, m2;
  l /= 255;
  s /= 100;
  // Warning: Foley, van Dam has a typo on the next line!
  m2 = (l<=0.5)?(l*(1.0+s)):(l+s-l*s);
  m1 = 2.0*l-m2;
  if (s<0.001)
    return PLPixel24(PLBYTE(l*255), PLBYTE(l*255), PLBYTE(l*255));
  else 
  {
    return PLPixel24(hls_value(m1,m2,h+120.0),
                     hls_value(m1,m2,h),
                     hls_value(m1,m2,h-120.0));
  }
}
예제 #3
0
// From Foley, van Dam p. 596
PLBYTE hls_value(double n1, double n2, double hue)
{
  if (hue>360)
    hue-=360;
  if (hue<0)   
    hue+=360;
  
  double rv;
  if (hue<60)  
    rv = n1+(n2-n1)*hue/60.0;
  else if (hue<180) 
    rv = n2;
  else if (hue<240) 
    rv = n1+(n2-n1)*(240.0-hue)/60.0;
  else 
    rv = n1;

  return PLBYTE(rv*255);
}