00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #ifndef QVIMAGE_H
00026 #define QVIMAGE_H
00027
00028 #include <QMetaType>
00029 #include <qvcore/qvimagebuffer.h>
00030 #include <QVGenericImage>
00031 #include <QImage>
00032
00042 #define QVIMAGE_INIT_READ(TYPE, IMAGE) \
00043 const TYPE * __qv_data_##IMAGE##__ = IMAGE.getReadData(); \
00044 const uInt __qv_step_##IMAGE##__ = IMAGE.getStep()/sizeof(TYPE); \
00045 const uChar __qv_planes_##IMAGE##__ = IMAGE.getChannels(); \
00046 const uInt __qv_next_line_inc_##IMAGE##__ = __qv_step_##IMAGE##__ - IMAGE.getCols();
00047
00057 #define QVIMAGE_INIT_WRITE(TYPE, IMAGE) \
00058 TYPE * __qv_data_##IMAGE##__ = IMAGE.getWriteData(); \
00059 const uInt __qv_step_##IMAGE##__ = IMAGE.getStep()/sizeof(TYPE); \
00060 const uChar __qv_planes_##IMAGE##__ = IMAGE.getChannels(); \
00061 const uInt __qv_next_line_inc_##IMAGE##__ = __qv_step_##IMAGE##__ - IMAGE.getCols();
00062
00072 #define QVIMAGE_PTR_INIT_READ(TYPE, IMAGE) \
00073 const TYPE * __qv_data_##IMAGE##__ = IMAGE->getReadData(); \
00074 const uInt __qv_step_##IMAGE##__ = IMAGE->getStep()/sizeof(TYPE); \
00075 const uChar __qv_planes_##IMAGE##__ = IMAGE->getChannels(); \
00076 const uInt __qv_next_line_inc_##IMAGE##__ = __qv_step_##IMAGE##__ - IMAGE->getCols();
00077
00087 #define QVIMAGE_PTR_INIT_WRITE(TYPE, IMAGE) \
00088 TYPE * __qv_data_##IMAGE##__ = IMAGE->getWriteData(); \
00089 const uInt __qv_step_##IMAGE##__ = IMAGE->getStep()/sizeof(TYPE); \
00090 const uChar __qv_planes_##IMAGE##__ = IMAGE->getChannels(); \
00091 const uInt __qv_next_line_inc_##IMAGE##__ = __qv_step_##IMAGE##__ - IMAGE->getCols();
00092
00102 #define QVIMAGE_PIXEL(IMAGE, Col, Row, Channel) \
00103 (__qv_data_##IMAGE##__ [(Row)* __qv_step_##IMAGE##__ + __qv_planes_##IMAGE##__ *(Col)+(Channel)])
00104
00114 #define QVIMAGE_PIXEL_PTR(IMAGE, Col, Row, Channel) \
00115 (& (__qv_data_##IMAGE##__ [(Row)* __qv_step_##IMAGE##__ + __qv_planes_##IMAGE##__ *(Col)+(Channel)]))
00116
00123 #define QVIMAGE_ROW_INCREMENT_PTR(IMAGE) ( __qv_step_##IMAGE##__ )
00124
00131 #define QVIMAGE_COL_INCREMENT_PTR(IMAGE) ( __qv_planes_##IMAGE##__ )
00132
00139 #define QVIMAGE_NEXT_LINE_INCREMENT_PTR(IMAGE) ( __qv_next_line_inc_##IMAGE##__ )
00140
00151 template <typename Type, int Channels = 1> class QVImage: public QVGenericImage
00152 {
00153 protected:
00154 uInt step_div_type_size;
00155 QSharedDataPointer< QVImageBuffer<Type,Channels> > imageBuffer;
00156
00157 public:
00163 QVImage():QVGenericImage()
00164 {
00165 this->imageBuffer = new QVImageBuffer<Type, Channels>(1, 1);
00166 setROI(0,0, this->imageBuffer->getCols(), this->imageBuffer->getRows());
00167 setAnchor(0,0);
00168 this->step_div_type_size = getStep()/sizeof(Type);
00169 }
00170
00207 QVImage(uInt cols, uInt rows, uInt step = 0, const Type * buffer = NULL):QVGenericImage()
00208 {
00209 this->imageBuffer = new QVImageBuffer<Type, Channels>(cols, rows, step, buffer);
00210 setROI(0,0, cols, rows);
00211 setAnchor(0,0);
00212 this->step_div_type_size = getStep()/sizeof(Type);
00213 }
00214
00231 QVImage(QVImage<uChar,1> const &img);
00232
00234 QVImage(QVImage<uChar,3> const &img);
00235
00237 QVImage(QVImage<uShort,1> const &img);
00238
00240 QVImage(QVImage<uShort,3> const &img);
00241
00243 QVImage(QVImage<sShort,1> const &img);
00244
00246 QVImage(QVImage<sShort,3> const &img);
00247
00249 QVImage(QVImage<sInt,1> const &img);
00250
00252 QVImage(QVImage<sInt,3> const &img);
00253
00255 QVImage(QVImage<sFloat,1> const &img);
00256
00258 QVImage(QVImage<sFloat,3> const &img);
00259
00269 QVImage(QVImage<uChar,1> const &red, QVImage<uChar,1> const &green, QVImage<uChar,1> const &blue);
00270
00272 QVImage(QVImage<uShort,1> const &red, QVImage<uShort,1> const &green, QVImage<uShort,1> const &blue);
00273
00275 QVImage(QVImage<sShort,1> const &red, QVImage<sShort,1> const &green, QVImage<sShort,1> const &blue);
00276
00278 QVImage(QVImage<sInt,1> const &red, QVImage<sInt,1> const &green, QVImage<sInt,1> const &blue);
00279
00281 QVImage(QVImage<sFloat,1> const &red, QVImage<sFloat,1> const &green, QVImage<sFloat,1> const &blue);
00282
00283
00285 QVImage(const QImage &qImage);
00286
00288 operator QImage() const;
00289
00290
00292 const char * getTypeQString() const;
00293
00295 uInt getRows() const { return imageBuffer->getRows(); }
00296
00298 uInt getCols() const { return imageBuffer->getCols(); }
00299
00301 inline uInt getStep() const { return imageBuffer->getStep(); }
00302
00304 inline uInt getChannels() const { return imageBuffer->getChannels(); }
00305
00307 uInt getDataSize() const { return imageBuffer->getDataSize(); }
00308
00310 uInt getTypeSize() const { return imageBuffer->getTypeSize(); }
00311
00322 const Type * getReadData() const { return imageBuffer->getReadData(); }
00323
00334 Type * getWriteData() { return imageBuffer->getWriteData(); }
00335
00350 void set(Type c1 = 0, Type c2 = 0, Type c3 = 0);
00351
00360 inline Type &operator()(const uInt col, const uInt row, const uInt channel = 0)
00361 {
00362 Q_ASSERT_X(step_div_type_size == getStep()/sizeof(Type), "QVImage::operator()", "step/size(Type) incorrect");
00363 Q_ASSERT_X(col < getCols(),"QVImage::operator()","col further upper bound");
00364 Q_ASSERT_X(row < getRows(),"QVImage::operator()","row further upper bound");
00365 const int idx = step_div_type_size*row + Channels*col + channel;
00366 Q_ASSERT_X(idx >= 0,"QVImage::operator()","accessing below data");
00367 Q_ASSERT_X(idx < getDataSize(),"QVImage::operator()","accessing above data");
00368
00369 return imageBuffer->getWriteData()[idx];
00370 }
00371
00372 inline Type operator()(const uInt col, const uInt row, const uInt channel = 0) const
00373 {
00374 Q_ASSERT_X(step_div_type_size == getStep()/sizeof(Type), "QVImage::operator()", "step/size(Type) incorrect");
00375 Q_ASSERT_X(col < getCols(),"QVImage::operator()","col further upper bound");
00376 Q_ASSERT_X(row < getRows(),"QVImage::operator()","row further upper bound");
00377 const int idx = step_div_type_size*row + Channels*col + channel;
00378 Q_ASSERT_X(idx >= 0,"QVImage::operator()","accessing below data");
00379 Q_ASSERT_X(idx < getDataSize(),"QVImage::operator()","accessing above data");
00380
00381 return imageBuffer->getReadData()[idx];
00382 }
00383
00390 inline Type &operator()(const QPoint point, const uInt channel = 0)
00391 {
00392 Q_ASSERT_X(step_div_type_size == getStep()/sizeof(Type), "QVImage::operator()", "step/size(Type) incorrect");
00393 Q_ASSERT_X(point.x() < getCols(),"QVImage::operator()","col further upper bound");
00394 Q_ASSERT_X(point.y() < getRows(),"QVImage::operator()","row further upper bound");
00395 const int idx = step_div_type_size*point.y() + Channels*point.x() + channel;
00396 Q_ASSERT_X(idx >= 0,"QVImage::operator()","accessing below data");
00397 Q_ASSERT_X(idx < getDataSize(),"QVImage::operator()","accessing above data");
00398
00399 return imageBuffer->getWriteData()[idx];
00400 }
00401
00402 inline Type operator()(const QPoint point, const uInt channel = 0) const
00403 {
00404 Q_ASSERT_X(step_div_type_size == getStep()/sizeof(Type), "QVImage::operator()", "step/size(Type) incorrect");
00405 Q_ASSERT_X(point.x() < getCols(),"QVImage::operator()","col further upper bound");
00406 Q_ASSERT_X(point.y() < getRows(),"QVImage::operator()","row further upper bound");
00407 const int idx = step_div_type_size*point.y() + Channels*point.x() + channel;
00408 Q_ASSERT_X(idx >= 0,"QVImage::operator()","accessing below data");
00409 Q_ASSERT_X(idx < getDataSize(),"QVImage::operator()","accessing above data");
00410
00411 return imageBuffer->getReadData()[idx];
00412 }
00413
00422 QVImage<Type, 1> operator()(const uInt channel = 0) const;
00423
00440 QVImage<Type, Channels> & operator=(const QVImage<uChar, 1> &sourceImage);
00441
00443 QVImage<Type, Channels> & operator=(const QVImage<uChar, 3> &sourceImage);
00444
00446 QVImage<Type, Channels> & operator=(const QVImage<uShort, 1> &sourceImage);
00447
00449 QVImage<Type, Channels> & operator=(const QVImage<uShort, 3> &sourceImage);
00450
00452 QVImage<Type, Channels> & operator=(const QVImage<sShort, 1> &sourceImage);
00453
00455 QVImage<Type, Channels> & operator=(const QVImage<sShort, 3> &sourceImage);
00456
00458 QVImage<Type, Channels> & operator=(const QVImage<sInt, 1> &sourceImage);
00459
00461 QVImage<Type, Channels> & operator=(const QVImage<sInt, 3> &sourceImage);
00462
00464 QVImage<Type, Channels> & operator=(const QVImage<sFloat, 1> &sourceImage);
00465
00467 QVImage<Type, Channels> & operator=(const QVImage<sFloat, 3> &sourceImage);
00468
00479 bool operator==(const QVImage<Type, Channels> &img) const;
00480
00494 bool operator!=(const QVImage<Type, Channels> &img) const { return !(*this == img); }
00495
00501 QVImage<uChar, 1> operator<(const QVImage<uChar, Channels> &img) const;
00502
00508 QVImage<uChar, 1> operator<(const QVImage<uShort, Channels> &img) const;
00509
00515 QVImage<uChar, 1> operator<(const QVImage<sShort, Channels> &img) const;
00516
00522 QVImage<uChar, 1> operator<(const QVImage<sInt, Channels> &img) const;
00523
00529 QVImage<uChar, 1> operator<(const QVImage<sFloat, Channels> &img) const;
00530
00536 QVImage<uChar, 1> operator>(const QVImage<uChar, Channels> &img) const;
00537
00543 QVImage<uChar, 1> operator>(const QVImage<uShort, Channels> &img) const;
00544
00550 QVImage<uChar, 1> operator>(const QVImage<sShort, Channels> &img) const;
00551
00557 QVImage<uChar, 1> operator>(const QVImage<sInt, Channels> &img) const;
00558
00564 QVImage<uChar, 1> operator>(const QVImage<sFloat, Channels> &img) const;
00565
00571 QVImage<uChar, 1> operator<=(const QVImage<uChar, Channels> &img) const;
00572
00578 QVImage<uChar, 1> operator<=(const QVImage<uShort, Channels> &img) const;
00579
00585 QVImage<uChar, 1> operator<=(const QVImage<sShort, Channels> &img) const;
00586
00592 QVImage<uChar, 1> operator<=(const QVImage<sInt, Channels> &img) const;
00593
00599 QVImage<uChar, 1> operator<=(const QVImage<sFloat, Channels> &img) const;
00600
00606 QVImage<uChar, 1> operator>=(const QVImage<uChar, Channels> &img) const;
00607
00613 QVImage<uChar, 1> operator>=(const QVImage<uShort, Channels> &img) const;
00614
00620 QVImage<uChar, 1> operator>=(const QVImage<sShort, Channels> &img) const;
00621
00627 QVImage<uChar, 1> operator>=(const QVImage<sInt, Channels> &img) const;
00628
00634 QVImage<uChar, 1> operator>=(const QVImage<sFloat, Channels> &img) const;
00635
00645 QVImage<Type, Channels> operator+(const Type constant) const;
00646
00656 QVImage<Type, Channels> operator*(const Type constant) const;
00657
00667 QVImage<Type, Channels> operator-(const Type constant) const;
00668
00678 QVImage<Type, Channels> operator/(const Type constant) const;
00679
00689 QVImage<Type, Channels> operator<<(const Type constant) const;
00690
00700 QVImage<Type, Channels> operator>>(const Type constant) const;
00701
00707 QVImage<Type, Channels> operator!() const;
00708
00715 QVImage<Type, Channels> operator&(const Type constant) const;
00716
00723 QVImage<Type, Channels> operator|(const Type constant) const;
00724
00731 QVImage<Type, Channels> operator^(const Type constant) const;
00732
00740 QVImage<Type, Channels> operator+(const QVImage<Type, Channels> &img) const;
00741
00749 QVImage<Type, Channels> operator*(const QVImage<Type, Channels> &img) const;
00750
00758 QVImage<Type, Channels> operator-(const QVImage<Type, Channels> &img) const;
00759
00767 QVImage<Type, Channels> operator/(const QVImage<Type, Channels> &img) const;
00768 };
00769
00770 template <typename Type, int C> bool QVImage<Type, C>::operator==(const QVImage<Type, C> &img) const
00771 {
00772 Q_ASSERT_X(img.getChannels() == this->getChannels(), "QVImage::operator==", "different number of planes");
00773 if (this->getCols() != img.getCols()) return false;
00774 if (this->getRows() != img.getRows()) return false;
00775 if (this->getChannels() != img.getChannels()) return false;
00776 if (this->getROI() != img.getROI()) return false;
00777 QVIMAGE_INIT_READ(Type,img);
00778 QVIMAGE_PTR_INIT_READ(Type,this);
00779
00780 uInt x0 = (uInt) img.getROI().x(), y0 = (uInt) img.getROI().y();
00781 uInt x1 = (uInt) img.getROI().width(), y1 = (uInt) img.getROI().height();
00782
00783 uInt lineSize = x1 * img.getChannels();
00784 for(uInt row = y0; row < y1; row++)
00785 if (memcmp(&QVIMAGE_PIXEL(img, x0, row, 0),&QVIMAGE_PIXEL(this, x0, row, 0), lineSize) != 0)
00786 return false;
00787 return true;
00788 };
00789
00790
00791 typedef QVImage<uChar,1> QVImageUCharC1;
00792 typedef QVImage<uChar,3> QVImageUCharC3;
00793 typedef QVImage<uShort,1> QVImageUShortC1;
00794 typedef QVImage<uShort,3> QVImageUShortC3;
00795 typedef QVImage<sShort,1> QVImageSShortC1;
00796 typedef QVImage<sShort,3> QVImageSShortC3;
00797 typedef QVImage<sInt,1> QVImageSIntC1;
00798 typedef QVImage<sInt,3> QVImageSIntC3;
00799 typedef QVImage<sFloat,1> QVImageSFloatC1;
00800 typedef QVImage<sFloat,3> QVImageSFloatC3;
00801
00802 Q_DECLARE_METATYPE(QVImageUCharC1);
00803 Q_DECLARE_METATYPE(QVImageUCharC3);
00804 Q_DECLARE_METATYPE(QVImageUShortC1);
00805 Q_DECLARE_METATYPE(QVImageUShortC3);
00806 Q_DECLARE_METATYPE(QVImageSShortC1);
00807 Q_DECLARE_METATYPE(QVImageSShortC3);
00808 Q_DECLARE_METATYPE(QVImageSIntC1);
00809 Q_DECLARE_METATYPE(QVImageSIntC3);
00810 Q_DECLARE_METATYPE(QVImageSFloatC1);
00811 Q_DECLARE_METATYPE(QVImageSFloatC3);
00812
00813 #endif // QVIMAGE_H