CVD 0.8
cvd/Linux/dvbuffer3.h
00001 /*                       
00002     This file is part of the CVD Library.
00003 
00004     Copyright (C) 2005 The Authors
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Lesser General Public
00008     License as published by the Free Software Foundation; either
00009     version 2.1 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Lesser General Public License for more details.
00015 
00016     You should have received a copy of the GNU Lesser General Public
00017     License along with this library; if not, write to the Free Software
00018     Foundation, Inc., 
00019     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 */
00021 // -*- c++ -*-
00022 
00023 #ifndef __DVBUFFER_3_H
00024 #define __DVBUFFER_3_H
00025 #include <cvd/videobuffer.h>
00026 #include <cvd/byte.h>
00027 #include <cvd/rgb.h>
00028 #include <inttypes.h>
00029 #include <cvd/colourspaces.h>
00030 
00031 namespace CVD
00032 {
00033   namespace Exceptions
00034   {
00035     namespace DVBuffer3
00036     {
00039       struct All : public CVD::Exceptions::VideoBuffer::All 
00040       {
00041     All(std::string sWhat)
00042       {
00043         what = "DVBuffer3: " + sWhat;
00044       }
00045       };
00046     }
00047   }
00048 
00050   namespace DV3
00051   {
00054     enum DV3Feature { BRIGHTNESS,  EXPOSURE,  SHARPNESS,
00055               WHITE_BALANCE,  HUE,  SATURATION,
00056               GAMMA,  SHUTTER,  GAIN,  IRIS,
00057               FOCUS, ZOOM,   PAN,  TILT, FRAME_RATE};
00058     
00061     enum DV3ColourSpace { MONO8,  MONO16,  MONO16S,
00062               RGB8,   RGB16,   RGB16S,
00063               YUV411, YUV422,  YUV444,
00064               RAW8,   RAW16};
00065     
00069     enum DV3ColourFilter { UNDEFINED = -1, RGGB = 0, GBRG = 1, GRBG = 2, BGGR = 3 };
00070     
00071 #ifndef DOXYGEN_IGNORE_INTERNAL
00072     // Translation helper classes to go from CVD-types to the above
00073     template<class C>  
00074       struct CSConvert
00075       { static const DV3ColourSpace space = C::Error__type_not_valid_for_camera; };
00076     template<> struct CSConvert<byte>
00077       { static const DV3ColourSpace space = MONO8;};
00078     template<> struct CSConvert<short unsigned int>
00079       { static const DV3ColourSpace space = MONO16;};
00080     template<> struct CSConvert<yuv411>
00081       { static const DV3ColourSpace space = YUV411;};
00082     template<> struct CSConvert<yuv422>
00083       { static const DV3ColourSpace space = YUV422;};
00084     template<> struct CSConvert<Rgb<byte> > 
00085       { static const DV3ColourSpace space = RGB8;};
00086     template<> struct CSConvert<bayer_bggr>
00087       { static const DV3ColourSpace space = RAW8; }; 
00088     template<> struct CSConvert<bayer_gbrg>
00089       { static const DV3ColourSpace space = RAW8; }; 
00090     template<> struct CSConvert<bayer_grbg>
00091       { static const DV3ColourSpace space = RAW8; }; 
00092     template<> struct CSConvert<bayer_rggb>
00093       { static const DV3ColourSpace space = RAW8; }; 
00094     template<> struct CSConvert<bayer_bggr16be>
00095       { static const DV3ColourSpace space = RAW16; }; 
00096     template<> struct CSConvert<bayer_gbrg16be>
00097       { static const DV3ColourSpace space = RAW16; }; 
00098     template<> struct CSConvert<bayer_grbg16be>
00099       { static const DV3ColourSpace space = RAW16; }; 
00100     template<> struct CSConvert<bayer_rggb16be>
00101       { static const DV3ColourSpace space = RAW16; }; 
00102 
00103     template<class C> struct CSFilter { static const DV3ColourFilter filter = UNDEFINED; };
00104     template<> struct CSFilter<bayer_bggr> { static const DV3ColourFilter filter = BGGR; };
00105     template<> struct CSFilter<bayer_gbrg> { static const DV3ColourFilter filter = GBRG; };
00106     template<> struct CSFilter<bayer_grbg> { static const DV3ColourFilter filter = GRBG; };
00107     template<> struct CSFilter<bayer_rggb> { static const DV3ColourFilter filter = RGGB; };
00108     template<> struct CSFilter<bayer_bggr16be> { static const DV3ColourFilter filter = BGGR; };
00109     template<> struct CSFilter<bayer_gbrg16be> { static const DV3ColourFilter filter = GBRG; };
00110     template<> struct CSFilter<bayer_grbg16be> { static const DV3ColourFilter filter = GRBG; };
00111     template<> struct CSFilter<bayer_rggb16be> { static const DV3ColourFilter filter = RGGB; };
00112 
00113     struct LibDCParams;
00114 #endif
00115     
00120     class RawDVBuffer3: public virtual RawVideoBuffer
00121     {
00122     public:
00131       RawDVBuffer3(DV3ColourSpace colourspace,
00132            int nCamNumber=0, 
00133            uint64_t cam_guid=-1,
00134            int cam_unit=-1,
00135            bool verbose=0,
00136            bool bus_reset=0,
00137            ImageRef irSize = ImageRef(-1,-1),
00138            float fFrameRate=-1.0, 
00139            ImageRef irOffset = ImageRef(-1,-1),
00140            int format7_mode=-1);
00141       
00142       ~RawDVBuffer3();
00143       static void stopAllTransmissions(void);
00144       inline ImageRef size() {return mirSize;}
00145       inline ImageRef offset() {return mirOffset;}
00146       inline double frame_rate() {return mdFramerate;}
00147       inline DV3ColourFilter colour_filter() { return mColourfilter; }
00148       
00149       VideoFrame<byte>* get_frame();
00150       void put_frame(VideoFrame<byte>* f);
00151       bool frame_pending();
00152 
00153       void set_feature_value(DV3Feature nFeature, unsigned int nValue);
00154       unsigned int get_feature_value(DV3Feature nFeature);
00155       std::pair<unsigned int, unsigned int> get_feature_min_max(DV3Feature nFeature);
00156       void auto_on_off(DV3Feature nFeature, bool bValue);
00157       void power_on_off(DV3Feature nFeature, bool bValue);
00158       
00159     private:
00160       
00161       ImageRef mirSize;
00162       ImageRef mirOffset;
00163       double mdFramerate;
00164       DV3ColourFilter mColourfilter;
00166       LibDCParams *mpLDCP;
00167     };
00168     
00169   }
00170 
00175   template <class pixel_T> 
00176     class DVBuffer3 : public VideoBuffer<pixel_T>, public DV3::RawDVBuffer3
00177     {
00178     public:
00179     DVBuffer3(unsigned int nCamNumber=0, 
00180           ImageRef irSize = ImageRef(-1,-1), 
00181           float fFPS = -1.0, 
00182           ImageRef irOffset = ImageRef(-1,-1),
00183           bool verbose=0,
00184           bool bus_reset=0,
00185           int format7_mode=-1)
00186       : VideoBuffer<pixel_T>(VideoBufferType::Live),
00187         RawDVBuffer3(DV3::CSConvert<pixel_T>::space, nCamNumber, 0, -1, verbose, bus_reset, irSize, fFPS, irOffset, format7_mode)
00188     {
00189         if(DV3::CSFilter<pixel_T>::filter != DV3::UNDEFINED && colour_filter() != DV3::CSFilter<pixel_T>::filter )
00190             throw(Exceptions::DVBuffer3::All("wrong colour filter expected"));
00191     }
00192       
00193       virtual ~DVBuffer3()   {}
00194       double frame_rate()    {return RawDVBuffer3::frame_rate();  }
00195       ImageRef size()        {return RawDVBuffer3::size(); }
00196       virtual VideoFrame<pixel_T>* get_frame()
00197       {
00198     return reinterpret_cast<VideoFrame<pixel_T>*>(RawDVBuffer3::get_frame());
00199       }
00200       virtual void put_frame(VideoFrame<pixel_T>* f)
00201       {
00202     RawDVBuffer3::put_frame(reinterpret_cast<VideoFrame<byte>*>(f));
00203       }
00204       virtual bool frame_pending() {return RawDVBuffer3::frame_pending();}
00205       virtual void seek_to(double){}
00206     };
00207   
00208 }
00209 
00210 #endif