00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #include <QDebug>
00026 #include <qvcore/qvimage.h>
00027
00028 template <> const char * QVImage<uChar,1>::getTypeQString() const { return "QVImage<uChar,1>"; }
00029 template <> const char * QVImage<uChar,3>::getTypeQString() const { return "QVImage<uChar,3>"; }
00030 template <> const char * QVImage<sShort,1>::getTypeQString() const { return "QVImage<sShort,1>"; }
00031 template <> const char * QVImage<sShort,3>::getTypeQString() const { return "QVImage<sShort,3>"; }
00032 template <> const char * QVImage<sFloat,1>::getTypeQString() const { return "QVImage<sFloat,1>"; }
00033 template <> const char * QVImage<sFloat,3>::getTypeQString() const { return "QVImage<sFloat,3>"; }
00034
00035
00036 #define CREATE_COPY_CONSTRUCTOR(TYPE, C) \
00037 template <> QVImage<TYPE, C>::QVImage(QVImage<TYPE, C> const &img):QVGenericImage(img) \
00038 { \
00039 imageBuffer = img.imageBuffer; \
00040 setROI(img.getROI()); setAnchor(img.getAnchor()); \
00041 }
00042
00043 CREATE_COPY_CONSTRUCTOR(uChar, 1);
00044 CREATE_COPY_CONSTRUCTOR(uChar, 3);
00045 CREATE_COPY_CONSTRUCTOR(sShort, 1);
00046 CREATE_COPY_CONSTRUCTOR(sShort, 3);
00047 CREATE_COPY_CONSTRUCTOR(sFloat, 1);
00048 CREATE_COPY_CONSTRUCTOR(sFloat, 3);
00049
00050
00051 #define CREATE_COPY_OPERATOR(TYPE, C) \
00052 template <> QVImage<TYPE,C> & QVImage<TYPE, C>::operator=(const QVImage<TYPE, C> &img) \
00053 { \
00054 imageBuffer = img.imageBuffer; \
00055 setROI(img.getROI()); setAnchor(img.getAnchor()); \
00056 return *this; \
00057 }
00058
00059 CREATE_COPY_OPERATOR(uChar, 1);
00060 CREATE_COPY_OPERATOR(uChar, 3);
00061 CREATE_COPY_OPERATOR(sShort, 1);
00062 CREATE_COPY_OPERATOR(sShort, 3);
00063 CREATE_COPY_OPERATOR(sFloat, 1);
00064 CREATE_COPY_OPERATOR(sFloat, 3);
00065
00067
00068 #include <qvipp/qvipp.h>
00069
00070
00071 #define CREATE_CONVERT_CONSTRUCTOR(TYPE1, C1, TYPE2, C2) \
00072 template <> QVImage<TYPE1, C1>::QVImage(QVImage<TYPE2, C2> const &img):QVGenericImage(img) \
00073 { \
00074 imageBuffer = new QVImageBuffer<TYPE1, C1>(img.getCols(), img.getRows()); \
00075 setAnchor(img.getROI().x(),img.getROI().y()); \
00076 Convert(img, *this); \
00077 setAnchor(img.getAnchor()); \
00078 }
00079
00080 CREATE_CONVERT_CONSTRUCTOR(uChar, 1, sShort, 1);
00081 CREATE_CONVERT_CONSTRUCTOR(uChar, 1, sFloat, 1);
00082 CREATE_CONVERT_CONSTRUCTOR(sShort, 1, uChar, 1);
00083 CREATE_CONVERT_CONSTRUCTOR(sShort, 1, sFloat, 1);
00084 CREATE_CONVERT_CONSTRUCTOR(sFloat, 1, uChar, 1);
00085 CREATE_CONVERT_CONSTRUCTOR(sFloat, 1, sShort, 1);
00086
00087 CREATE_CONVERT_CONSTRUCTOR(uChar, 3, sShort, 3);
00088 CREATE_CONVERT_CONSTRUCTOR(uChar, 3, sFloat, 3);
00089 CREATE_CONVERT_CONSTRUCTOR(sShort, 3, uChar, 3);
00090 CREATE_CONVERT_CONSTRUCTOR(sShort, 3, sFloat, 3);
00091 CREATE_CONVERT_CONSTRUCTOR(sFloat, 3, uChar, 3);
00092 CREATE_CONVERT_CONSTRUCTOR(sFloat, 3, sShort, 3);
00093
00094 #define CREATE_CONVERT_CONSTRUCTOR_C3_C1(TYPE) \
00095 template <> QVImage<TYPE, 1>::QVImage(QVImage<TYPE, 3> const &img):QVGenericImage(img) \
00096 { \
00097 imageBuffer = new QVImageBuffer<TYPE, 1>(img.getCols(), img.getRows()); \
00098 setAnchor(img.getROI().x(),img.getROI().y()); \
00099 RGBToGray(img, *this); \
00100 setAnchor(img.getAnchor()); \
00101 }
00102
00103 CREATE_CONVERT_CONSTRUCTOR_C3_C1(uChar);
00104 CREATE_CONVERT_CONSTRUCTOR_C3_C1(sShort);
00105 CREATE_CONVERT_CONSTRUCTOR_C3_C1(sFloat);
00106
00107 #define CREATE_CONVERT_CONSTRUCTOR_C1_C3(TYPE) \
00108 template <> QVImage<TYPE, 3>::QVImage(QVImage<TYPE, 1> const &img):QVGenericImage(img) \
00109 { \
00110 imageBuffer = new QVImageBuffer<TYPE, 3>(img.getCols(), img.getRows()); \
00111 setAnchor(img.getROI().x(),img.getROI().y()); \
00112 Copy(img, *this); \
00113 setAnchor(img.getAnchor()); \
00114 }
00115
00116 CREATE_CONVERT_CONSTRUCTOR_C1_C3(uChar);
00117 CREATE_CONVERT_CONSTRUCTOR_C1_C3(sShort);
00118 CREATE_CONVERT_CONSTRUCTOR_C1_C3(sFloat);
00119
00120
00121 #define CREATE_OPERATOR(NAME, OPERATOR, TYPE, C) \
00122 template <> QVImage<TYPE, C> QVImage<TYPE,C>::OPERATOR(const QVImage<TYPE, C> &img) const \
00123 { \
00124 QVImage<TYPE, C> result = *this; \
00125 NAME(*this, img, result); \
00126 return result; \
00127 }
00128
00129 CREATE_OPERATOR(Add, operator+, uChar, 1);
00130 CREATE_OPERATOR(Mul, operator*, uChar, 1);
00131 CREATE_OPERATOR(Sub, operator-, uChar, 1);
00132 CREATE_OPERATOR(Div, operator/, uChar, 1);
00133
00134 CREATE_OPERATOR(Add, operator+, uChar, 3);
00135 CREATE_OPERATOR(Mul, operator*, uChar, 3);
00136 CREATE_OPERATOR(Sub, operator-, uChar, 3);
00137 CREATE_OPERATOR(Div, operator/, uChar, 3);
00138
00139 CREATE_OPERATOR(Add, operator+, sShort, 1);
00140 CREATE_OPERATOR(Mul, operator*, sShort, 1);
00141 CREATE_OPERATOR(Sub, operator-, sShort, 1);
00142 CREATE_OPERATOR(Div, operator/, sShort, 1);
00143
00144 CREATE_OPERATOR(Add, operator+, sShort, 3);
00145 CREATE_OPERATOR(Mul, operator*, sShort, 3);
00146 CREATE_OPERATOR(Sub, operator-, sShort, 3);
00147 CREATE_OPERATOR(Div, operator/, sShort, 3);
00148
00149
00150 #define CREATE_CONST_OPERATOR(NAME, OPERATOR, TYPE, C) \
00151 template <> QVImage<TYPE, C> QVImage<TYPE,C>::OPERATOR(const TYPE value) const \
00152 { \
00153 QVImage<TYPE, C> result = *this; \
00154 NAME(*this, result, value); \
00155 return result; \
00156 }
00157
00158 CREATE_CONST_OPERATOR(AddC, operator+, uChar, 1);
00159 CREATE_CONST_OPERATOR(AddC, operator+, sShort, 1);
00160 CREATE_CONST_OPERATOR(AddC, operator+, sFloat, 1);
00161
00162 CREATE_CONST_OPERATOR(MulC, operator*, uChar, 1);
00163 CREATE_CONST_OPERATOR(MulC, operator*, sShort, 1);
00164 CREATE_CONST_OPERATOR(MulC, operator*, sFloat, 1);
00165
00166 CREATE_CONST_OPERATOR(SubC, operator-, uChar, 1);
00167 CREATE_CONST_OPERATOR(SubC, operator-, sShort, 1);
00168 CREATE_CONST_OPERATOR(SubC, operator-, sFloat, 1);
00169
00170 CREATE_CONST_OPERATOR(DivC, operator/, uChar, 1);
00171 CREATE_CONST_OPERATOR(DivC, operator/, sShort, 1);
00172 CREATE_CONST_OPERATOR(DivC, operator/, sFloat, 1);
00173
00174 CREATE_CONST_OPERATOR(LShiftC, operator<<, uChar, 1);
00175 CREATE_CONST_OPERATOR(RShiftC, operator>>, uChar, 1);
00176
00177 CREATE_CONST_OPERATOR(AndC, operator&, uChar, 1);
00178 CREATE_CONST_OPERATOR(OrC, operator|, uChar, 1);
00179 CREATE_CONST_OPERATOR(XorC, operator^, uChar, 1);
00180
00181 #define CREATE_NOT_OPERATOR(NAME, OPERATOR, TYPE, C) \
00182 template <> QVImage<TYPE, C> QVImage<TYPE,C>::OPERATOR() const \
00183 { \
00184 QVImage<TYPE, C> result = *this; \
00185 NAME(*this, result); \
00186 return result; \
00187 }
00188
00189 CREATE_NOT_OPERATOR(Not, operator!, uChar, 1);
00190 CREATE_NOT_OPERATOR(Not, operator!, uChar, 3);
00191
00192 #define CREATE_COMPARE_OPERATOR(NAME, OPERATOR, CMP, TYPE, C) \
00193 template <> QVImage<uChar> QVImage<TYPE,C>::OPERATOR(const QVImage<TYPE, C> &img) const \
00194 { \
00195 QVImage<uChar> result(getCols(), getRows()); \
00196 NAME(*this, img, result, CMP); \
00197 return result; \
00198 }
00199
00200
00201 CREATE_COMPARE_OPERATOR(Compare, operator<, ippCmpLess, uChar, 1);
00202 CREATE_COMPARE_OPERATOR(Compare, operator<, ippCmpLess, sShort, 1);
00203 CREATE_COMPARE_OPERATOR(Compare, operator<, ippCmpLess, sFloat, 1);
00204
00205 CREATE_COMPARE_OPERATOR(Compare, operator<, ippCmpLess, uChar, 3);
00206 CREATE_COMPARE_OPERATOR(Compare, operator<, ippCmpLess, sShort, 3);
00207 CREATE_COMPARE_OPERATOR(Compare, operator<, ippCmpLess, sFloat, 3);
00208
00209
00210 CREATE_COMPARE_OPERATOR(Compare, operator>, ippCmpGreater, uChar, 1);
00211 CREATE_COMPARE_OPERATOR(Compare, operator>, ippCmpGreater, sShort, 1);
00212 CREATE_COMPARE_OPERATOR(Compare, operator>, ippCmpGreater, sFloat, 1);
00213
00214 CREATE_COMPARE_OPERATOR(Compare, operator>, ippCmpGreater, uChar, 3);
00215 CREATE_COMPARE_OPERATOR(Compare, operator>, ippCmpGreater, sShort, 3);
00216 CREATE_COMPARE_OPERATOR(Compare, operator>, ippCmpGreater, sFloat, 3);
00217
00218
00219 CREATE_COMPARE_OPERATOR(Compare, operator<=, ippCmpLessEq, uChar, 1);
00220 CREATE_COMPARE_OPERATOR(Compare, operator<=, ippCmpLessEq, sShort, 1);
00221 CREATE_COMPARE_OPERATOR(Compare, operator<=, ippCmpLessEq, sFloat, 1);
00222
00223 CREATE_COMPARE_OPERATOR(Compare, operator<=, ippCmpLessEq, uChar, 3);
00224 CREATE_COMPARE_OPERATOR(Compare, operator<=, ippCmpLessEq, sShort, 3);
00225 CREATE_COMPARE_OPERATOR(Compare, operator<=, ippCmpLessEq, sFloat, 3);
00226
00227
00228 CREATE_COMPARE_OPERATOR(Compare, operator>=, ippCmpGreaterEq, uChar, 1);
00229 CREATE_COMPARE_OPERATOR(Compare, operator>=, ippCmpGreaterEq, sShort, 1);
00230 CREATE_COMPARE_OPERATOR(Compare, operator>=, ippCmpGreaterEq, sFloat, 1);
00231
00232 CREATE_COMPARE_OPERATOR(Compare, operator>=, ippCmpGreaterEq, uChar, 3);
00233 CREATE_COMPARE_OPERATOR(Compare, operator>=, ippCmpGreaterEq, sShort, 3);
00234 CREATE_COMPARE_OPERATOR(Compare, operator>=, ippCmpGreaterEq, sFloat, 3);
00235
00236
00237
00238 #define CREATE_SET_FUNCTION_C1(TYPE) \
00239 template <> void QVImage<TYPE>::set(TYPE c1, TYPE, TYPE) \
00240 { Set(*this, c1); }
00241
00242 CREATE_SET_FUNCTION_C1(uChar);
00243 CREATE_SET_FUNCTION_C1(sShort);
00244 CREATE_SET_FUNCTION_C1(sFloat);
00245
00246 #define CREATE_SET_FUNCTION_C3(TYPE) \
00247 template <> void QVImage<TYPE,3>::set(TYPE c1, TYPE c2, TYPE c3) \
00248 { Set(*this, c1, c2, c3); }
00249
00250 CREATE_SET_FUNCTION_C3(uChar);
00251 CREATE_SET_FUNCTION_C3(sShort);
00252 CREATE_SET_FUNCTION_C3(sFloat);
00253
00254
00256
00257 #define CREATE_CONVERT_OPERATOR(TYPE1, TYPE2, C) \
00258 template <> QVImage<TYPE1, C> & QVImage<TYPE1, C>::operator=(const QVImage<TYPE2, C> &img) \
00259 { \
00260 imageBuffer = new QVImageBuffer<TYPE1, C>(img.getCols(), img.getRows()); \
00261 setAnchor(img.getROI().x(),img.getROI().y()); \
00262 Convert(img, *this); \
00263 setAnchor(img.getAnchor()); \
00264 return *this; \
00265 }
00266
00267 CREATE_CONVERT_OPERATOR(uChar, sFloat, 1);
00268 CREATE_CONVERT_OPERATOR(uChar, sShort, 1);
00269 CREATE_CONVERT_OPERATOR(sShort, uChar, 1);
00270 CREATE_CONVERT_OPERATOR(sShort, sFloat, 1);
00271 CREATE_CONVERT_OPERATOR(sFloat, uChar, 1);
00272 CREATE_CONVERT_OPERATOR(sFloat, sShort, 1);
00273
00274 CREATE_CONVERT_OPERATOR(uChar, sFloat, 3);
00275 CREATE_CONVERT_OPERATOR(uChar, sShort, 3);
00276 CREATE_CONVERT_OPERATOR(sShort, uChar, 3);
00277 CREATE_CONVERT_OPERATOR(sShort, sFloat, 3);
00278 CREATE_CONVERT_OPERATOR(sFloat, uChar, 3);
00279 CREATE_CONVERT_OPERATOR(sFloat, sShort, 3);
00280
00281 #define CREATE_CONVERT_OPERATOR_C3_C1(TYPE1, C1, TYPE2, C2) \
00282 template <> QVImage<TYPE1, C1> & QVImage<TYPE1, C1>::operator=(const QVImage<TYPE2, C2> &img) \
00283 { \
00284 imageBuffer = new QVImageBuffer<TYPE1, C1>(img.getCols(), img.getRows()); \
00285 setAnchor(img.getROI().x(),img.getROI().y()); \
00286 RGBToGray(img, *this); \
00287 setAnchor(img.getAnchor()); \
00288 return *this; \
00289 }
00290
00291 CREATE_CONVERT_OPERATOR_C3_C1(uChar, 1, uChar, 3);
00292
00293 #define CREATE_CONVERT_OPERATOR_C1_C3(TYPE1, C1, TYPE2, C2) \
00294 template <> QVImage<TYPE1, C1> & QVImage<TYPE1, C1>::operator=(const QVImage<TYPE2, C2> &img) \
00295 { \
00296 imageBuffer = new QVImageBuffer<TYPE1, C1>(img.getCols(), img.getRows()); \
00297 setAnchor(img.getROI().x(),img.getROI().y()); \
00298 Copy(img, *this); \
00299 setAnchor(img.getAnchor()); \
00300 return *this; \
00301 }
00302
00303 CREATE_CONVERT_OPERATOR_C1_C3(uChar, 3, uChar, 1);
00304