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
#pragma once
 
class CPixelPtr
{
public:
    CPixelPtr(CImage &image)
    {
        m_cyImage = image.GetHeight();
        m_pRow = new BYTE *[m_cyImage];
        int nPitch = image.GetPitch();
 
        BYTE *pRow = (BYTE *)image.GetBits();
 
        for(int y=0 ; y<m_cyImage ; y++)
        {
            m_pRow[y] = (BYTE *)pRow;
            pRow += nPitch;
        }
    }
 
    virtual ~CPixelPtr(void)
    {
        if(m_pRow != NULL)
            delete [] m_pRow;
    }
 
    BYTE *operator[](LONG index) {
        ASSERT(index>=0 && index<m_cyImage);
        return m_pRow[index];
    }
 
    BYTE *operator[](int index) {
        ASSERT(index>=0 && index<m_cyImage);
        return m_pRow[index];
    }
 
protected:
    BYTE ** m_pRow;
    int m_cyImage;
};