Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

BufferedImageGenerator.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_BufferedImageGenerator_h_
00003 #define INCLUDED_BufferedImageGenerator_h_
00004 
00005 #include "FilterBankGenerator.h"
00006 #include "RawCameraGenerator.h"
00007 
00008 class MessageReceiver;
00009 
00010 //! description of BufferedImageGenerator
00011 class BufferedImageGenerator : public FilterBankGenerator {
00012 public:
00013   //!Stores information about the current frame, (not the image itself, but meta data a pointer to it)
00014   struct ImageSource {
00015     //!constructor
00016     ImageSource() : width(0), height(0), channels(0), frameIndex(0), layer(0), receiver(NULL), img(NULL) {}
00017     //!copy constructor
00018     ImageSource(const ImageSource& src) : width(src.width), height(src.height), channels(src.channels), frameIndex(src.frameIndex), layer(src.layer), receiver(src.receiver), img(src.img) {}
00019     //!assignment operator
00020     ImageSource& operator=(const ImageSource& src) { width=src.width; height=src.height; channels=src.channels; frameIndex=src.frameIndex; layer=src.layer; receiver=src.receiver; img=src.img; return *this; } 
00021     unsigned int width; //!< the width of #img
00022     unsigned int height; //!< the height of #img
00023     unsigned int channels; //!< the number of color channels in #img
00024     unsigned int frameIndex; //!< the serial number of the current frame (should be a unique, increasing ID)
00025 
00026     //! indicates what resolution layer of the pipeline this should be used at
00027     /*! Negative values are interpreted as "from the top", so -1 is the topmost layer, -2 is next-to-top, and so on.\n
00028      *  Non-negative values are interpreted as direct layer values, so 0 indicates bottommost layer, 1 indicates next-to-bottom, and so on. */
00029     unsigned int layer; 
00030 
00031     //! a pointer back to the MessageReceiver which got the image
00032     /*! If this value is non-NULL, when getImage is called, MessageReceiver::markRead() will be called on the receiver */
00033     MessageReceiver * receiver;
00034 
00035     //! pointer to the first byte of the image buffer
00036     /*! img should be stored in a channel-interleaved format, e.g. RGBRGBRGB... */
00037     unsigned char * img;
00038   };
00039 
00040   //! constructor
00041   BufferedImageGenerator(const std::string& name,EventBase::EventGeneratorID_t mgid, unsigned int msid, unsigned int nLayers, EventBase::EventGeneratorID_t srcgid, unsigned int srcsid)
00042     : FilterBankGenerator("BufferedImageGenerator",name,mgid,msid,srcgid,srcsid), imgsrc(), isAllocated(NULL), accessed(true)
00043   { 
00044     /* As a root stage, we need to listen to all incoming image
00045      * events, even if we don't currently have listeners of our own --
00046      * This is just in case user code directly accesses a generator
00047      * and we have to retroactively go back and dig up the previous
00048      * frame */
00049     unsetAutoListen();
00050     
00051     setNumImages(nLayers,RawCameraGenerator::NUM_CHANNELS);
00052   }
00053   virtual ~BufferedImageGenerator() { destruct(); }
00054   
00055   //! need to override EventGeneratorBase's lazy listening -- as a root stage, need to remember each frame, just in case it might be used
00056   virtual void DoStart() { FilterBankGenerator::DoStart(); addSrcListener(); }
00057 
00058   virtual void processEvent(const EventBase & event);
00059   
00060   virtual unsigned int getBinSize() const;
00061   
00062   virtual unsigned int LoadBuffer(const char buf[], unsigned int len);
00063   
00064   virtual unsigned int SaveBuffer(char buf[], unsigned int len) const;
00065   
00066   virtual unsigned int SaveFileStream(FILE* f) const; //!< overrridden to allow saving direct to file without an extra buffer copy
00067 
00068   virtual unsigned char * getImage(unsigned int layer, unsigned int channel);
00069   virtual void freeCaches();
00070   virtual void invalidateCaches();
00071   
00072 protected:
00073   //! constructor for subclasses
00074   BufferedImageGenerator(const std::string& classname,const std::string& instancename,EventBase::EventGeneratorID_t mgid, unsigned int msid, unsigned int nLayers,EventBase::EventGeneratorID_t srcgid, unsigned int srcsid)
00075     : FilterBankGenerator(classname,instancename,mgid,msid,srcgid,srcsid), imgsrc(), isAllocated(NULL), accessed(true)
00076   {setNumImages(nLayers,RawCameraGenerator::NUM_CHANNELS);}
00077   
00078   virtual unsigned char * createImageCache(unsigned int layer, unsigned int channel) const;
00079   virtual void calcImage(unsigned int layer, unsigned int channel) ;
00080   virtual void setDimensions();
00081   virtual void destruct();
00082   virtual void setNumImages(unsigned int nLayers, unsigned int nChannels);
00083 
00084   //! duplicates pixels to make a higher resolution version of @a srcLayer, @a chan into @a destLayer, @a chan
00085   /*! Doesn't do anything fancy like blurring or smoothing */
00086   virtual void upsampleImage(unsigned int srcLayer, unsigned int chan, unsigned int destLayer);
00087 
00088   ImageSource imgsrc; //!< the data storage of the current image (not the image itself, but meta data a pointer to it)
00089   bool ** isAllocated; //!< for each image in the filterbank, a bool to account whether the pointer is to an external resource or a self-allocated resource
00090   bool accessed; //!< marked true once getImage is called, reset to false with each new image (i.e. processEvent())
00091   
00092 private:
00093   BufferedImageGenerator(const BufferedImageGenerator&); //!< don't call
00094   BufferedImageGenerator& operator=(const BufferedImageGenerator&); //!< don't call
00095 };
00096 
00097 /*! @file
00098  * @brief 
00099  * @author Ethan Tira-Thompson (ejt) (Creator)
00100  *
00101  * $Author: ejt $
00102  * $Name: tekkotsu-2_4_1 $
00103  * $Revision: 1.5 $
00104  * $State: Exp $
00105  * $Date: 2005/08/07 04:11:04 $
00106  */
00107 
00108 #endif

Tekkotsu v2.4.1
Generated Tue Aug 16 16:32:46 2005 by Doxygen 1.4.4