// ======================================================== // Module: Ccnlv.h/cpp // // Description: Apply various filters onto an image // // Author(s): Chi Toung Yeung cty // // Input: raw binary image ( no line end padding ) // Output: raw binary image ( no line end padding ) // // History: // 26Sep02 General methods definitions cty // 29Sep02 SetKernel(), GetKernel() cty // 20Jan03 SetKernel() cty // 20Jan03 Sobel() - 8bpp raw only cty // 20Jan03 Sobel_X_8bpp() cty // 20Jan03 Sobel_Y_8bpp() cty // 20Jan03 Absol() cty // 20Jan03 Apply() need future updates to compensate // for big image memory model cty // 21Jan03 KERNEL_BLUR_MORE removed cty // 27Jan03 Custom() cty // 09Sept05 Re-worked for Cnvltn dialog app. cty // 09Sept05 Added lots of in-stock kernels cty // 09Sept05 Removed all the specialized methods. // instead, just load the kernel and call // the generic Convolve(). It is slower cty // 09Sept05 Convolve() needs work cty // 11Sept05 Added the three options in Convolve() cty // 12Sept05 Median filter removed.. it belongs in // statistical or noise filter cty // 14Sept05 Correction to highpass cty // 16Sept05 Add unsharpmask filter - strange, did not // need to reduced the derivative result cty // 16Sept05 Add unsharpmask for 1 plane... just for // SharperImage application cty // ======================================================== // -------------------------------------------------------- // Constants // -------------------------------------------------------- #define CCNLV_MONOCHROME 8 #define CCNLV_RGB 24 #define CCNLV_CMYK 32 #define CCNLV_DEFAULT_KERNEL_SIZE 9 #define CCNLV_SOBEL_KERNEL_SIZE 2 #define CCNLV_DEFAULT_WIDTH 3 #define CCNLV_KERNEL_CENTER 4 #define NUM_OF_FILTERS 11 #define NAME_LAPLACIAN "Laplacian" #define NAME_SOBEL_X "Sobel X" #define NAME_SOBEL_Y "Sobel Y" #define NAME_ROBERTS_45 "Roberts 45" #define NAME_ROBERTS_135 "Roberts 135" #define NAME_PREWITT_X "Prewitt X" #define NAME_PREWITT_Y "Prewitt Y" #define NAME_LOWPASS "Lowpass" #define NAME_HIGHPASS "Highpass" #define NAME_UNSHARP_MASK "Unsharp Mask" #define NAME_CUSTOM "Custom" enum {LAPLACIAN, SOBEL_X, SOBEL_Y, ROBERTS_45, ROBERTS_135 , PREWITT_X, PREWITT_Y, LOW_PASS, HIGH_PASS, UNSHARP_MASK, CUSTOM}; // -------------------------------------------------------- // Errors // -------------------------------------------------------- #define CCNLV_OK 1 #define CCNLV_NO_KERNEL -900 #define CCNLV_BAD_KERNEL_TYPE -901 #define CCNLV_MISSING_IMAGE -902 #define CCNLV_BAD_IMAGE -904 #define CCNLV_INVALID_PIXEL_DEPTH -905 #define CCNLV_INVALID_ENTRY -906 #define CCNLV_INVALID_KERNEL -907 #define CCNLV_INVALID_KERNEL_LENGTH -908 // -------------------------------------------------------- // Class definition // -------------------------------------------------------- class Ccnlv { public: Ccnlv(); ~Ccnlv(); void Empty(); bool IsEmpty(); public: int LoadImage( uchar *pImage, int iNofp, long lWid, long lLen ); int SetKernel ( int iType ); int SetKernel ( int wid, double pKern[] ); int Convolve (); int UnSharpMask (); int UnSharpMask ( int plane ); private: int Absol ( int ); int Absol ( double ); int Requant ( int ); public: int m_iRc; CString m_sRc; double *m_pKern; int m_iKrnWid; private: long m_lImgWid, m_lImgLen; int m_iNofp; uchar *m_pImg; };