Homepage | Demos | Overview | Downloads | Tutorials | Reference | Credits |
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(EventBase::EventGeneratorID_t gid, unsigned int sid, unsigned int mysid); 00046 //! constructor 00047 JPEGGenerator(EventBase::EventGeneratorID_t gid, unsigned int sid, unsigned int mysid, src_mode_t sMode); 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 void setDimensions(); //!< resets width, height, skip and stride parameters 00087 virtual unsigned char * createImageCache(unsigned int layer, unsigned int chan) const; 00088 virtual void calcImage(unsigned int layer, unsigned int chan) const; 00089 virtual void destruct(); 00090 00091 const FilterBankGenerator * src; //!< the generator of the last FilterBankEvent received 00092 src_mode_t srcMode; //!< how to interpret source channel of next filter bank event 00093 src_mode_t curMode; //!< how to interpret getImage's current image 00094 00095 unsigned int ** bytesUsed; //!< number of bytes used per image to actually store data; 00096 00097 mutable struct jpeg_compress_struct cinfo; //!< used to interface with libjpeg - holds compression parameters and state 00098 mutable struct jpeg_error_mgr jerr; //!< used to interface with libjpeg - gives us access to error information 00099 00100 unsigned int quality; //!< quality level to pass to libjpeg; -1U causes Config::vision_config::rawcam_compress_quality to be used 00101 00102 private: 00103 JPEGGenerator(const JPEGGenerator& fbk); //!< don't call 00104 const JPEGGenerator& operator=(const JPEGGenerator& fbk); //!< don't call 00105 }; 00106 00107 /*! @file 00108 * @brief Describes JPEGGenerator, which generates FilterBankEvents containing JPEG compressed images 00109 * @author ejt (Creator) 00110 * 00111 * $Author: ejt $ 00112 * $Name: tekkotsu-2_0 $ 00113 * $Revision: 1.6 $ 00114 * $State: Exp $ 00115 * $Date: 2004/01/19 07:56:41 $ 00116 */ 00117 00118 #endif
Tekkotsu v2.0 |
Generated Wed Jan 21 03:20:28 2004 by Doxygen 1.3.4 |