1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#pragma once
 
#include "cxcore.h"
#include "cv.h"
#include "highgui.h"
 
enum ImageBandType    { ImageBand_Red=0, ImageBand_Green, ImageBand_Blue, ImageBand_Gray, ImageBand_Color, ImageBand_Count };
 
//struct _IplImage;
 
class AFX_EXT_CLASS CImageBuffer
{
public:
    CImageBuffer(void);
    CImageBuffer(int nWidth, int nHeight, int nDepth=8, int nChannels=1);
    virtual ~CImageBuffer(void);
 
public: // virtual functions
    virtual BOOL    CreateImage(int nWidth, int nHeight, int nDepth=8, int nChannels=1);
    virtual BOOL    CreateImageHeader(int nWidth, int nHeight, int nDepth=8, int nChannels=1);
    virtual BOOL    GetImageExist(void) const;
    virtual BOOL    GetAllocatedData(void) const;
 
    virtual void    ReleaseImage(void);
    virtual int        GetHeight(void) const;
    virtual int        GetWidth(void) const;
    virtual int        GetWidthStep(void) const;
    virtual int        GetDepth(void) const;
    virtual int        GetChannels(void) const;
    virtual int        GetBpp(void) const;
    virtual int        GetImageSize(void) const;
 
    virtual char*    GetImageBuffer(void);
    virtual char*    GetImageBufferOrigin(void);
    virtual const char*    GetImageBuffer(void) const;
    virtual const char*    GetImageBufferOrigin(void) const;
    virtual int        GetPixelValue(int x, int y) const;
    virtual int        SetPixelValue(int x, int y, int nR, int nG, int nB);
    virtual int        SetPixelValue(int x, int y, int nR, int nG, int nB, int nA);
 
    virtual BOOL    LoadImage(const CString& strFilename);
    virtual BOOL    SaveImage(const CString& strFilename, int nQiality=95) const;
 
public: // common functions
    // clear
    BOOL    ClearImage(int nValue);
    BOOL    ClearImage(int nValue, int nA);
 
    // copy func
    BOOL    CopyImageTo(CImageBuffer *pToImage) const;
    BOOL    CopyImageTo(IplImage *pToImage) const;
    BOOL    CopyImageFrom(const CImageBuffer *pFromImage);
    BOOL    CopyImageFrom(const IplImage *pFromImage);
 
    // show func
    void    ShowImage(HDC hDC, const CRect& dstRect);
    void    ShowImage(HDC hDC, const CRect& srcRect, const CRect& dstRect);
    void    ShowImage(HDC hDC, int nSx, int nSy, int nWidth, int nHeight, int nFromX, int nFromY);
 
    // get image data
    BOOL    GetSubImage(int nSx, int nSy, int nWidth, int nHeight, CImageBuffer *pGetImage);
    BOOL    GetSubImage(int nSx, int nSy, int nWidth, int nHeight, int nChannels, BYTE *pGetBuffer);
    BOOL    GetSubImage(const CRect& rtRect, CImageBuffer *pGetImage);
    BOOL    GetSubImage(const CRect& rtRect, int nChannels, BYTE *pGetBuffer);
 
    BOOL    GetBandImage(int nColorBand, CImageBuffer* pGetImage) const;
    BOOL    GetBandImage(int nColorBand, int nSx, int nSy, int nWidth, int nHeight, CImageBuffer* pGetImage);
    BOOL    GetBandImage(int nColorBand, int nSx, int nSy, int nWidth, int nHeight, BYTE* pGetBuffer);
    BOOL    GetBandImage(int nColorBand, const CRect& rtRect, CImageBuffer* pGetImage);
    BOOL    GetBandImage(int nColorBand, const CRect& rtRect, BYTE* pGetBuffer);
 
    // set image data
    BOOL    SetSubImage(int nSx, int nSy, int nWidth, int nHeight, CImageBuffer* pSetImage);
    BOOL    SetSubImage(int nSx, int nSy, int nWidth, int nHeight, int nBpp, BYTE *pSetBuffer);
    BOOL    SetSubImage(const CRect& rtRect, CImageBuffer *pSetImage);
    BOOL    SetSubImage(const CRect& rtRect, int nChannels, BYTE *pSetBuffer);
 
    // draw function
    BOOL    DrawLine(CPoint ptPos1, CPoint ptPos2, DWORD nColor, int nThickness=1, int nLineType=8, int nShift=0 );
    BOOL    DrawRectangle(CPoint ptPos1, CPoint ptPos2, DWORD nColor, int nThickness=1, int nLineType=8, int nShift=0 );
    BOOL    DrawCircle(CPoint ptCenter, int nRadius, DWORD nColor, int nThickness=1, int nLineType=8, int nShift=0 );
    BOOL    DrawEllipse(CPoint ptCenter, CPoint ptSize, double dAngle, DWORD nColor, int nThickness=1, int nLineType=8, int nShift=0);
    BOOL    DrawText(CPoint ptPoint, DWORD nColor, const CString& strText);
 
    // buffer access
    IplImage*            GetIplImage(void);
    BOOL                SetImageBufferPtr(char* pPtr);
 
    BOOL            DIBtoIplImage(HBITMAP& hbmp, HDC hdc=NULL);
    BOOL            DCtoIplImage(CDC* pDC, const CRect& rect);
 
    // 4Ch Image..
    CvScalar GetPixelScalar(int x, int y);
 
protected:
    static void        FillBitmapInfo(BITMAPINFO* bmi, int width, int height, int bpp, int origin);
 
    BOOL        m_bAllocatedData;
 
public:
    IplImage    *m_pImageData;
};