00001
00018 #include "vetFrameRGB24.h"
00019
00020 vetFrameRGB24::vetFrameRGB24() : vetFrame()
00021 {
00022 height = 0;
00023 width = 0;
00024 data = NULL;
00025 autoFreeData = true;
00026 }
00027
00033 vetFrameRGB24::vetFrameRGB24(unsigned int w, unsigned int h)
00034 {
00035 data = NULL;
00036 reAllocCanvas(w, h);
00037 autoFreeData = true;
00038 }
00039
00040
00044 vetFrameRGB24::vetFrameRGB24(vetFrameRGB24& img)
00045 {
00046 data = NULL;
00047 reAllocCanvas(img.width, img.height);
00048
00049 *this = img;
00050
00051 autoFreeData = true;
00052 }
00053
00058 vetFrameRGB24::vetFrameRGB24(vetFrameRGB96& img)
00059 {
00060 data = NULL;
00061 reAllocCanvas(img.width, img.height);
00062
00063 *this << img;
00064
00065 autoFreeData = true;
00066 }
00071 vetFrameRGB24::vetFrameRGB24(vetFrameRGBA32& img)
00072 {
00073 data = NULL;
00074 reAllocCanvas(img.width, img.height);
00075
00076 *this << img;
00077
00078 autoFreeData = true;
00079 }
00080
00081
00085 vetFrameRGB24::~vetFrameRGB24()
00086 {
00087 if ( autoFreeData && data != NULL )
00088 delete [] data;
00089 }
00090
00091
00092 VETRESULT vetFrameRGB24::reAllocCanvas(unsigned int w, unsigned int h)
00093 {
00094 if (data != NULL)
00095 delete [] data;
00096
00097 height = h;
00098 width = w;
00099 data = NULL;
00100
00101 if ( width == 0 || height == 0)
00102 return VETRET_PARAM_ERR;
00103
00104 data = new PixelRGB24[width * height];
00105
00106 return VETRET_OK;
00107 }
00108
00109 VETRESULT vetFrameRGB24::setBlack()
00110 {
00111 if (width == 0 || height == 0 || data == NULL)
00112 return VETRET_ILLEGAL_USE;
00113
00114 memset(data, '\0', width * height * sizeof(PixelRGB24) );
00115
00116 return VETRET_OK;
00117 }
00118
00119 VETRESULT vetFrameRGB24::setWhite()
00120 {
00121 if (width == 0 || height == 0 || data == NULL)
00122 return VETRET_ILLEGAL_USE;
00123
00124 memset(data, 255, width * height * sizeof(PixelRGB24) );
00125
00126 return VETRET_OK;
00127 }
00128
00129 VETRESULT vetFrameRGB24::extractBrightness(unsigned char* buffer, unsigned int* size)
00130 {
00131 if (width == 0 || height == 0 || data == NULL)
00132 return VETRET_ILLEGAL_USE;
00133
00134 if (buffer == NULL)
00135 {
00136 if ( size == NULL)
00137 return VETRET_PARAM_ERR;
00138
00139 *size = width*height;
00140 return VETRET_OK;
00141 }
00142
00143 return VETRET_NOT_IMPLEMENTED;
00144 }
00145
00146
00156 VETRESULT vetFrameRGB24::getPixel(unsigned int x, unsigned int y, PixelRGB24& p)
00157 {
00158 #ifdef _vetFrameRGB24_SLOWMODE
00159 if ( x >= width || y >= height )
00160 throw "Invalid Coordinates in method vetFrameRGB24::getPixel(unsigned int x, unsigned int y, PixelRGB& p)";
00161 #endif //_vetFrameRGB24_SLOWMODE
00162
00163 unsigned int offset = y * width + x;
00164
00165 p[RED] = data[offset][RED];
00166 p[GREEN]= data[offset][GREEN];
00167 p[BLUE] = data[offset][BLUE];
00168
00169 return VETRET_OK;
00170 }
00171
00181 VETRESULT vetFrameRGB24::setPixel(unsigned int x, unsigned int y, PixelRGB24 p)
00182 {
00183 #ifdef _vetFrameRGB24_SLOWMODE
00184 if ( x >= width || y >= height )
00185 throw "Invalid Coordinates in method vetFrameRGB24::setPixel(unsigned int x, unsigned int y, PixelRGB p)";
00186 #endif //_vetFrameRGB24_SLOWMODE
00187
00188 data[y * width + x] = p;
00189
00190 return VETRET_OK;
00191 }
00192
00193
00201 vetFrameRGB24& vetFrameRGB24::clearWith(PixelRGB24& p)
00202 {
00203 if ( data == NULL )
00204 throw "Image is empty.";
00205
00206 for ( unsigned int i=0; i < width * height; i++)
00207 data[i] = p;
00208
00209 return *this;
00210 }
00211
00220 vetFrameRGB24& vetFrameRGB24::operator = (vetFrameRGB24& img)
00221 {
00222
00223 if (this == &img)
00224 return *this;
00225
00226
00227 if (width != img.width || height != img.height)
00228 reAllocCanvas(img.width, img.height);
00229
00230 if ( width == 0 || height == 0 )
00231 throw "Cannot do that with empty image (no size)";
00232
00233
00234 memcpy(data, img.data, width * height * sizeof(PixelRGB24));
00235
00236 return *this;
00237 }
00238
00239
00240 vetFrameRGB24& vetFrameRGB24::operator += (vetFrameRGB24& img)
00241 {
00242 INFO("vetFrameRGB24& vetFrameRGB24::operator += (vetFrameRGB24& img)")
00243
00244 if (width != img.width || height != img.height)
00245 throw "Difference in vetFrameYUV420 Dimensions";
00246
00247 for(unsigned int i=0; i < width * height; i++)
00248 data[i] += img.data[i];
00249
00250 return *this;
00251 }
00252
00253
00254
00255 vetFrameRGB24& vetFrameRGB24::operator -= (vetFrameRGB24& img)
00256 {
00257 INFO("vetFrameRGB24& vetFrameRGB24::operator += (vetFrameRGB24& img)")
00258
00259 if (width != img.width || height != img.height)
00260 throw "Difference in vetFrameYUV420 Dimensions";
00261
00262 for(unsigned int i=0; i < width * height; i++)
00263 data[i] -= img.data[i];
00264
00265 return *this;
00266 }
00267
00268
00269
00270
00271
00272
00273 vetFrameRGB24& vetFrameRGB24::operator >> (vetFrameYUV420& img)
00274 {
00275 INFO("vetFrameRGB24& vetFrameRGB24::operator >> (vetFrameYUV420& img) [pushing data]")
00276
00277 if ( width == 0 || height == 0 )
00278 throw "Cannot do that with empty image (no size)";
00279
00280 if ( width != img.width || height != img.height )
00281 img.reAllocCanvas(width, height);
00282
00283
00284
00285 return *this;
00286 }
00287
00288 vetFrameRGB24& vetFrameRGB24::operator >> (vetFrameRGB96& img)
00289 {
00290 INFO("vetFrameRGB24& vetFrameRGB24::operator >> (vetFrameRGB96& img) [pushing data]")
00291
00292 if ( width == 0 || height == 0 )
00293 throw "Cannot do that with empty image (no size)";
00294
00295 if ( width != img.width || height != img.height )
00296 img.reAllocCanvas(width, height);
00297
00298 unsigned char* dataPtr = static_cast<unsigned char*>( data[0] );
00299 int* destPtr = static_cast<int*>( img.data[0] );
00300
00301 for(unsigned int i=0; i < width * height * 3; i++)
00302 *(destPtr++) = (int) (*dataPtr++);
00303
00304 return *this;
00305 }
00306
00307 vetFrameRGB24& vetFrameRGB24::operator >> (vetFrameRGBA32& img)
00308 {
00309 INFO("vetFrameRGB24& vetFrameRGB24::operator >> (vetFrameRGBA32& img) [pushing data]")
00310
00311 if ( width == 0 || height == 0 )
00312 throw "Cannot do that with empty image (no size)";
00313
00314 if ( width != img.width || height != img.height )
00315 img.reAllocCanvas(width, height);
00316
00317 memset(img.data + width * height * 3, '\0', width * height );
00318
00319 unsigned char* R = img.data;
00320 unsigned char* G = img.data + width*height;
00321 unsigned char* B = img.data + width*height*2;
00322
00323 for (unsigned int i=0; i< width*height; i++)
00324 {
00325 *(R++) = data[i][0];
00326 *(G++) = data[i][1];
00327 *(B++) = data[i][2];
00328 }
00329
00330
00331
00332 return *this;
00333 }
00334
00335
00336
00337
00338 void vetFrameRGB24::operator << (const vetFrameYUV420& img)
00339 {
00340 INFO("void vetFrameRGB24::operator << (const vetFrameYUV420& img) [importing data]")
00341
00342 if ( img.width == 0 || img.height == 0 )
00343 throw "Cannot do that with empty image (no size)";
00344
00345 if ( width != img.width || height != img.height )
00346 reAllocCanvas(img.width, img.height);
00347
00348
00349
00350 }
00351
00352
00353 void vetFrameRGB24::operator << (const vetFrameRGB96& img)
00354 {
00355 INFO("void vetFrameRGB24::operator << (const vetFrameRGB32& img) [importing data]")
00356
00357 if ( img.width == 0 || img.height == 0 )
00358 throw "Cannot do that with empty image (no size)";
00359
00360 if ( width != img.width || height != img.height )
00361 reAllocCanvas(img.width, img.height);
00362
00363 unsigned char* dataPtr = static_cast<unsigned char*>( data[0] );
00364 int* srcPtr = static_cast<int*>( img.data[0] );
00365
00366 for(unsigned int i=0; i < width * height * 3; i++)
00367 *(dataPtr++) = (unsigned char) (*srcPtr++);
00368
00369 }
00370
00371
00372 void vetFrameRGB24::operator << (const vetFrameRGBA32& img)
00373 {
00374 INFO("void vetFrameRGB24::operator << (const vetFrameRGBA32& img) [importing data]")
00375
00376 if ( img.width == 0 || img.height == 0 )
00377 throw "Cannot do that with empty image (no size)";
00378
00379 if ( width != img.width || height != img.height )
00380 reAllocCanvas(img.width, img.height);
00381
00382 unsigned char* R = img.data;
00383 unsigned char* G = img.data + width*height;
00384 unsigned char* B = img.data + width*height*2;
00385
00386 for (unsigned int i=0; i< width*height; i++)
00387 {
00388 data[i][0] = *(R++);
00389 data[i][1] = *(G++);
00390 data[i][2] = *(B++);
00391 }
00392
00393
00394 }
00395
00396
00397
00398
00399
00400
00401