App

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

TBitmap.hpp
Go to the documentation of this file.
1
6 // forward declaration
7 namespace app {
8 template <typename TPIXEL, typename TCHANNEL> class TBitmap;
9 }
10
11 #ifndef TBITMAP_HPP_
12 #define TBITMAP_HPP_
13
14 #include <cstdlib>
15
16 #include "../typedefs.hpp"
17 #include "../utils/Geometry.hpp"
18 #include "../utils/PointerArea.hpp"
19
20 typedef app::TBitmap<px_4x8bit, px_1x8bit> rgba_8bit_bitmap;
21 typedef app::TBitmap<px_1x8bit, px_1x8bit> mono_8bit_bitmap;
22
23
24 using namespace std;
25
26 namespace app {
27
28
33 typedef enum {
34 INVALID_COLOR_MODE = 0,
35 MONO = 1,
36 RGBA = 2,
37 HSVA = 3,
38 HLSA = 4,
39 } ColorMode;
40
45 typedef enum {
46 invalid_type = 0,
47 mono_8_bit = 1,
48 rgba_8_bit = 2,
49 mono_16_bit = 3,
50 rgba_16_bit = 4,
51 } BitmapNativeType;
52
65 template <typename TPIXEL, typename TCHANNEL>
66 class TBitmap {
67 protected:
68 ColorMode type;
69 TPIXEL * data;
70 unsigned int width;
71 unsigned int height;
72 unsigned int bpp;
73 int premultiplied;
74 int ownsData;
75
76 public:
77
78 static const unsigned int chCount;
79 static const TCHANNEL maxVal;
80
82 TBitmap() {
83 type = INVALID_COLOR_MODE;
84 data = NULL;
85 width = 0;
86 height = 0;
87 bpp = 0;
88 premultiplied = 0;
89 ownsData = 0;
90 }
91
93
100 TBitmap (unsigned int width, unsigned int height, ColorMode type, int premultiplied) {
101 data = NULL;
102 unsigned long int size = width * height;
103 if (size > 0) {
104 data = (TPIXEL *) malloc((unsigned long int)(size * sizeof(TPIXEL))); // ANDROID_SPECIFIC Přetypování na unsigned long int kvůli Eclipse a androidu
105 }
106 if (data != NULL) {
107 this->type = type;
108 this->width = width;
109 this->height = height;
110 bpp = sizeof(TPIXEL);
111 this->premultiplied = premultiplied;
112 ownsData = 1;
113 } else {
114 this->type = INVALID_COLOR_MODE;
115 data = NULL;
116 this->width = 0;
117 this->height = 0;
118 bpp = 0;
119 this->premultiplied = 0;
120 ownsData = 0;
121 }
122 }
123
125
133 TBitmap (void * data, unsigned width, unsigned height, ColorMode type, int premultiplied) {
134 if (data != NULL && width > 0 && height > 0) {
135 this->type = type;
136 this->width = width;
137 this->height = height;
138 bpp = sizeof(TPIXEL);
139 this->premultiplied = premultiplied;
140 ownsData = 0;
141 this->data = (TPIXEL *) data;
142 } else {
143 this->type = INVALID_COLOR_MODE;
144 data = NULL;
145 this->width = 0;
146 this->height = 0;
147 bpp = 0;
148 this->premultiplied = 0;
149 ownsData = 0;
150 }
151
152 }
153
155 TBitmap(TBitmap<TPIXEL, TCHANNEL> &other) {
156 type = other.type;
157 width = other.width;
158 height = other.height;
159 bpp = other.bpp;
160 premultiplied = other.premultiplied;
161 if (other.data != NULL) { // raději jak neplatný typ, že se jedná o stejnou bitmapu je dáno template
162 int size = width * height * sizeof(TPIXEL);
163 data = (TPIXEL *) malloc(size);
164 if (data != NULL) {
165 memcpy(data, other.data, size);
166 ownsData = 1;
167 } else {
168 type = INVALID_COLOR_MODE;
169 ownsData = 0;
170 }
171 } else {
172 data = NULL;
173 ownsData = 0;
174 }
175 }
176
178 virtual ~TBitmap() ;
179
181 ColorMode getType() const {return type;}
182
184 void setType(ColorMode mode) {type = mode;}
185
187 TPIXEL * getData() const {return data;}
188
190 unsigned int getWidth() const {return width;}
191
193 unsigned int getHeight() const {return height;}
194
196 unsigned int getBpp() const {return bpp;}
197
199
203 Rect getRect() const {return Rect(0, 0, width, height);}
204
206 PointerArea getPointerArea() const {return PointerArea(data, getRect(), bpp);}
207
209 int isPremultiplied() { return premultiplied; }
210
212
216 void setPremultiplied(int premultiplied) { this->premultiplied = premultiplied; }
217
219
225 virtual int premultiply();
226
228
233 virtual int demultiply();
234
236
241 virtual TBitmap<TCHANNEL, TCHANNEL> * getChannel(unsigned index) const;
242
244
258 virtual int copyTo(TBitmap<TPIXEL, TCHANNEL> &dst, Rect srcRect, Point srcOrig) const;
259
261
268 virtual int fill(Rect area, TPIXEL * src);
269
271 int clear() {
272 if (data != NULL) {
273 memset(data, 0, width * height * bpp);
274 return 0;
275 }
276 return 1;
277 }
278
280
292 virtual TBitmap<TPIXEL, TCHANNEL> * difference(TBitmap<TPIXEL, TCHANNEL> &other, int proportional = 0) const;};
293
294 template <typename TPIXEL, typename TCHANNEL>
295 const unsigned TBitmap<TPIXEL, TCHANNEL>::chCount = sizeof(TPIXEL) / sizeof(TCHANNEL);
296
297 template <typename TPIXEL, typename TCHANNEL>
298 const TCHANNEL TBitmap<TPIXEL, TCHANNEL>::maxVal = ~0;
299
300 } /* namespace app */
301 #endif /* TBITMAP_HPP_ */