QCamFrame.hpp

00001 #ifndef _QCamFrame_hpp_
00002 #define _QCamFrame_hpp_
00003 
00004 #include <stdlib.h>
00005 
00006 #include <qsize.h>
00007 
00008 #include <iostream>
00009 #include <assert.h>
00010 #include <string>
00011 #include <map>
00012 
00013 class QImage;
00014 
00015 using namespace std;
00016 
00017 enum ImageMode {
00018    YuvFrame,
00019    GreyFrame,
00020    /* GR
00021       BG */
00022    RawRgbFrame1,
00023    /* RG
00024       GB */
00025    RawRgbFrame2,
00026    /* BG
00027       GR */
00028    RawRgbFrame3,
00029    /* GB
00030       RG */
00031    RawRgbFrame4,
00032    
00033 };
00034 
00035 /*** to not be used */
00036 class QCamFrameCommon {
00037 protected:
00038    QCamFrameCommon(ImageMode mode): mode_(mode) {
00039       init();
00040       //cout << "new()="<<this<<endl;
00041    };
00042    QCamFrameCommon * clone();
00043 
00044    int nbRef() const { return nbRef_;};
00045    void incRef() {
00046       assert(this);
00047       ++nbRef_;
00048       //cout << "incRef "<<this <<" "<<nbRef_<<endl;
00049    }
00050    
00051    void decRef();
00052    
00053    const unsigned char * Y() const { return yFrame_;}
00054    const unsigned char * U() const { return (mode_!=YuvFrame)?UVGreyBuff():uFrame_;}
00055    const unsigned char * V() const { return (mode_!=YuvFrame)?UVGreyBuff():vFrame_;}
00056 
00057    unsigned char * Y() { return yFrame_;}
00058    unsigned char * U() { return (mode_!=YuvFrame)?UVGreyBuff():uFrame_;}
00059    unsigned char * V() { return (mode_!=YuvFrame)?UVGreyBuff():vFrame_;}
00060 
00061    int ySize() const { return ySize_;}
00062    int uSize() const { return uSize_;}
00063    int vSize() const { return vSize_;}
00064    
00065    const unsigned char * YLine(int line) const {
00066       return yFrame_+line*size_.width();
00067    }
00068    const unsigned char * ULine(int line) const {
00069       return (mode_!=YuvFrame)?UVGreyBuff():(uFrame_+(line/2)*(size_.width()/2));
00070    }
00071    const unsigned char * VLine(int line) const {
00072       return (mode_!=YuvFrame)?UVGreyBuff():(vFrame_+(line/2)*(size_.width()/2));
00073    }
00074    unsigned char * YLine(int line) {
00075       return yFrame_+line*size_.width();
00076    }
00077    unsigned char * ULine(int line) {
00078       return (mode_!=YuvFrame)?UVGreyBuff():(uFrame_+(line/2)*(size_.width()/2));
00079    }
00080    unsigned char * VLine(int line) {
00081       return (mode_!=YuvFrame)?UVGreyBuff():(vFrame_+(line/2)*(size_.width()/2));
00082    }
00083    void clear();
00084    bool empty() const;
00085    void setSize(QSize s);
00086    const QSize & size() { return size_;}
00087    const QImage & colorImage() const;
00088    const QImage & grayImage() const;
00089    const QImage & grayImageNegated() const;
00090    const QImage & falseColorImage() const;
00091    void clearCache();
00092    void copy(const QCamFrameCommon & src,
00093              int srcX1,int srcY1,
00094              int srcX2,int srcY2,
00095              int dstX,int dstY,
00096              bool mirrorX,bool mirrorY);
00097    void move(int srcX1,int srcY1,
00098              int srcX2,int srcY2,
00099              int dstX,int dstY);
00100    void setMode(ImageMode val) { mode_=val; allocBuff();}
00101    ImageMode getMode() const { return mode_;}
00102    friend class QCamFrame;
00103    void rotate(int center_x, int center_y, double angle);
00104    void rotatePI(int center_x,int center_y);
00105    const string & getProperty(const string & propName) const;
00106 private:
00107    void hShear(int liney, double radang);
00108    void vShear(int linex, double radang);
00109    void rasterOpV(int   x, int   w, int   vshift);
00110    void rasterOpH(int   y, int   h, int   hshift);
00111    const unsigned char * UVGreyBuff() const;
00112    unsigned char * UVGreyBuff();
00113    ~QCamFrameCommon();
00114    QCamFrameCommon(const QCamFrameCommon&);
00115    QCamFrameCommon & operator=(const QCamFrameCommon&);
00116    void init() {
00117       nbRef_=0;
00118       yFrame_=uFrame_=vFrame_=0;
00119       size_=QSize(0,0);
00120       ySize_=uSize_=vSize_=0;
00121       colorImage_=grayImage_=0;
00122       colorImageBuff_=0;
00123    }
00124    void allocBuff();
00125    ImageMode mode_;
00126    int nbRef_;
00127    unsigned char *yFrame_;
00128    unsigned char *uFrame_;
00129    unsigned char *vFrame_;
00130    QSize size_;
00131    int ySize_;
00132    int uSize_;
00133    int vSize_;
00134    mutable QImage * colorImage_;
00135    mutable uchar * colorImageBuff_;
00136    mutable QImage * grayImage_;
00137    mutable map<string,string> properties_;
00138 };
00139 
00140 class QCamFrame {
00141 public:
00142    QCamFrame(ImageMode mode=YuvFrame);
00143    QCamFrame(const QCamFrame& other);
00144    QCamFrame & operator=(const QCamFrame & other);
00145    ~QCamFrame();
00146    const QCamFrameCommon * getCommon() const { return common_; }
00147    QCamFrameCommon * setCommon();
00148    const QSize & size() const { return common_->size_;}
00149    int ySize() const { return getCommon()->ySize_;}
00150    int uSize() const { return getCommon()->uSize_;}
00151    int vSize() const { return getCommon()->vSize_;}
00152    const unsigned char * Y() const { return getCommon()->Y();}
00153    const unsigned char * U() const { return getCommon()->U();}
00154    const unsigned char * V() const { return getCommon()->V();}
00155    const unsigned char * YLine(int line) const
00156       { return getCommon()->YLine(line);}
00157    const unsigned char * ULine(int line) const
00158       { return getCommon()->ULine(line);}
00159    const unsigned char * VLine(int line) const
00160       { return getCommon()->VLine(line);}
00161    unsigned char * YforUpdate() { return setCommon()->Y();}
00162    unsigned char * UforUpdate() { return setCommon()->U();}
00163    unsigned char * VforUpdate() { return setCommon()->V();}
00164    unsigned char * YforOverwrite();
00165    unsigned char * UforOverwrite();
00166    unsigned char * VforOverwrite();
00167    unsigned char * YLineForUpdate(int line)
00168       { return setCommon()->YLine(line);}
00169    unsigned char * ULineForUpdate(int line)
00170       { return setCommon()->ULine(line);}
00171    unsigned char * VLineForUpdate(int line)
00172       { return setCommon()->VLine(line);}
00173    void setSize(const QSize & s) { if (getCommon()->size_ != s) setCommon()->setSize(s) ;}
00174    bool empty() const { return getCommon()->empty(); }
00175    void clear() { setCommon()->clear();}
00176    const QImage & colorImage() const { return getCommon()->colorImage();}
00177    const QImage & grayImage() const { return getCommon()->grayImage();}
00178    const QImage & grayImageNegated() const { return getCommon()->grayImageNegated();}
00179    const QImage & falseColorImage() const { return getCommon()->falseColorImage();}
00180    void copy(const QCamFrame & src,
00181              int srcX1,int srcY1,
00182              int srcX2,int srcY2,
00183              int dstX,int dstY,
00184              bool mirrorX=false,bool mirrorY=false);
00185    void setMode(ImageMode val) { if (getCommon()->getMode() != val) setCommon()->setMode(val);}
00186    ImageMode getMode() const { return getCommon()->getMode();}
00187    void rotate(int centerX,int centerY,double angle) {if (angle !=0.0) setCommon()->rotate(centerX,centerY,angle);}
00188    const string & getProperty(const string & propName) const { return getCommon()->getProperty(propName);}
00189    void exportProperties(map<string,string> & dest) const;
00190    void setAllProperies(const map<string,string> & src) const;
00191 private:
00192    QCamFrameCommon * common_;
00193 };
00194 
00195 #endif

Generated on Sat Oct 27 09:21:03 2007 for QastroCam by  doxygen 1.5.1