Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

ImageStreamDriver.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_ImageStreamDriver_h_
00003 #define INCLUDED_ImageStreamDriver_h_
00004 
00005 #include "DataStreamDriver.h"
00006 #include "Shared/ProjectInterface.h"
00007 
00008 //! description of ImageStreamDriver
00009 class ImageStreamDriver : public DataStreamDriver {
00010 public:
00011   explicit ImageStreamDriver(const std::string& name)
00012     : DeviceDriver(autoRegisterDriver,name), DataStreamDriver(autoRegisterDriver,name), format(FORMAT_JPEG,formatNames), payloadSize(0), sid(ProjectInterface::visRawCameraSID)
00013   {
00014     addEntry("Format",format,"The type of format to expect from the comm port.\n"
00015          "'YUV' expects interleaved components 'CameraResolutionX' wide and 'CameraResolutionY' high\n"
00016          "(defined in target's RobotInfo namespace)");
00017   }
00018 
00019   virtual std::string getClassName() const { return autoRegisterDriver; }
00020 
00021   virtual void getImageSources(std::map<std::string,DataSource*>& sources) {
00022     sources.clear();
00023     sources["Camera"]=this;
00024   }
00025   
00026   virtual void plistValueChanged(const plist::PrimitiveBase& pl);
00027   
00028   //! enumerates the available formats for input to the driver
00029   enum format_t {
00030     FORMAT_YUV=0, //!< raw interleaved YUV data, @c CameraResolutionX wide by @c CameraResolutionY high (defined in target's RobotInfo namespace)
00031     FORMAT_PNG, //!< PNG compressed image
00032     FORMAT_JPEG, //!< JPEG compressed iamge
00033     FORMAT_TEKKOTSU //!< the format used by the Tekkotsu streaming video
00034   };
00035   //! number of entries in format_t
00036   static const size_t NUM_FORMATS = 4;
00037   //! human-readable names for the supported formats, see format_t
00038   static const char * formatNames[NUM_FORMATS+1];
00039   
00040   //! The type of format to expect from the comm port.
00041   /*! 'YUV' expects interleaved components 'CameraResolutionX' wide and 'CameraResolutionY' high (defined in target's RobotInfo namespace) */
00042   plist::NamedEnumeration<format_t> format;
00043 
00044 protected:
00045   virtual bool readData(std::istream& is);
00046   RCRegion * readImage(std::istream& is);
00047   static void copyImage(char * buf, unsigned int width, unsigned int height, unsigned int channels, const char * chan, unsigned int lwidth, unsigned int lheight, unsigned int lchan);
00048   
00049   virtual void connect(CommPort* comm);
00050   virtual void disconnect(CommPort* comm);
00051 
00052   void setSID(unsigned short imageSID) {this->sid = imageSID;}
00053   
00054   size_t payloadSize; //!< caches size of last decompressed (yuv) image to assume next image will be the same size
00055   unsigned short sid; // the source id of the stream
00056 
00057 private:
00058   //! holds the class name, set via registration with the DeviceDriver registry
00059   static const std::string autoRegisterDriver;
00060   ImageStreamDriver(const ImageStreamDriver&); //!< no call
00061   ImageStreamDriver operator=(const ImageStreamDriver&); //!< no call
00062 };
00063 
00064 /*! @file
00065  * @brief 
00066  * @author Ethan Tira-Thompson (ejt) (Creator)
00067  */
00068 
00069 #endif

Tekkotsu Hardware Abstraction Layer 5.1CVS
Generated Mon May 9 05:01:38 2016 by Doxygen 1.6.3