]> git.saurik.com Git - wxWidgets.git/blob - interface/rawbmp.h
First attempt to document raw bitmap access
[wxWidgets.git] / interface / rawbmp.h
1
2 /**
3 @class wxPixelData
4 @wxheader{rawbmp.h}
5
6 A class template with ready to use implementations for getting
7 direct and efficient access to wxBitmap's internal data and
8 wxImage's internal data through a standard interface. It is
9 possible to extend this class (interface) to other types of
10 image content.
11
12 Implemented on Windows, GTK+ and OS X:
13 wxNativePixelData: Class to access to wxBitmap's internal data without alpha channel (RGB).
14 wxAlphaPixelData: Class to access to wxBitmap's internal data with alpha channel (RGBA).
15
16 Implemented everywhere:
17 wxImagePixelData: Class to access to wxImage's internal data with alpha channel (RGBA).
18
19 @code
20 wxBitmap bmp;
21 wxNativePixelData data(bmp);
22 if ( !data )
23 {
24 ... raw access to bitmap data unavailable, do something else ...
25 return;
26 }
27
28 if ( data.GetWidth() < 20 || data.GetHeight() < 20 )
29 {
30 ... complain: the bitmap it too small ...
31 return;
32 }
33
34 wxNativePixelData::Iterator p(data);
35
36 // we draw a (10, 10)-(20, 20) rect manually using the given r, g, b
37 p.Offset(data, 10, 10);
38
39 for ( int y = 0; y < 10; ++y )
40 {
41 wxNativePixelData::Iterator rowStart = p;
42
43 for ( int x = 0; x < 10; ++x, ++p )
44 {
45 p.Red() = r;
46 p.Green() = g;
47 p.Blue() = b;
48 }
49
50 p = rowStart;
51 p.OffsetY(data, 1);
52 }
53 @endcode
54
55 @library{wxcore}
56 @category{gdi}
57
58 @see wxBitmap, wxImage
59 */
60 template <class Image, class PixelFormat = wxPixelFormatFor<Image> >
61 class wxPixelData :
62 public wxPixelDataOut<Image>::template wxPixelDataIn<PixelFormat>
63 {
64 public:
65 /**
66 the type of the class we're working with
67 */
68 typedef Image ImageType;
69
70 /**
71 Create pixel data object representing the entire image
72 */
73 wxPixelData(Image& image);
74
75
76 /**
77 Create pixel data object representing the area
78 of the image defined by @e rect.
79 */
80 wxPixelData(Image& i, const wxRect& rect);
81
82 /**
83 Create pixel data object representing the area
84 of the image defined by @e pt and @e sz.
85 */
86 wxPixelData(Image& i, const wxPoint& pt, const wxSize& sz)
87
88 /**
89 Return true of if we could get access to bitmap data
90 successfully
91 */
92 operator bool() const:
93
94 /**
95 Return the iterator pointing to the origin of the image
96 */
97 Iterator GetPixels() const;
98
99 /**
100 Returns origin of the rectangular region we represent
101 */
102 wxPoint GetOrigin() const;
103
104 /**
105 Return width of the region we represent
106 */
107 int GetWidth() const;
108
109 /**
110 Return height of the region we represent
111 */
112 int GetHeight() const;
113
114 /*
115 Return area which this class represents in the image
116 */
117 wxSize GetSize() const;
118
119 /**
120 Return the distance between two rows
121 */
122 int GetRowStride() const;
123
124
125 /**
126 Iterator
127 */
128 class Iterator
129 {
130 public:
131 /**
132 go back to (0, 0)
133 */
134 void Reset(const PixelData& data);
135
136 /**
137 Initializes the iterator to point to the origin of the given
138 pixel data
139 */
140 Iterator(PixelData& data);
141
142 /**
143 Initializes the iterator to point to the origin of the given
144 Bitmap
145 */
146 Iterator(wxBitmap& bmp, PixelData& data);
147
148 /**
149 Default constructor
150 */
151 Iterator();
152
153 /**
154 Return true if this iterator is valid
155 */
156 bool IsOk() const;
157
158 /**
159 Advance the iterator to the next pixel, prefix version
160 */
161 Iterator& operator++();
162
163 /**
164 Postfix (hence less efficient -- don't use it unless you
165 absolutely must) version
166 */
167 Iterator operator++(int);
168
169 /**
170 Move x pixels to the right and y down
171 note that the rows don't wrap!
172 */
173 void Offset(const PixelData& data, int x, int y);
174
175 /**
176 Move x pixels to the right (again, no row wrapping)
177 */
178 void OffsetX(const PixelData&data, int x);
179
180 /**
181 Move y rows to the bottom
182 */
183 void OffsetY(const PixelData& data, int y);
184
185 /**
186 Go to the given position
187 */
188 void MoveTo(const PixelData& data, int x, int y);
189
190 //@{
191 /**
192 Data access: gives access to invidividual colour components.
193 */
194 ChannelType& Red();
195 ChannelType& Green();
196 ChannelType& Blue();
197 ChannelType& Alpha();
198 //@}
199 };
200 };
201