Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
JPEGGenerator.hGo to the documentation of this file.00001 //-*-c++-*- 00002 #ifndef INCLUDED_JPEGGenerator_h_ 00003 #define INCLUDED_JPEGGenerator_h_ 00004 00005 #include "Vision/FilterBankGenerator.h" 00006 00007 extern "C" { 00008 #include <jpeglib.h> 00009 } 00010 00011 //! Generates FilterBankEvents containing JPEG compressed images 00012 /*! There's only one channel per resolution layer, which holds the 00013 * compressed data. This is mostly intended for being sent over 00014 * wireless, but if you know how JPEG works, you may be able to 00015 * interpret the compressed data directly and glean useful 00016 * information from it. After all, compression is all about throwing 00017 * away unimportant details and storing the salient information. 00018 * 00019 * The generated events use 0 for their event source IDs. The row 00020 * skip and row stride are 0. (they don't really apply here) 00021 * 00022 * This can either compress a greyscale image or an interleaved YUV 00023 * image. If the source generator's type is not 00024 * InterleavedYUVGenerator, it will assume greyscale. Call 00025 * setSource() to override this. 00026 * 00027 * The InterleavedYUVGenerator is separated from this because it 00028 * wouldn't really make things much faster to combine the algorithms, 00029 * and others might find the interleaved format handy for passing to 00030 * other libraries which expect that format, such as what happened 00031 * with libjpeg. 00032 * 00033 * @todo possible speedup by using jpeg_write_raw_data 00034 */ 00035 class JPEGGenerator : public FilterBankGenerator { 00036 public: 00037 static const unsigned int JPEG_HEADER_PAD=500; //!< add a bit to the expected size in getBinSize just to leave a little extra room for small images 00038 enum src_mode_t { 00039 SRC_AUTO, //!< if src is not a InterleavedYUVGenerator, SRC_GREYSCALE, otherwise SRC_COLOR 00040 SRC_GRAYSCALE, 00041 SRC_COLOR 00042 }; 00043 00044 //! constructor 00045 JPEGGenerator(unsigned int mysid, FilterBankGenerator* fbg, EventBase::EventTypeID_t tid); 00046 //! constructor 00047 JPEGGenerator(unsigned int mysid, JPEGGenerator::src_mode_t sMode, FilterBankGenerator* fbg, EventBase::EventTypeID_t tid); 00048 00049 //! destructor 00050 virtual ~JPEGGenerator(); 00051 00052 //! set #srcMode and #curMode as well if @a mode==SRC_AUTO 00053 virtual void setSourceMode(src_mode_t mode) { srcMode=mode; if(mode!=SRC_AUTO) curMode=mode;} 00054 //! returns #srcMode 00055 virtual src_mode_t getSourceMode() const { return srcMode; } 00056 //! returns #curMode 00057 virtual src_mode_t getCurrentSourceFormat() const { return curMode; } 00058 00059 static std::string getClassDescription() { return "Converts a compresses its source FilterBankGenerator's data into JPEG format"; } 00060 00061 //! should receive FilterBankEvents from a RawCameraGenerator (or a subclass thereof) 00062 virtual void processEvent(const EventBase& event); 00063 00064 //! if we don't already know bytesUsed, let's assume the size will be smaller than the original uncompressed. If we fail this assumption, probably better to fail anyway. 00065 virtual unsigned int getBinSize() const; 00066 00067 virtual unsigned int LoadBuffer(const char buf[], unsigned int len); 00068 00069 virtual unsigned int SaveBuffer(char buf[], unsigned int len) const; 00070 00071 //! returns #quality 00072 virtual unsigned int getQuality() const { return quality; } 00073 //! sets #quality; this will invalidate the cache if @a q does not equal current #quality 00074 virtual void setQuality(unsigned int q) { 00075 if(quality!=q) { 00076 quality=q; 00077 invalidateCaches(); 00078 } 00079 } 00080 00081 //! returns the number of bytes used for the image returned by getImage() - will return 0 if the image hasn't been calculated yet (so call it @e after getImage()) 00082 virtual unsigned int getImageSize(unsigned int layer, unsigned int chan) const { return bytesUsed[layer][chan]; } 00083 00084 protected: 00085 virtual void setNumImages(unsigned int nLayers, unsigned int nChannels); 00086 virtual unsigned char * createImageCache(unsigned int layer, unsigned int chan) const; 00087 virtual void calcImage(unsigned int layer, unsigned int chan); 00088 virtual void destruct(); 00089 00090 src_mode_t srcMode; //!< how to interpret source channel of next filter bank event 00091 src_mode_t curMode; //!< how to interpret getImage's current image 00092 00093 unsigned int ** bytesUsed; //!< number of bytes used per image to actually store data; 00094 00095 struct jpeg_compress_struct cinfo; //!< used to interface with libjpeg - holds compression parameters and state 00096 struct jpeg_error_mgr jerr; //!< used to interface with libjpeg - gives us access to error information 00097 00098 unsigned int quality; //!< quality level to pass to libjpeg; -1U causes Config::vision_config::rawcam_compress_quality to be used 00099 00100 private: 00101 JPEGGenerator(const JPEGGenerator& fbk); //!< don't call 00102 const JPEGGenerator& operator=(const JPEGGenerator& fbk); //!< don't call 00103 }; 00104 00105 /*! @file 00106 * @brief Describes JPEGGenerator, which generates FilterBankEvents containing JPEG compressed images 00107 * @author ejt (Creator) 00108 * 00109 * $Author: ejt $ 00110 * $Name: tekkotsu-2_4_1 $ 00111 * $Revision: 1.10 $ 00112 * $State: Exp $ 00113 * $Date: 2005/08/07 04:11:04 $ 00114 */ 00115 00116 #endif |
Tekkotsu v2.4.1 |
Generated Tue Aug 16 16:32:47 2005 by Doxygen 1.4.4 |