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 Planes = 1> class QVImageBuffer: public QSharedData
00053         {
00054         public:
00055                 //QVImageBuffer();
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                 /*QVImageBuffer * subscribe()                   { references++; return this; }
00073                 const uInt unsubscribe()
00074                         {
00075                         Q_ASSERT_X(references > 0,"QVImageBuffer::unsubscribe()","no QVImage is susbscribed");
00076                         return --references;
00077                         }*/
00078 
00079                 // DEPRECATED
00080                 //void copy(const Type * buffer, uInt step);
00081                 //bool soleOwner()                      const   { return references < 2; }
00082 
00083                 // WARNING: use this function with care.
00084                 //void incrementReferences()                    { references++; }
00085 
00086                 //QVImageBuffer<Type,Planes> & operator=(const QVImageBuffer<uChar, 1> &sourceImageBuffer);
00087                 //QVImageBuffer<Type,Planes> & operator=(const QVImageBuffer<uChar, 3> &sourceImageBuffer);
00088                 //QVImageBuffer<Type,Planes> & operator=(const QVImageBuffer<sShort, 1> &sourceImageBuffer);
00089                 //QVImageBuffer<Type,Planes> & operator=(const QVImageBuffer<sShort, 3> &sourceImageBuffer);
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         //qDebug() << "QVImageBuffer<Type,Planes>::allocData(): dataSize" << this->dataSize;
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                 // *_* to *_* (copy)
00159                 memcpy(this->data,buffer,this->dataSize);
00160         qDebug() << "QVImageBuffer<Type, Planes>::QVImageBuffer() <- return";
00161         }
00163 #endif

Generated on Thu Dec 13 13:06:25 2007 for QVision by  doxygen 1.5.3