Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

PNGGenerator.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_PNGGenerator_h_
00003 #define INCLUDED_PNGGenerator_h_
00004 
00005 #include "Vision/FilterBankGenerator.h"
00006 #include <png.h>
00007 
00008 extern "C" {
00009   void user_write_png_data(png_structp png_ptr, png_bytep data, png_size_t length);
00010 }
00011   
00012 //! Generates FilterBankEvents containing PNG compressed images
00013 /*!
00014  *  This class shares a lot of non-PNG specific code with JPEGGenerator,
00015  *  so you may want to replicate any changes made in that class as well.
00016  *
00017  *  @todo create a common super class with JPEGGenerator to hold common setup code
00018 */
00019 class PNGGenerator : public FilterBankGenerator {
00020 public:
00021   static const unsigned int PNG_HEADER_PAD=500; //!< add a bit to the expected size in getBinSize just to leave a little extra room for small images
00022   
00023   //! defines how to interpret the source images (see #srcMode and #curMode)
00024   enum src_mode_t {
00025     SRC_AUTO,       //!< if src is not a InterleavedYUVGenerator, SRC_GREYSCALE, otherwise SRC_COLOR
00026     SRC_GRAYSCALE,  //!< indicates each channel of source should be compressed individually as grayscale images
00027     SRC_COLOR       //!< indicates first channel should be in an interleaved layout which can be compressed into a "color" image
00028   };
00029   
00030   //! constructor
00031   PNGGenerator(unsigned int mysid, FilterBankGenerator* fbg, EventBase::EventTypeID_t tid);
00032   //! constructor
00033   PNGGenerator(unsigned int mysid, PNGGenerator::src_mode_t sMode, FilterBankGenerator* fbg, EventBase::EventTypeID_t tid);
00034 
00035   //! destructor
00036   virtual ~PNGGenerator();
00037 
00038   //! set #srcMode and #curMode as well if @a mode==SRC_AUTO
00039   virtual void setSourceMode(src_mode_t mode) { srcMode=mode; if(mode!=SRC_AUTO) curMode=mode;}
00040   //! returns #srcMode
00041   virtual src_mode_t getSourceMode() const { return srcMode; }
00042   //! returns #curMode
00043   virtual src_mode_t getCurrentSourceFormat() const { return curMode; }
00044   
00045   static std::string getClassDescription() { return "Compresses its source FilterBankGenerator's data into PNG format"; }
00046   
00047   //! should receive FilterBankEvents from a RawCameraGenerator (or a subclass thereof)
00048   virtual void processEvent(const EventBase& event);
00049   
00050   //! 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.
00051   virtual unsigned int getBinSize() const;
00052   
00053   virtual unsigned int loadBuffer(const char buf[], unsigned int len);
00054   
00055   //! you probably don't want to be calling this to access the PNG -- use getImage() instead (saveBuffer will prepend some header information before the actual image data)
00056   virtual unsigned int saveBuffer(char buf[], unsigned int len) const;
00057 
00058   //! 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())
00059   virtual unsigned int getImageSize(unsigned int layer, unsigned int chan) const { return bytesUsed[layer][chan]; }
00060   
00061 protected:
00062   virtual void setNumImages(unsigned int nLayers, unsigned int nChannels);
00063   virtual unsigned char * createImageCache(unsigned int layer, unsigned int chan) const;
00064   virtual void calcImage(unsigned int layer, unsigned int chan);
00065   virtual void destruct();
00066   
00067   src_mode_t srcMode;   //!< how to interpret source channel of next filter bank event
00068   src_mode_t curMode;   //!< how to interpret getImage's current image
00069   
00070   unsigned int ** bytesUsed; //!< number of bytes used per image to actually store data;
00071     
00072 private:
00073   PNGGenerator(const PNGGenerator& fbk); //!< don't call
00074   const PNGGenerator& operator=(const PNGGenerator& fbk); //!< don't call
00075 };
00076 
00077 /*! @file
00078  * @brief Describes PNGGenerator, which generates FilterBankEvents containing PNG compressed images
00079  * @author Ethan Tira-Thompson (ejt) (Creator)
00080  *
00081  * $Author: ejt $
00082  * $Name: tekkotsu-3_0 $
00083  * $Revision: 1.3 $
00084  * $State: Exp $
00085  * $Date: 2006/09/16 17:32:40 $
00086  */
00087 
00088 #endif

Tekkotsu v3.0
Generated Wed Oct 4 00:03:45 2006 by Doxygen 1.4.7