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
00041 typedef unsigned char uChar;
00042 typedef unsigned short uShort;
00043 typedef unsigned int uInt;
00044 typedef signed char sChar;
00045 typedef signed short sShort;
00046 typedef signed int sInt;
00047
00048
00049 typedef float sFloat;
00050 typedef double sDouble;
00051
00052 template <typename Type = uChar, int Channels = 1> class QVImageBuffer: public QSharedData
00053 {
00054 public:
00055
00056
00057 QVImageBuffer(): QSharedData() {};
00058 QVImageBuffer(const QVImageBuffer<Type, Channels> &);
00059 QVImageBuffer(uInt cols, uInt rows, uInt step = 0, const Type * buffer = NULL);
00060
00061 ~QVImageBuffer() { delete this->data; }
00062
00063 uInt getRows() const { return rows; }
00064 uInt getCols() const { return cols; }
00065 uInt getStep() const { return step; }
00066 uInt getChannels() const { return planes; }
00067 uInt getTypeSize() const { return typeSize; }
00068
00069 int getDataSize() const { return dataSize; }
00070 const Type * const getReadData() const { return data; }
00071 Type * const getWriteData() const { return data; }
00072
00073 protected:
00074 Type * data;
00075 uInt cols, rows, step, planes, dataSize, typeSize, references;
00076 void allocData(uInt cols, uInt rows, uInt step = 0);
00077 };
00078
00079 template <typename Type, int Channels>
00080 void QVImageBuffer<Type,Channels>::allocData(uInt cols, uInt rows, uInt step)
00081 {
00082 qDebug() << "QVImageBuffer<Type,Channels>::allocData(" << cols << "," << rows << "," << step << ")";
00083 Q_ASSERT_X(cols > 0, "QVImageBuffer::allocData()", "cols <= 0");
00084 Q_ASSERT_X(rows > 0, "QVImageBuffer::allocData()", "rows <= 0");
00085 Q_ASSERT_X((step == 0) || (step >= cols), "QVImageBuffer::allocData()", "0 < step < cols");
00086 this->rows = rows;
00087 this->cols = cols;
00088 this->references = 0;
00089 this->planes = Channels;
00090 this->typeSize = sizeof(Type);
00091
00092 qDebug() << "QVImageBuffer<Type,Channels>::allocData(): planes" << this->planes;
00093 uInt temp = this->planes * this->typeSize * cols;
00094
00095 if (step == 0)
00096 this->step = 8*(uInt)ceil((double)(temp)/8);
00097 else
00098 this->step = step;
00099
00100 Q_ASSERT_X( (this->step % 8) == 0, "QVImageBuffer::QVImageBuffer()","step % 8 != 0");
00101 Q_ASSERT_X( this->step >= temp, "QVImageBuffer::QVImageBuffer()","step insufficient");
00102
00103 qDebug() << "QVImageBuffer<Type,Channels>::allocData(): rows" << this->rows;
00104
00105 qDebug() << "QVImageBuffer<Type,Channels>::allocData(): planes" << this->planes;
00106 this->dataSize = this->rows * this->step * this->planes;
00107
00108 qDebug() << "QVImageBuffer<Type,Channels>::allocData(): dataSize" << this->dataSize;
00109
00110 if ( (this->data != NULL) && (this->cols * this->rows != cols * rows) )
00111 {
00112 delete this->data;
00113 this->data = NULL;
00114 }
00115
00116
00117
00118 if (this->data == NULL)
00119 this->data = new Type[this->dataSize];
00120
00121 qDebug() << "QVImageBuffer<Type,Channels>::allocData(): step" << this->step;
00122 qDebug() << "QVImageBuffer<Type,Channels>::allocData(): step" << this->getStep();
00123 qDebug() << "QVImageBuffer<Type,Channels>::allocData(): dataSize" << this->dataSize;
00124 qDebug() << "QVImageBuffer<Type,Channels>::allocData(): dataSize" << this->getDataSize();
00125 qDebug() << "QVImageBuffer<Type,Channels>::allocData(" << cols << "," << rows << "," << step << ") <- return";
00126 }
00127
00128 template <typename Type, int Channels>
00129 QVImageBuffer<Type,Channels>::QVImageBuffer(uInt cols, uInt rows, uInt step, const Type *buffer): QSharedData(),
00130 data(NULL)
00131 {
00132 qDebug() << "QVImageBuffer<Type, Channels>::QVImageBuffer(" << cols << "," << rows << "," << step << ")";
00133 Q_ASSERT_X(cols > 0, "QVImageBuffer::allocData()", "cols <= 0");
00134 Q_ASSERT_X(rows > 0, "QVImageBuffer::allocData()", "rows <= 0");
00135 Q_ASSERT_X((step == 0) || (step >= cols), "QVImageBuffer::allocData()", "0 < step < cols");
00136
00137 allocData(cols, rows, step);
00138
00139 if (buffer != NULL)
00140
00141 memcpy(this->data,buffer,this->dataSize);
00142 qDebug() << "QVImageBuffer<Type, Channels>::QVImageBuffer() <- return";
00143 }
00145 #endif