/*
* Copyright (C) =USTC= Fu Li
*
* Author : Fu Li
* Create : 2005-7-29
* Home : http://www.crazy-bit.com/
* Mail : crazybit@263.net
* History :
*/
#ifndef __FOO_PIXEL_PROCESSOR_BASE__2005_07_29__H__
#define __FOO_PIXEL_PROCESSOR_BASE__2005_07_29__H__
#include "../ObjImage.h"
#include "../FHistogram.h"
#include "../FColor.h"
//class FCInterface_PixelProcess ;
class FCSinglePixelProcessBase ;
class FCPixelConvertTo16Bit ; // 1, 4, 8, 24, 32 ==> 16
class FCPixelConvertTo8BitGray ; // 1, 4, 8, 16, 24, 32 ==> 8bit gray
class FCPixelGrayscale ; // gray scale (>=24 bit)
class FCPixelFillColor ; // Fill color (>=24 bit)
class FCPixelHueSaturation ; // hue saturation (>=24 bit)]
class FCPixelMirror ; // mirror (>=8 bit)
class FCPixelFlip ; // flip (>=8 bit)
class FCPixelShift ; // shift (>=24 bit)
class FCPixelAutoContrast ; // auto contrast (>=24 bit)
class FCPixelAutoColorEnhance ; // auto color enhance (>=24 bit)
class FCPixelEmboss ; // emboss (>=24 bit)
class FCPixelIllusion ; // illusion (>=24 bit)
class FCPixelBlinds ; // blinds (>=24 bit)
class FCPixelMosaic ; // mosaic (32 bit)
class FCPixelFill3DSolidFrame ; // fill 3D solid frame (>=24 bit)
class FCPixelAdjustRGB ; // adjust RGB (>=24 bit)
class FCPixelColorLevel ; // color level (>=24 bit)
class FCPixelThreshold ; // threshold (>=24 bit)
class FCPixelRotate90 ; // clockwise rotate 90' (>=8 bit)
class FCPixelRotate270 ; // clockwise rotate 270' (>=8 bit)
class FCPixelDeinterlace ; // de-interlace (32 bit)
class FCPixelHalftoneM3 ; // halftone (>=24 bit)
class FCPixelOilPaint ; // oil paint (>=24 bit)
class FCPixelColorTone ; // color tone (>=24 bit)
class FCPixelAddRandomNoise ; // add random noise (>=24 bit)
class FCPixelSplash ; // splash (>=24 bit)
class FCPixelVideo ; // video (>=24 bit)
class FCPixelColorBalance ; // color balance (>=24 bit)
class FCPixelFillGrid ; // fill grid (>=24 bit)
class FCPixel3DGrid ; // add 3D grid (>=24 bit)
class FCPixelMedianFilter ; // Median filter (>=24 bit)
class FCPixelSpliteChannel_RGB ; // splite RGB channel (>=24 bit)
class FCPixelCombineChannel_RGB ; // combine RGB channel (>=24 bit)
class FCPixelConvolute ; // image convolute (>= 24 bit)
class FCPixelGaussianBlur3x3 ; // Standard 3x3 gaussian blur (>=24 bit)
class FCPixelGaussianBlur5x5 ; // Standard 5x5 gaussian blur (>=24 bit)
class FCPixelDetectEdges ; // Detect edges (>=24 bit)
class FCPixelSharp ; // Sharp (laplacian template) (>=24 bit)
class FCPixelGradientBase ; // base class of gradient fill (>=24 bit)
class FCPixelGradientLine ; // gradient fill linear (>=24 bit)
class FCPixelGradientBiLine ; // gradient fill bilinear (>=24 bit)
class FCPixelGradientConicalSym ; // gradient fill symmetric conical (>=24 bit)
class FCPixelGradientConicalASym ; // gradient fill Anti-symmetric conical (>=24 bit)
class FCPixelGradientRect ; // gradient fill rect (>=24 bit)
class FCPixelGradientRadial ; // gradient fill radial (>=24 bit)
class FCPixelBilinearDistord ; // bilinear distord (>=24 bit)
class FCPixelCylinder ; // cylinder (>=24 bit)
class FCPixelWave ; // wave (>=24 bit)
class FCPixelWhirlPinch ; // whirl & pinch (>=24 bit)
class FCPixelFractalTrace ; // Fractal trace (>=24 bit)
class FCPixelLens ; // lens (>=24 bit)
class FCPixelSkew ; // skew transform (>=24 bit)
class FCPixelPerspective ; // perspective transform (>=24 bit)
class FCPixelRotate ; // rotate (>=24 bit)
class FCPixelRibbon ; // ribbon (>=24 bit)
class FCPixelRipple ; // ripple (>=24 bit)
class FCPixelSmallTile ; // tile (>=24 bit)
class FCPixelLUTRoutine ; // LUT(look up table) routine (>=24 bit)
class FCPixelBrightness ; // adjust brightness (>=24 bit)
class FCPixelContrast ; // adjust contrast (>=24 bit)
class FCPixelGamma ; // adjust gamma (>=24 bit)
class FCPixelInvert ; // negate (>=24 bit)
class FCPixelSolarize ; // Solarize (>=24 bit)
class FCPixelPosterize ; // posterize (>=24 bit)
class FCPixelColorsCount ; // count image's number of color (>=24 bit)
class FCPixelGetKeyColor ; // Find a color unused in image (>=24 bit)
class FCPixelExportAscII ; // save a ASCII text file (>=24 bit)
//=============================================================================
/**
* Base class of processor.
*/
class FCSinglePixelProcessBase : public FCInterface_PixelProcess
{
public:
FCSinglePixelProcessBase() : m_pImgOld(0) {}
virtual ~FCSinglePixelProcessBase() {if(m_pImgOld) delete m_pImgOld;}
/// whether the image can be disposed by this processor.
/// default test image's bpp >= 24
virtual bool ValidateColorBits (const FCObjImage* pImg)
{
return pImg->IsValidImage() && (pImg->ColorBits() >= 24) ;
}
protected:
void SetBackupImage (const FCObjImage* pImg)
{
if (pImg)
{
if (m_pImgOld)
delete m_pImgOld ;
m_pImgOld = new FCObjImage(*pImg) ;
}
}
FCObjImage* GetBackupImage() const {return m_pImgOld;}
private:
FCObjImage * m_pImgOld ; // backup image
};
//=============================================================================
/**
* 1, 4, 8, 24, 32 ==> 16.
@verbatim
example:
FCPixelConvertTo16Bit aCmd ;
img.SinglePixelProcessProc (aCmd) ;
@endverbatim
*/
class FCPixelConvertTo16Bit : public FCSinglePixelProcessBase
{
virtual bool ValidateColorBits (const FCObjImage* pImg) {return pImg->IsValidImage() && (pImg->ColorBits() != 16) ;}
virtual void OnEnterProcess (FCObjImage* pImg)
{
SetBackupImage(pImg) ;
// make it easier, now we only need 24(32) ==> 16
if (pImg->ColorBits() <= 8)
GetBackupImage()->ConvertTo24Bit() ;
pImg->Create (pImg->Width(), pImg->Height(), 16) ;
}
virtual void ProcessPixel (FCObjImage* pImg, int x, int y, BYTE* pPixel)
{
*(WORD*)pPixel = Combine16Bit_555 (GetBackupImage()->GetBits(x,y)) ; // 24,32 ==> 16
}
static WORD Combine16Bit_555 (const void* pRGB)
{
const WORD wR = ((PCL_R(pRGB) >> 3) << 10),
wG = ((PCL_G(pRGB) >> 3) << 5),
wB = (PCL_B(pRGB) >> 3) ;
return (wR | wG | wB) ;
}
};
//=============================================================================
/**
* 1, 4, 8, 16, 24, 32 ==> 8bit gray.
@verbatim
example:
FCPixelConvertTo8BitGray aCmd ;
img.SinglePixelProcessProc (aCmd) ;
@endverbatim
*/
class FCPixelConvertTo8BitGray : public FCSinglePixelProcessBase
{
virtual bool ValidateColorBits (const FCObjImage* pImg) {return pImg->IsValidImage();}
virtual void OnEnterProcess (FCObjImage* pImg)
{
SetBackupImage(pImg) ;
// make it easier, now we only need 24(32) ==> 8bit gray
if (pImg->ColorBits() <= 16)
GetBackupImage()->ConvertTo24Bit() ;
pImg->Create (pImg->Width(), pImg->Height(), 8) ; // default to set a gray palette
}
virtual void ProcessPixel (FCObjImage* pImg, int x, int y, BYTE* pPixel)
{
*pPixel = FCColor::GetGrayscale (GetBackupImage()->GetBits(x,y)) ;
}
};
//=============================================================================
/**
* Gray scale image (>=24 bit).
* all channel are same after process.
@verbatim
example:
FCPixelGrayscale aCmd ;
img.SinglePixelProcessProc (aCmd) ;
@endverbatim
*/
class FCPixelGrayscale : public FCSinglePixelProcessBase
{