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