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 Planes = 1> class QVImageBuffer: public QSharedData
00053 {
00054 public:
00055
00056
00057 QVImageBuffer(): QSharedData() {};
00058 QVImageBuffer(const QVImageBuffer<Type, Planes> &);
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 getPlanes() 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
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 protected:
00092 Type * data;
00093 uInt cols, rows, step, planes, dataSize, typeSize, references;
00094 void allocData(uInt cols, uInt rows, uInt step = 0);
00095 };
00096
00097 template <typename Type, int Planes>
00098 void QVImageBuffer<Type,Planes>::allocData(uInt cols, uInt rows, uInt step)
00099 {
00100 qDebug() << "QVImageBuffer<Type,Planes>::allocData(" << cols << "," << rows << "," << step << ")";
00101 Q_ASSERT_X(cols > 0, "QVImageBuffer::allocData()", "cols <= 0");
00102 Q_ASSERT_X(rows > 0, "QVImageBuffer::allocData()", "rows <= 0");
00103 Q_ASSERT_X((step == 0) || (step >= cols), "QVImageBuffer::allocData()", "0 < step < cols");
00104 this->rows = rows;
00105 this->cols = cols;
00106 this->references = 0;
00107 this->planes = Planes;
00108 this->typeSize = sizeof(Type);
00109
00110 qDebug() << "QVImageBuffer<Type,Planes>::allocData(): planes" << this->planes;
00111 uInt temp = this->planes * this->typeSize * cols;
00112
00113 if (step == 0)
00114 this->step = 8*(uInt)ceil((double)(temp)/8);
00115 else
00116 this->step = step;
00117
00118 Q_ASSERT_X( (this->step % 8) == 0, "QVImageBuffer::QVImageBuffer()","step % 8 != 0");
00119 Q_ASSERT_X( this->step >= temp, "QVImageBuffer::QVImageBuffer()","step insufficient");
00120
00121 qDebug() << "QVImageBuffer<Type,Planes>::allocData(): rows" << this->rows;
00122
00123 qDebug() << "QVImageBuffer<Type,Planes>::allocData(): planes" << this->planes;
00124 this->dataSize = this->rows * this->step * this->planes;
00125
00126 qDebug() << "QVImageBuffer<Type,Planes>::allocData(): dataSize" << this->dataSize;
00127
00128 if ( (this->data != NULL) && (this->cols * this->rows != cols * rows) )
00129 {
00130 delete this->data;
00131 this->data = NULL;
00132 }
00133
00134
00135
00136 if (this->data == NULL)
00137 this->data = new Type[this->dataSize];
00138
00139 qDebug() << "QVImageBuffer<Type,Planes>::allocData(): step" << this->step;
00140 qDebug() << "QVImageBuffer<Type,Planes>::allocData(): step" << this->getStep();
00141 qDebug() << "QVImageBuffer<Type,Planes>::allocData(): dataSize" << this->dataSize;
00142 qDebug() << "QVImageBuffer<Type,Planes>::allocData(): dataSize" << this->getDataSize();
00143 qDebug() << "QVImageBuffer<Type,Planes>::allocData(" << cols << "," << rows << "," << step << ") <- return";
00144 }
00145
00146 template <typename Type, int Planes>
00147 QVImageBuffer<Type,Planes>::QVImageBuffer(uInt cols, uInt rows, uInt step, const Type *buffer): QSharedData(),
00148 data(NULL)
00149 {
00150 qDebug() << "QVImageBuffer<Type, Planes>::QVImageBuffer(" << cols << "," << rows << "," << step << ")";
00151 Q_ASSERT_X(cols > 0, "QVImageBuffer::allocData()", "cols <= 0");
00152 Q_ASSERT_X(rows > 0, "QVImageBuffer::allocData()", "rows <= 0");
00153 Q_ASSERT_X((step == 0) || (step >= cols), "QVImageBuffer::allocData()", "0 < step < cols");
00154
00155 allocData(cols, rows, step);
00156
00157 if (buffer != NULL)
00158
00159 memcpy(this->data,buffer,this->dataSize);
00160 qDebug() << "QVImageBuffer<Type, Planes>::QVImageBuffer() <- return";
00161 }
00163 #endif