00001
00002
00003
00004 #ifndef _XVAFFINEWARP_ICC_
00005 #define _XVAFFINEWARP_ICC_
00006
00007 template <class T>
00008 inline XVImageBase<T> & cropAroundPoly(const XVImageBase<T> & im, XVImageBase<T> & croppedIM,
00009 const int * cornersX, const int * cornersY,
00010 const int numOfCorners){
00011
00012 int minX, minXind, minY, minYind, maxX, maxXind, maxY, maxYind;
00013 min(cornersX, numOfCorners, minX, minXind);
00014 min(cornersY, numOfCorners, minY, minYind);
00015 max(cornersX, numOfCorners, maxX, maxXind);
00016 max(cornersY, numOfCorners, maxY, maxYind);
00017
00018 if(minX < 0) minX = 0;
00019 else if(minX > im.Width()) minX = im.Width() - 1;
00020 if(minY < 0) minY = 0;
00021 else if(minY > im.Height()) minY = im.Height() - 1;
00022 if(maxX < 0) maxX = 0;
00023 else if(maxX > im.Width()) maxX = im.Width() - 1;
00024 if(minY < 0) maxY = 0;
00025 else if(maxY > im.Height()) maxY = im.Height() - 1;
00026
00027 int w = maxX - minX;
00028 int h = maxY - minY;
00029
00030 croppedIM = subimage(im, minX, minY, w, h);
00031 return croppedIM;
00032 };
00033
00034 template <class T>
00035 inline T warpRect(T & im,
00036 const XVPosition & center,
00037 const XVSize & size,
00038 float angle) {
00039
00040 XVAffineWarp<typename T::PIXELTYPE> transform(-angle);
00041 T warpedIM(size.Width(), size.Height());
00042
00043 transform.warp(im, warpedIM, (XVCoord2D)center);
00044
00045 return warpedIM;
00046 };
00047
00048 template <class T>
00049 inline T warpRect(T & im,
00050 const XVPosition & center,
00051 const XVSize & size,
00052 float sheer, float d1, float d2) {
00053
00054
00055 XVAffineWarp<typename T::PIXELTYPE> transform(sheer, d1, d2);
00056 T warpedIM(size.Width(), size.Height());
00057
00058 transform.warp(im, warpedIM, (XVCoord2D)center);
00059
00060 return warpedIM;
00061 };
00062
00063 template <class T>
00064 inline T warpRect(T & im,
00065 const XVPosition & center,
00066 const XVSize & size,
00067 float sx, float sy) {
00068
00069
00070 XVAffineWarp<typename T::PIXELTYPE> transform(sx, sy);
00071 T warpedIM(size.Width(), size.Height());
00072
00073 transform.warp(im, warpedIM, (XVCoord2D)center);
00074
00075 return warpedIM;
00076 };
00077
00078 template <class T>
00079 inline T warpRect(T & im,
00080 const XVPosition & center,
00081 const XVSize & size,
00082 float theta, float sx, float sy, float sh){
00083
00084
00085 XVAffineWarp<typename T::PIXELTYPE> transform(theta, sx, sy, sh);
00086 T warpedIM(size.Width(), size.Height());
00087
00088 transform.warp(im, warpedIM, (XVCoord2D)center);
00089
00090 return warpedIM;
00091 };
00092
00093 #endif