00001
00018 #include "vetFrameRGBA32.h"
00019
00020 vetFrameRGBA32::vetFrameRGBA32() : vetFrame()
00021 {
00022 height = 0;
00023 width = 0;
00024 data = NULL;
00025 autoFreeData = true;
00026 }
00027
00033 vetFrameRGBA32::vetFrameRGBA32(unsigned int w, unsigned int h)
00034 {
00035 data = NULL;
00036 reAllocCanvas(w, h);
00037 autoFreeData = true;
00038 }
00039
00040
00041
00045 vetFrameRGBA32::vetFrameRGBA32(vetFrameRGBA32& img)
00046 {
00047 data = NULL;
00048 reAllocCanvas(img.width, img.height);
00049
00050 if ( width != 0 && height != 0 )
00051 memcpy(data, img.data, width * height * 4);
00052
00053 autoFreeData = true;
00054 }
00055
00056
00057
00058
00062 vetFrameRGBA32::vetFrameRGBA32(vetFrameRGB24& img)
00063 {
00064 data = NULL;
00065 reAllocCanvas(img.width, img.height);
00066
00067 *this << img;
00068
00069 autoFreeData = true;
00070 }
00071
00075 vetFrameRGBA32::vetFrameRGBA32(vetFrameRGB96& img)
00076 {
00077 data = NULL;
00078 reAllocCanvas(img.width, img.height);
00079
00080 *this << img;
00081
00082 autoFreeData = true;
00083 }
00084
00085
00089 vetFrameRGBA32::~vetFrameRGBA32()
00090 {
00091 INFO("vetFrameRGBA32::~vetFrameRGBA32() [DESTRUCTOR]")
00092
00093 if ( autoFreeData && data != NULL )
00094 delete [] data;
00095 }
00096
00097
00098 VETRESULT vetFrameRGBA32::reAllocCanvas(unsigned int w, unsigned int h)
00099 {
00100 if (data != NULL)
00101 delete [] data;
00102
00103 height = h;
00104 width = w;
00105 data = NULL;
00106
00107 if ( width == 0 || height == 0)
00108 return VETRET_PARAM_ERR;
00109
00110 data = new unsigned char[width * height * 4];
00111
00112 return VETRET_OK;
00113 }
00114
00115 VETRESULT vetFrameRGBA32::setBlack()
00116 {
00117 if (width == 0 || height == 0 || data == NULL)
00118 return VETRET_ILLEGAL_USE;
00119
00120 memset(data, '\0', width * height * 4 );
00121
00122 return VETRET_OK;
00123 }
00124
00125 VETRESULT vetFrameRGBA32::setWhite()
00126 {
00127 if (width == 0 || height == 0 || data == NULL)
00128 return VETRET_ILLEGAL_USE;
00129
00130 memset(data, 255, width * height * 4 );
00131
00132 return VETRET_OK;
00133 }
00134
00135 VETRESULT vetFrameRGBA32::extractBrightness(unsigned char* buffer, unsigned int* size)
00136 {
00137 if (width == 0 || height == 0 || data == NULL)
00138 return VETRET_ILLEGAL_USE;
00139
00140 if (buffer == NULL)
00141 {
00142 if ( size == NULL)
00143 return VETRET_PARAM_ERR;
00144
00145 *size = width*height;
00146 return VETRET_OK;
00147 }
00148
00149 return VETRET_NOT_IMPLEMENTED;
00150 }
00151
00152
00162 VETRESULT vetFrameRGBA32::getPixel(unsigned int x, unsigned int y, unsigned char* p)
00163 {
00164 #ifdef _vetFrameRGBA32_SLOWMODE
00165 if ( x >= width || y >= height )
00166 throw "Invalid Coordinates in method vetFrameRGBA32::getPixel(unsigned int x, unsigned int y, PixelRGB& p)";
00167 #endif //_vetFrameRGBA32_SLOWMODE
00168
00169 unsigned int offset = y * width + x;
00170
00171 p[0] = data[offset];
00172 p[1] = data[offset + width*height];
00173 p[2] = data[offset + width*height*2];
00174 p[3] = data[offset + width*height*3];
00175
00176 return VETRET_OK;
00177 }
00178
00188 VETRESULT vetFrameRGBA32::setPixel(unsigned int x, unsigned int y, unsigned char* p)
00189 {
00190 #ifdef _vetFrameRGBA32_SLOWMODE
00191 if ( x >= width || y >= height )
00192 throw "Invalid Coordinates in method vetFrameRGBA32::setPixel(unsigned int x, unsigned int y, PixelRGB p)";
00193 #endif //_vetFrameRGBA32_SLOWMODE
00194
00195 data[y * width + x] = p[0];
00196
00197 data[y * width + x + width*height] = p[1];
00198 data[y * width + x + width*height*2] = p[2];
00199 data[y * width + x + width*height*3] = p[3];
00200
00201 return VETRET_OK;
00202 }
00203
00204
00212 vetFrameRGBA32& vetFrameRGBA32::clearWith(unsigned char* p)
00213 {
00214 if ( data == NULL || width == 0 || height == 0)
00215 throw "Image is empty.";
00216
00217
00218 memset(data, p[0], width * height );
00219 memset(data + width * height, p[1], width * height );
00220 memset(data + width * height * 2, p[2], width * height );
00221 memset(data + width * height * 3, p[3], width * height );
00222
00223
00224
00225 return *this;
00226 }
00227
00236 vetFrameRGBA32& vetFrameRGBA32::operator = (vetFrameRGBA32& img)
00237 {
00238
00239 if (this == &img)
00240 return *this;
00241
00242 if (width != img.width || height != img.height)
00243 reAllocCanvas(img.width, img.height);
00244
00245 if ( width == 0 || height == 0 )
00246 throw "Cannot do that with empty image (no size)";
00247
00248 memcpy(data, img.data, width * height * 4);
00249
00250 return *this;
00251 }
00252
00253
00254 vetFrameRGBA32& vetFrameRGBA32::operator += (vetFrameRGBA32& img)
00255 {
00256 INFO("vetFrameRGBA32& vetFrameRGBA32::operator += (vetFrameRGBA32& img)")
00257
00258 if (width != img.width || height != img.height)
00259 throw "Difference in vetFrameYUV420 Dimensions";
00260
00261 for(unsigned int i=0; i < width * height * 4; i++)
00262 data[i] += img.data[i];
00263
00264 return *this;
00265 }
00266
00267 vetFrameRGBA32& vetFrameRGBA32::operator -= (vetFrameRGBA32& img)
00268 {
00269 INFO("vetFrameRGBA32& vetFrameRGBA32::operator += (vetFrameRGBA32& img)")
00270
00271 if (width != img.width || height != img.height)
00272 throw "Difference in vetFrameYUV420 Dimensions";
00273
00274 for(unsigned int i=0; i < width * height * 4; i++)
00275 data[i] -= img.data[i];
00276
00277 return *this;
00278 }
00279
00280
00281
00282 vetFrameRGBA32& vetFrameRGBA32::operator >> (vetFrameRGB24& img)
00283 {
00284 INFO("vetFrameRGBA32& vetFrameRGBA32::operator >> (vetFrameRGB24& img) [pushing data]")
00285
00286 if ( width == 0 || height == 0 )
00287 throw "Cannot do that with empty image (no size)";
00288
00289 if (width != img.width || height != img.height )
00290 img.reAllocCanvas(width, height);
00291
00292 unsigned char* R = data;
00293 unsigned char* G = data + width*height;
00294 unsigned char* B = data + width*height*2;
00295
00296 for (unsigned int i=0; i< width*height; i++)
00297 {
00298 img.data[i][0] = *(R++);
00299 img.data[i][1] = *(G++);
00300 img.data[i][2] = *(B++);
00301 }
00302
00303
00304 return *this;
00305 }
00306
00307
00308
00309 vetFrameRGBA32& vetFrameRGBA32::operator >> (vetFrameRGB96& img)
00310 {
00311 INFO("vetFrameRGBA32& vetFrameRGBA32::operator >> (vetFrameRGB96& img) [pushing data]")
00312
00313 if ( width == 0 || height == 0 )
00314 throw "Cannot do that with empty image (no size)";
00315
00316 if (width != img.width || height != img.height )
00317 img.reAllocCanvas(width, height);
00318
00319 unsigned char* R = data;
00320 unsigned char* G = data + width*height;
00321 unsigned char* B = data + width*height*2;
00322
00323 for (unsigned int i=0; i< width*height; i++)
00324 {
00325 img.data[i][0] = (int)*(R++);
00326 img.data[i][1] = (int)*(G++);
00327 img.data[i][2] = (int)*(B++);
00328 }
00329
00330
00331 return *this;
00332 }
00333
00334
00335 void vetFrameRGBA32::operator << (const vetFrameRGB24& img)
00336 {
00337 INFO("void vetFrameRGBA32::operator << (const vetFrameRGB24& img) [importing data]")
00338
00339 if ( img.width == 0 || img.height == 0 )
00340 throw "Cannot do that with empty image (no size)";
00341
00342 if (width != img.width || height != img.height)
00343 reAllocCanvas(img.width, img.height);
00344
00345 memset(data + width * height * 3, '\0', width * height );
00346
00347 unsigned char* R = data;
00348 unsigned char* G = data + width*height;
00349 unsigned char* B = data + width*height*2;
00350
00351 for (unsigned int i=0; i< width*height; i++)
00352 {
00353 *(R++) = img.data[i][0];
00354 *(G++) = img.data[i][1];
00355 *(B++) = img.data[i][2];
00356 }
00357
00358
00359
00360 }
00361
00362 void vetFrameRGBA32::operator << (const vetFrameRGB96& img)
00363 {
00364 INFO("void vetFrameRGBA32::operator << (const vetFrameRGB96& img) [importing data]")
00365
00366 if ( img.width == 0 || img.height == 0 )
00367 throw "Cannot do that with empty image (no size)";
00368
00369 if (width != img.width || height != img.height)
00370 reAllocCanvas(img.width, img.height);
00371
00372 memset(data + width * height * 3, '\0', width * height );
00373
00374 unsigned char* R = data;
00375 unsigned char* G = data + width*height;
00376 unsigned char* B = data + width*height*2;
00377
00378 for (unsigned int i=0; i< width*height; i++)
00379 {
00380 *(R++) = (unsigned char)img.data[i][0];
00381 *(G++) = (unsigned char)img.data[i][1];
00382 *(B++) = (unsigned char)img.data[i][2];
00383 }
00384
00385
00386
00387 }
00388
00389
00390
00391
00392
00393
00394