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 <math.h>
00029 #include <QObject>
00030 #include <QDebug>
00031 #include <QSharedData>
00032 #include <qvdefines.h>
00033
00034
00035 #include <malloc.h>
00036
00037 #ifndef DOXYGEN_IGNORE_THIS
00038 template <typename Type = uChar> class QVImageBuffer: public QSharedData
00039 {
00040 public:
00041
00042 QVImageBuffer(uInt cols = 0, uInt rows = 0, uInt stepPadding = 8);
00043
00044
00045 QVImageBuffer(uInt cols, uInt rows, uInt step, const Type * buffer = NULL);
00046
00047
00048 QVImageBuffer(const QVImageBuffer<Type> &);
00049
00050
00051 ~QVImageBuffer() { if (_data != NULL) delete _data; }
00052
00053 uInt getRows() const { return rows; }
00054 uInt getCols() const { return cols; }
00055 uInt getStep() const { return step; }
00056 int getDataSize() const { return dataSize; }
00057 const Type *getReadData() const { return _data; }
00058 Type * getWriteData() const { return _data; }
00059
00060 private:
00061 const uInt cols, rows, step, dataSize;
00062 Type * _data;
00063 };
00064
00065
00066
00067
00068 uInt paddedStep(const uInt size, const uInt padding);
00069
00070
00071 template <typename Type>
00072 QVImageBuffer<Type>::QVImageBuffer(uInt cols, uInt rows, uInt stepPadding): QSharedData(),
00073 cols(cols), rows(rows), step( stepPadding*(uInt)ceil((double)(sizeof(Type) * cols)/stepPadding) ),
00074 dataSize(rows * step),
00075 _data( (dataSize > 0)? new Type[dataSize]: NULL )
00076 {
00077
00078
00079
00080 Q_ASSERT_X(step % stepPadding == 0, "QVImageBuffer::QVImageBuffer()","step % stepPadding != 0");
00081 Q_ASSERT_X(step >= cols, "QVImageBuffer::allocData()", "0 < step < cols");
00082 Q_ASSERT_X(step == paddedStep(sizeof(Type) * cols, stepPadding), "QVImageBuffer::allocData()", "Debug error 31145X");
00083 }
00084
00085
00086 template <typename Type>
00087 QVImageBuffer<Type>::QVImageBuffer(uInt cols, uInt rows, uInt step, const Type *buffer): QSharedData(),
00088 cols(cols), rows(rows), step(step), dataSize(rows * step),
00089 _data( (dataSize > 0)? new Type[dataSize]: NULL )
00090 {
00091
00092
00093
00094 if ( (buffer != NULL) and (dataSize > 0) )
00095 memcpy(_data,buffer, dataSize);
00096
00097 Q_ASSERT_X(step >= cols, "QVImageBuffer::allocData()", "0 < step < cols");
00098 }
00099
00100
00101 template <typename Type>
00102 QVImageBuffer<Type>::QVImageBuffer(const QVImageBuffer<Type> &imageBuffer): QSharedData(imageBuffer),
00103 cols(imageBuffer.cols), rows(imageBuffer.rows), step(imageBuffer.step), dataSize(imageBuffer.dataSize),
00104 _data( (dataSize > 0)? new Type[dataSize]: NULL )
00105 {
00106
00107
00108
00109 if (dataSize > 0)
00110 memcpy(_data, imageBuffer.getReadData(), dataSize);
00111 }
00112
00113 #endif // DOXYGEN_IGNORE_THIS
00114 #endif // QVIMAGE_BUFFER_H