00001
00029
00030
00031
00032
00033
00034 #ifndef __VETLIB_VETFRAMETH__
00035 #define __VETLIB_VETFRAMETH__
00036
00037 #define _VETFRAMET_SLOWMODE
00038
00039 #include "vetDefs.h"
00040
00041 #include "vetFrame.h"
00042
00043
00044 template<class T>
00045 class vetFrameT : public virtual vetFrame
00046 {
00047
00048 public:
00049
00053 unsigned int width;
00054
00058 unsigned int height;
00059
00060 bool autoFreeData;
00061
00062 VETFRAME_PROFILE profile;
00063
00064 VETFRAME_CHANNEL_TYPE dataType;
00065
00069 T *data;
00070
00071
00072 public:
00073
00077 vetFrameT()
00078 {
00079 height = 0;
00080 width = 0;
00081 data = NULL;
00082 autoFreeData = true;
00083 dataType = vetFrame::VETFRAME_CT_NONE;
00084 profile = vetFrame::VETFRAME_NONE;
00085 }
00086
00087
00088 vetFrameT(unsigned int w, unsigned int h)
00089 {
00090 data = NULL;
00091 autoFreeData = true;
00092 dataType = vetFrame::VETFRAME_CT_PACKED;
00093 profile = vetFrame::VETFRAME_MONO;
00094
00095 reAllocCanvas(w, h);
00096 }
00097
00103 vetFrameT(unsigned int w, unsigned int h, vetFrame::VETFRAME_PROFILE prof, vetFrame::VETFRAME_CHANNEL_TYPE dataTy = vetFrame::VETFRAME_CT_PLANAR)
00104 {
00105 data = NULL;
00106 autoFreeData = true;
00107 dataType = dataTy;
00108 profile = prof;
00109
00110 reAllocCanvas(w, h);
00111 }
00112
00117 vetFrameT(vetFrameT& img)
00118 {
00119 data = NULL;
00120 dataType = img.dataType;
00121 profile = img.profile;
00122 autoFreeData = img.autoFreeData;
00123
00124 reAllocCanvas(img.width, img.height);
00125 memcpy(static_cast<char*>(data), static_cast<char*>(img.data), getBufferSize() );
00126 }
00127
00131 ~vetFrameT()
00132 {
00133 if ( autoFreeData && data != NULL )
00134 delete [] data;
00135 }
00136
00137
00138 bool isBuiltInSupportedProfile(VETFRAME_PROFILE pr)
00139 {
00140 switch( profile )
00141 {
00142 case vetFrame::VETFRAME_MONO:
00143 case vetFrame::VETFRAME_RGB24:
00144 case vetFrame::VETFRAME_BGR24:
00145 case vetFrame::VETFRAME_RGB32:
00146 case vetFrame::VETFRAME_BGR32:
00147 return true;
00148
00149 case vetFrame::VETFRAME_ARGB32:
00150 case vetFrame::VETFRAME_ABGR32:
00151 case vetFrame::VETFRAME_RGBA32:
00152 case vetFrame::VETFRAME_BGRA32:
00153
00154 default:
00155 return false;
00156
00157 }
00158 }
00159
00165 unsigned int getWidth() const { return width; };
00166 unsigned int getWidth() { return width; };
00167
00173 unsigned int getHeight() const { return height; };
00174 unsigned int getHeight() { return height; };
00175
00176
00177 void* dump_buffer() { return static_cast<void*>(data); };
00178
00179 VETRESULT reAllocCanvas(unsigned int w, unsigned int h)
00180 {
00181 width = w;
00182 height = h;
00183
00184 if ( width == 0 || height == 0 )
00185 return VETRET_PARAM_ERR;
00186
00187 if ( data != NULL )
00188 delete [] data;
00189 data = NULL;
00190
00191 int multiplier = 1;
00192 switch( profile )
00193 {
00194 case vetFrame::VETFRAME_MONO:
00195 multiplier = 1; break;
00196
00197 case vetFrame::VETFRAME_RGB24:
00198 case vetFrame::VETFRAME_BGR24:
00199 case vetFrame::VETFRAME_RGB96:
00200 case vetFrame::VETFRAME_BGR32:
00201 multiplier = 3; break;
00202
00203 case vetFrame::VETFRAME_ARGB32:
00204 case vetFrame::VETFRAME_ABGR32:
00205 case vetFrame::VETFRAME_RGBA32:
00206 case vetFrame::VETFRAME_BGRA32:
00207 multiplier = 4; break;
00208
00209 default:
00210 break;
00211 }
00212
00213 data = new T[ (unsigned int)(width * height * multiplier) ];
00214
00215 return VETRET_OK;
00216
00217 }
00218
00219 VETRESULT extractBrightness(unsigned char* buffer, unsigned int* size = NULL )
00220 {
00221 return 666;
00222 }
00223
00224 unsigned int getBpp()
00225 {
00226 switch( profile )
00227 {
00228 case vetFrame::VETFRAME_RGB24:
00229 case vetFrame::VETFRAME_BGR24: return 24;
00230 case vetFrame::VETFRAME_RGB96:
00231 case vetFrame::VETFRAME_BGR96: return 96;
00232
00233 case vetFrame::VETFRAME_ARGB32:
00234 case vetFrame::VETFRAME_ABGR32:
00235 case vetFrame::VETFRAME_RGBA32:
00236 case vetFrame::VETFRAME_BGRA32: return 32;
00237
00238
00239 case vetFrame::VETFRAME_MONO: return sizeof(T) * 8;
00240 default: return 0;
00241
00242 }
00243 }
00244
00245 unsigned int getBufferSize()
00246 {
00247 switch( profile )
00248 {
00249 case vetFrame::VETFRAME_MONO: return width * height * sizeof(T);
00250 case vetFrame::VETFRAME_RGB24:
00251 case vetFrame::VETFRAME_BGR24: return width * height * 3 * sizeof(T);
00252 case vetFrame::VETFRAME_RGB96:
00253 case vetFrame::VETFRAME_BGR96: return width * height * 3 * sizeof(T);
00254
00255 case vetFrame::VETFRAME_ARGB32:
00256 case vetFrame::VETFRAME_ABGR32:
00257 case vetFrame::VETFRAME_RGBA32:
00258 case vetFrame::VETFRAME_BGRA32: return width * height * 4 * sizeof(T);
00259
00260
00261 default: return 0;
00262
00263 }
00264 }
00265
00266
00267 VETRESULT setBlack()
00268 {
00269 switch( profile )
00270 {
00271 case vetFrame::VETFRAME_MONO:
00272 case vetFrame::VETFRAME_RGB24:
00273 case vetFrame::VETFRAME_BGR24:
00274 case vetFrame::VETFRAME_RGB96:
00275 case vetFrame::VETFRAME_BGR96:
00276 case vetFrame::VETFRAME_ARGB32:
00277 case vetFrame::VETFRAME_ABGR32:
00278 case vetFrame::VETFRAME_RGBA32:
00279 case vetFrame::VETFRAME_BGRA32:
00280 {
00281 memset(data, '\0', getBufferSize() );
00282 return VETRET_OK;
00283 }
00284
00285 default:
00286 return VETRET_NOT_IMPLEMENTED;
00287
00288 }
00289 }
00290
00291 VETRESULT setWhite()
00292 {
00293 switch( profile )
00294 {
00295 case vetFrame::VETFRAME_MONO:
00296 case vetFrame::VETFRAME_RGB24:
00297 case vetFrame::VETFRAME_BGR24:
00298 case vetFrame::VETFRAME_RGB96:
00299 case vetFrame::VETFRAME_BGR96:
00300 {
00301 memset(data, 255, getBufferSize() );
00302 return VETRET_OK;
00303 }
00304
00305 case vetFrame::VETFRAME_ARGB32:
00306 case vetFrame::VETFRAME_ABGR32:
00307 {
00308 memset(data, '\0', width*height );
00309 return VETRET_OK;
00310 }
00311
00312 case vetFrame::VETFRAME_RGBA32:
00313 case vetFrame::VETFRAME_BGRA32:
00314 {
00315 memset(data+width*height*3, '\0', width*height );
00316 return VETRET_OK;
00317 }
00318
00319 default:
00320 return VETRET_NOT_IMPLEMENTED;
00321
00322 }
00323 }
00324
00325
00335 VETRESULT setPixel(unsigned int x, unsigned int y, T p)
00336 {
00337 #ifdef _VETFRAMECACHE_SLOWMODE
00338 if ( x >= width || y >= height )
00339 return VETRET_PARAM_ERR;
00340
00341 #endif //_VETFRAMECACHE_SLOWMODE
00342
00343
00344
00345
00346 return VETRET_NOT_IMPLEMENTED;
00347
00348
00349
00350 return VETRET_OK;
00351 }
00352
00353
00363 VETRESULT getPixel(unsigned int x, unsigned int y, T& p)
00364 {
00365 #ifdef _VETFRAMECACHE_SLOWMODE
00366 if ( x >= width || y >= height )
00367 return VETRET_PARAM_ERR;
00368
00369 #endif //_VETFRAMECACHE_SLOWMODE
00370
00371
00372
00373
00374 return VETRET_NOT_IMPLEMENTED;
00375
00376
00377 return VETRET_OK;
00378 }
00379
00380
00389 vetFrameT& operator = (vetFrameT& img)
00390 {
00391
00392 if (this == &img)
00393 throw "Source and Destination are same Image";
00394
00395
00396 if ( width != img.width || height != img.height || profile != img.profile )
00397 {
00398 profile = img.profile;
00399 dataType = img.dataType;
00400 reAllocCanvas(img.width, img.height);
00401 }
00402
00403 if ( width == 0 || height == 0 )
00404 throw "Cannot do that with empty image (no size)";
00405
00406 memcpy(static_cast<void*>(data), static_cast<void*>(img.data), getBufferSize() );
00407
00408 return *this;
00409 }
00410
00419 vetFrameT& operator += (vetFrameT& img)
00420 {
00421 INFO("vetFrameCache& vetFrameCache::operator += (vetFrameCache& img)")
00422
00423 if (width != img.width || height != img.height)
00424 throw "Difference in vetFrameCache Dimensions";
00425 if ( dataType != img.dataType || profile != img.profile )
00426 throw "Difference in vetFrameT data structure";
00427
00428
00429
00430
00431
00432 return *this;
00433 }
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444 VETFRAME_PROFILE getProfile() { return profile; };
00445
00446 VETFRAME_CHANNEL_TYPE getChannelType() { return dataType; };
00447
00448
00449 int getFOURCC()
00450 {
00451 switch( profile )
00452 {
00453 case vetFrame::VETFRAME_MONO:
00454 case vetFrame::VETFRAME_RGB24:
00455 case vetFrame::VETFRAME_BGR24:
00456 case vetFrame::VETFRAME_RGB32:
00457 case vetFrame::VETFRAME_BGR32:
00458 return 0x32424752;
00459
00460 case vetFrame::VETFRAME_ARGB32:
00461 case vetFrame::VETFRAME_ABGR32:
00462 return 0x41424752;
00463
00464 case vetFrame::VETFRAME_RGBA32:
00465 case vetFrame::VETFRAME_BGRA32:
00466
00467 default:
00468 return 0;
00469
00470 }
00471
00472 };
00473
00474 };
00475
00476
00477
00478 #endif //__VETLIB_VETFRAMETH__
00479