
| //================================================================ class FCSinglePixelProcessBase { public : virtual void ProcessPixel (int x, int y, BYTE * pPixel) PURE ; } ; //================================================================ class FCPixelInvert : public FCSinglePixelProcessBase { public : virtual void ProcessPixel (int x, int y, BYTE * pPixel) ; } ; void FCPixelInvert::ProcessPixel (int x, int y, BYTE * pPixel) { pPixel[0] = ~pPixel[0] ; pPixel[1] = ~pPixel[1] ; pPixel[2] = ~pPixel[2] ; } //================================================================ class FCPixelAdjustRGB : public FCSinglePixelProcessBase { public : FCPixelAdjustRGB (int DeltaR, int DeltaG, int DeltaB) ; virtual void ProcessPixel (int x, int y, BYTE * pPixel) ; protected : int m_iDeltaR, m_iDeltaG, m_iDeltaB ; } ; void FCPixelAdjustRGB::ProcessPixel (int x, int y, BYTE * pPixel) { pPixel[0] = FClamp0255 (pPixel[0] + m_iDeltaB) ; pPixel[1] = FClamp0255 (pPixel[1] + m_iDeltaG) ; pPixel[2] = FClamp0255 (pPixel[2] + m_iDeltaR) ; } //================================================================ |
| //================================================================ #include "PixelProcessor.h" class FCObjImage { public : void PixelHandler (FCSinglePixelProcessBase & PixelProcessor, FCObjProgress * progress = NULL) ; } ; //================================================================ void FCObjImage::PixelHandler (FCSinglePixelProcessBase & PixelProcessor, FCObjProgress * progress) { if (GetHandle() == NULL) return ; int nSpan = ColorBits() / 8 ; // 每象素字节数3, 4 for (int y=0 ; y < Height() ; y++) { BYTE * pPixel = GetBits (y) ; for (int x=0 ; x < Width() ; x++, pPixel += nSpan) { PixelProcessor.ProcessPixel (x, y, pPixel) ; } if (progress != NULL) progress->SetProgress (y * 100 / Height()) ; } } //================================================================ void FCObjImage::Invert (FCObjProgress * progress) { PixelHandler (FCPixelInvert(), progress) ; } void FCObjImage::AdjustRGB (int R, int G, int B, FCObjProgress * progress) { PixelHandler (FCPixelAdjustRGB (R,G,B), progress) ; } //================================================================ |
| //================================================================class FCPixelTest : public FCSinglePixelProcessBase { public : virtual void ProcessPixel (int x, int y, BYTE * pPixel) ; } ; void FCPixelTest::ProcessPixel (int x, int y, BYTE * pPixel) { if (y % 2) pPixel[0]=pPixel[1]=pPixel[2] = 0 ; // 奇数行 else pPixel[0]=pPixel[1]=pPixel[2] = 0xFF ; // 偶数行 } |
| PixelHandler (FCPixelTest(), progress) ; //================================================================ |
| #include "PixelProcessor.h" |
| class FCSinglePixelProcessBase ; // external class 前置声明 |