src/qvcore/qvimagebuffer.h

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
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;          // Ipp8u        1 bytes
00042 typedef unsigned short  uShort;         // Ipp16u       2 "
00043 typedef unsigned int    uInt;           // Ipp32u       4 "
00044 typedef signed char     sChar;          // Ipp8s        1 ...
00045 typedef signed short    sShort;         // Ipp16s       2
00046 typedef signed int      sInt;           // Ipp32s       4
00047 //typedef __INT64       sLong;          // Ipp64s       8 (not estandar type)
00048 //typedef __UINT64      uLong;          // Ipp64u       8 (not estandar type)
00049 typedef float           sFloat;         // Ipp32f       4
00050 typedef double          sDouble;        // Ipp64f       8
00051 
00052 template <typename Type = uChar, int Channels = 1> class QVImageBuffer: public QSharedData
00053         {
00054         public:
00055                 //QVImageBuffer();
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         //qDebug() << "QVImageBuffer<Type,Channels>::allocData(): dataSize" << this->dataSize;
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                 // *_* to *_* (copy)
00141                 memcpy(this->data,buffer,this->dataSize);
00142         qDebug() << "QVImageBuffer<Type, Channels>::QVImageBuffer() <- return";
00143         }
00145 #endif

Generated on Thu Mar 13 19:18:16 2008 for QVision by  doxygen 1.5.3