00001
00029 #ifndef __VETLIB_VETFILTERGEOMETRIC_H__
00030 #define __VETLIB_VETFILTERGEOMETRIC_H__
00031
00032 #include "../vetDefs.h"
00033 #include "../vetFilter.h"
00034
00035 #include "../vetFrameYUV420.h"
00036 #include "../vetFrameRGB24.h"
00037 #include "../vetFrameT.h"
00038
00039
00040
00041 class vetFilterGeometricParameters : public vetFilterParameters
00042 {
00043 public:
00044
00045 enum RUNMODE{ DO_NOTHING, ROTATE90, ROTATE180, ROTATE270, ROTATE, FLIP_VERTICAL, FLIP_HORIZONTAL, RESIZE, RESIZECANVAS };
00046
00047 protected:
00048
00049 RUNMODE runMode;
00050
00051 float par_Rotation;
00052 unsigned int par_ResizeWidth;
00053 unsigned int par_ResizeHeight;
00054 bool par_forzeSize;
00055
00056 friend class vetFilterGeometric;
00057
00058 public:
00059
00060 vetFilterGeometricParameters(RUNMODE mode = vetFilterGeometricParameters::DO_NOTHING);
00061 ~vetFilterGeometricParameters() {}
00062
00063 void reset();
00064
00065 void setRunMode(RUNMODE mode) { runMode = mode; };
00066 RUNMODE getRunMode() { return runMode; };
00067
00068 void setRotationDegree(float degree) { par_Rotation = degree; };
00069 void setResizeDimension(unsigned int width, unsigned int height) { par_ResizeWidth = width; par_ResizeHeight = height; };
00070
00071 float getRotationDegree() { return par_Rotation; };
00072 unsigned int getResizeDimensionWidth() { return par_ResizeWidth; };
00073 unsigned int getResizeDimensionHeight() { return par_ResizeHeight; };
00074
00075 void forceOutputSize(bool value = true) { par_forzeSize = value; };
00076 bool isForceOutputSizeEnabled() { return par_forzeSize; };
00077
00078
00079 VETRESULT saveToStreamXML(FILE *fp);
00080 VETRESULT loadFromStreamXML(FILE *fp);
00081
00082 };
00083
00084
00085
00086 class vetFilterGeometric : public vetFilter
00087 {
00088
00089 protected:
00090
00094 vetFilterGeometricParameters* myParams;
00095
00096
00097
00098 public:
00099
00104 vetFilterGeometric(vetFilterGeometricParameters* initParams = NULL );
00105
00109 ~vetFilterGeometric();
00110
00111 float getFrameRate() const { return 0; };
00112
00113
00114
00115
00125 VETRESULT setParameters(vetFilterGeometricParameters* initParams);
00126
00132 vetFilterGeometricParameters& getParameters() { return *myParams; };
00133
00134
00135
00145 VETRESULT setFilterParameters (vetFilterParameters* initParams)
00146 {
00147 if (initParams == NULL)
00148 return setParameters(NULL);
00149 else
00150 return setParameters(static_cast<vetFilterGeometricParameters*>(initParams));
00151 };
00152
00153
00154
00160 vetFilterParameters* getFilterParameters ()
00161 {
00162 if (myParams == NULL)
00163 return NULL;
00164 else
00165 return static_cast<vetFilterParameters*>(myParams);
00166 };
00167
00168
00174 VETRESULT reset();
00175
00176
00177
00188 VETRESULT resize(vetFrameYUV420& img, unsigned int dimX , unsigned int dimY);
00189 VETRESULT resize(vetFrameRGB24& img, unsigned int dimX , unsigned int dimY);
00190 VETRESULT resize(vetFrameT<unsigned char>& img, unsigned int dimX , unsigned int dimY);
00191
00192
00204 VETRESULT resizeCanvas(vetFrameYUV420& img, unsigned int newdimX, unsigned int newdimY);
00205 VETRESULT resizeCanvas(vetFrameRGB24& img, unsigned int newdimX, unsigned int newdimY);
00206 VETRESULT resizeCanvas(vetFrameT<unsigned char>& img, unsigned int newdimX, unsigned int newdimY);
00207
00220 VETRESULT resizeCanvas(vetFrameYUV420& img, unsigned int newdimX , unsigned int newdimY, unsigned char& valY, unsigned char& valU, unsigned char& valV);
00221 VETRESULT resizeCanvas(vetFrameRGB24& img, unsigned int newdimX , unsigned int newdimY, PixelRGB24 defaultColor);
00222 VETRESULT resizeCanvas(vetFrameT<unsigned char>& img, unsigned int newdimX , unsigned int newdimY, unsigned char& val1, unsigned char& val2, unsigned char& val3);
00223
00224
00230 VETRESULT rotate90(vetFrameYUV420& img);
00231 VETRESULT rotate90(vetFrameRGB24& img);
00232 VETRESULT rotate90(vetFrameT<unsigned char>& img);
00233
00234
00240 VETRESULT rotate180(vetFrameYUV420& img);
00241 VETRESULT rotate180(vetFrameRGB24& img);
00242 VETRESULT rotate180(vetFrameT<unsigned char>& img);
00243
00244
00250 VETRESULT rotate270(vetFrameYUV420& img);
00251 VETRESULT rotate270(vetFrameRGB24& img);
00252 VETRESULT rotate270(vetFrameT<unsigned char>& img);
00253
00254
00262 VETRESULT rotate(vetFrameYUV420& img, float alpha);
00263 VETRESULT rotate(vetFrameRGB24& img, float alpha);
00264 VETRESULT rotate(vetFrameT<unsigned char>& img, float alpha);
00265
00266
00272 VETRESULT flipHorizontal(vetFrameYUV420& img);
00273 VETRESULT flipHorizontal(vetFrameRGB24& img);
00274 VETRESULT flipHorizontal(vetFrameT<unsigned char>& img);
00275
00276
00282 VETRESULT flipVertical(vetFrameYUV420& img);
00283 VETRESULT flipVertical(vetFrameRGB24& img);
00284 VETRESULT flipVertical(vetFrameT<unsigned char>& img);
00285
00286
00287
00298 VETRESULT importFrom(vetFrameYUV420& img);
00299
00310 VETRESULT importFrom(vetFrameRGB24& img);
00311
00322 VETRESULT importFrom(vetFrameT<unsigned char>& img);
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00354
00355 template <class T>
00356 static VETRESULT rotate90(vetFrameT<T> *src, vetFrameT<T> *dst, bool clockDir)
00357 {
00358 int xd,yd,x,y;
00359
00360 if (dir)
00361 xd = 0;
00362 else
00363 xd = dst.width - 1;
00364
00365 for(y = 0 ; y < src.height ; y++)
00366 {
00367 if (dir)
00368 yd = dst.height - 1;
00369 else
00370 yd = 0;
00371
00372 for(x = 0 ; x < src.width ; x++)
00373 {
00374 dst.data[yd * dst.width + xd] = src.data[y * src.width + x];
00375
00376 if (dir)
00377 yd--;
00378 else
00379 yd++;
00380 }
00381
00382 if (dir)
00383 xd++;
00384 else
00385 xd--;
00386 }
00387
00388 return VETRET_OK;
00389 }
00390
00391
00392 template <class T>
00393 static VETRESULT rotate180(vetFrameT<T> *src, vetFrameT<T> *dst)
00394 {
00395 for (unsigned int i=0; i < src.width*src.height; i++)
00396 dst.data[i] = src.data[src.width*src.height-1-i];
00397
00398 return VETRET_OK;
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417 }
00418
00419 template <class T>
00420 static VETRESULT mirror(vetFrameT<T> *src, vetFrameT<T> *dst)
00421 {
00422 unsigned int width = src.width;
00423
00424 for ( unsigned int y=0; y < src.height; y++ )
00425 for ( unsigned int x=0; x < width; x++ )
00426 dst->data[x+y*width] = img.data[y*width + (width-1)-x];
00427
00428 return VETRET_OK;
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443 }
00444
00445 template <class T>
00446 static VETRESULT flip(vetFrameT<T> *src, vetFrameT<T> *dst)
00447 {
00448 int yd,y;
00449
00450 yd = dst.height - 1;
00451
00452 for(y = 0 ; y < src.height ; y++)
00453 {
00454 memcpy(dst.data+yd*dst.width,src.data+y*src.width,src.width * sizeof(T));
00455 yd--;
00456 }
00457 return VETRET_OK;
00458 }
00459
00461
00462
00463
00464
00465 };
00466
00467
00468 #endif //__VETLIB_VETFILTERGEOMETRIC_H__
00469