00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #ifndef QVIMAGE_BUFFER_H
00026 #define QVIMAGE_BUFFER_H
00027
00028 #include <stdio.h>
00029 #include <string.h>
00030 #include <math.h>
00031
00032 #include <QObject>
00033 #include <QRect>
00034 #include <QDebug>
00035 #include <ipp.h>
00036
00037 #include <QPoint>
00038 #include <QSharedData>
00039 #include <qvdefines.h>
00040
00041 #ifndef DOXYGEN_IGNORE_THIS
00042
00043 template <typename Type = uChar, int Channels = 1> class QVImageBuffer: public QSharedData
00044 {
00045 public:
00046
00047
00048 QVImageBuffer(): QSharedData() {};
00049 QVImageBuffer(const QVImageBuffer<Type, Channels> &);
00050 QVImageBuffer(uInt cols, uInt rows, uInt step = 0, const Type * buffer = NULL);
00051
00052 ~QVImageBuffer() { delete this->data; }
00053
00054 uInt getRows() const { return rows; }
00055 uInt getCols() const { return cols; }
00056 uInt getStep() const { return step; }
00057 uInt getChannels() const { return planes; }
00058 uInt getTypeSize() const { return typeSize; }
00059
00060 int getDataSize() const { return dataSize; }
00061 const Type * const getReadData() const { return data; }
00062 Type * const getWriteData() const { return data; }
00063
00064 protected:
00065 Type * data;
00066 uInt cols, rows, step, planes, dataSize, typeSize;
00067 void allocData(uInt cols, uInt rows, uInt step = 0);
00068 };
00069
00070 template <typename Type, int Channels>
00071 void QVImageBuffer<Type,Channels>::allocData(uInt cols, uInt rows, uInt step)
00072 {
00073 qDebug() << "QVImageBuffer<Type,Channels>::allocData(" << cols << "," << rows << "," << step << ")";
00074 Q_ASSERT_X(cols > 0, "QVImageBuffer::allocData()", "cols <= 0");
00075 Q_ASSERT_X(rows > 0, "QVImageBuffer::allocData()", "rows <= 0");
00076 Q_ASSERT_X((step == 0) || (step >= cols), "QVImageBuffer::allocData()", "0 < step < cols");
00077 this->rows = rows;
00078 this->cols = cols;
00079 this->planes = Channels;
00080 this->typeSize = sizeof(Type);
00081
00082 qDebug() << "QVImageBuffer<Type,Channels>::allocData(): planes" << this->planes;
00083 uInt temp = this->planes * this->typeSize * cols;
00084
00085 if (step == 0)
00086 this->step = 8*(uInt)ceil((double)(temp)/8);
00087 else
00088 this->step = step;
00089
00090 Q_ASSERT_X( (this->step % 8) == 0, "QVImageBuffer::QVImageBuffer()","step % 8 != 0");
00091 Q_ASSERT_X( this->step >= temp, "QVImageBuffer::QVImageBuffer()","step insufficient");
00092
00093 qDebug() << "QVImageBuffer<Type,Channels>::allocData(): rows" << this->rows;
00094
00095 qDebug() << "QVImageBuffer<Type,Channels>::allocData(): planes" << this->planes;
00096 this->dataSize = this->rows * this->step * this->planes;
00097
00098 qDebug() << "QVImageBuffer<Type,Channels>::allocData(): dataSize" << this->dataSize;
00099
00100 if ( (this->data != NULL) && (this->cols * this->rows != cols * rows) )
00101 {
00102 delete this->data;
00103 this->data = NULL;
00104 }
00105
00106
00107
00108 if (this->data == NULL)
00109 this->data = new Type[this->dataSize];
00110
00111 qDebug() << "QVImageBuffer<Type,Channels>::allocData(): step" << this->step;
00112 qDebug() << "QVImageBuffer<Type,Channels>::allocData(): step" << this->getStep();
00113 qDebug() << "QVImageBuffer<Type,Channels>::allocData(): dataSize" << this->dataSize;
00114 qDebug() << "QVImageBuffer<Type,Channels>::allocData(): dataSize" << this->getDataSize();
00115 qDebug() << "QVImageBuffer<Type,Channels>::allocData(" << cols << "," << rows << "," << step << ") <- return";
00116 }
00117
00118 template <typename Type, int Channels>
00119 QVImageBuffer<Type,Channels>::QVImageBuffer(uInt cols, uInt rows, uInt step, const Type *buffer): QSharedData(),
00120 data(NULL)
00121 {
00122 qDebug() << "QVImageBuffer<Type, Channels>::QVImageBuffer(" << cols << "," << rows << "," << step << ")";
00123 Q_ASSERT_X(cols > 0, "QVImageBuffer::allocData()", "cols <= 0");
00124 Q_ASSERT_X(rows > 0, "QVImageBuffer::allocData()", "rows <= 0");
00125 Q_ASSERT_X((step == 0) || (step >= cols), "QVImageBuffer::allocData()", "0 < step < cols");
00126
00127 allocData(cols, rows, step);
00128
00129 if (buffer != NULL)
00130
00131 memcpy(this->data,buffer,this->dataSize);
00132 qDebug() << "QVImageBuffer<Type, Channels>::QVImageBuffer() <- return";
00133 }
00134 #endif
00135 #endif