pfs.h

Go to the documentation of this file.
00001 
00040 #ifndef PFS_H
00041 #define PFS_H
00042 
00043 #include <stdio.h>
00044 #include <string.h>
00045 #include "array2d.h"
00046 
00047 struct option;
00048 
00052 namespace pfs
00053 {
00054 
00064   template<class T>
00065     class SelfDestructPtr
00066     {
00067       T *ptr;
00068       mutable bool itsOwn;
00069     public:
00070       explicit SelfDestructPtr( T *ptr = 0 ): ptr(ptr), itsOwn(ptr!=0)
00071         {
00072         }
00073 
00074       SelfDestructPtr( const SelfDestructPtr& r ) 
00075         : itsOwn(r.itsOwn), ptr(r.release()) {}
00076       
00077       SelfDestructPtr& operator=( const SelfDestructPtr& r ) {
00078         if (&r != this) {
00079             if (ptr != r.ptr) {
00080               if( itsOwn ) delete ptr;
00081               itsOwn = r.itsOwn;
00082             }
00083             else if( r.itsOwn ) itsOwn = true;
00084             ptr = r.release();
00085         }
00086         return *this;
00087       }
00088       
00089       ~SelfDestructPtr()
00090         {
00091           if( itsOwn ) 
00092             delete ptr;
00093         }  
00094 
00095       bool operator==( const SelfDestructPtr &x ) const {
00096         return *(ptr) == *(x.ptr);
00097       }
00098 
00099       bool operator!=( const SelfDestructPtr &x ) const {
00100         return *(ptr) != *(x.ptr);
00101       }
00102       
00103       T& operator*()  const            {return *ptr;}
00104       T* operator->() const            {return ptr;}
00105       T* get()        const            {return ptr;}
00106       T* release()    const  {itsOwn = false; return ptr;}
00107       
00108     };
00109   
00110   
00115   class TagIterator 
00116     {
00117     public:
00123       virtual const char *getNext() = 0;
00127       virtual bool hasNext() const = 0;
00128     };
00129 
00130   typedef SelfDestructPtr<TagIterator> TagIteratorPtr;
00131   
00135   class TagContainer
00136     {
00137     public:
00143       virtual const char* getString( const char *tagName ) = 0;
00144 
00150       virtual void setString( const char *tagName, const char *tagValue ) = 0;
00151       
00156       virtual void removeTag( const char *tagName ) = 0;
00157 
00174       virtual TagIteratorPtr getIterator() const = 0;
00175     };
00176 
00177 
00182   class Channel : public Array2D {
00183   public:
00188     int getWidth() const {
00189       return getCols();
00190     }
00191 
00196     virtual int getHeight() const
00197       {
00198         return getRows();
00199       }
00200 
00204     virtual const char *getName() const = 0;
00205         
00210     virtual TagContainer *getTags() = 0;
00211 
00220     virtual float *getRawData() = 0;
00221   };
00222 
00226   class ChannelIterator 
00227     {
00228     public:
00232       virtual Channel *getNext() = 0;
00236       virtual bool hasNext() const = 0;
00237     };
00238   
00239   typedef SelfDestructPtr<ChannelIterator> ChannelIteratorPtr;
00240   
00247   class Frame {
00248   public:
00252     virtual int getWidth() const = 0;
00253 
00257     virtual int getHeight() const = 0;
00258 
00269     virtual void getXYZChannels( Channel* &X, Channel* &Y, Channel* &Z ) = 0;
00270 
00281     virtual void createXYZChannels( Channel* &X, Channel* &Y, Channel* &Z ) = 0;
00282 
00290     virtual Channel* getChannel( const char *name ) = 0;
00291 
00304     virtual Channel* createChannel( const char *name ) = 0;
00305 
00306 
00313     virtual void removeChannel( Channel *channel ) = 0;
00314     
00328     virtual ChannelIterator *getChannels() = 0;
00329     
00346     virtual ChannelIteratorPtr getChannelIterator() = 0;
00347     
00352     virtual TagContainer *getTags() = 0;
00353 
00354     virtual ~Frame() = 0;
00355     
00356   };
00357 
00367   void copyTags( Frame *from, Frame *to );
00368   
00375   void copyTags( const TagContainer *from, TagContainer *to );
00376 
00377   
00378   class DOMIOImpl;
00379 
00383   class DOMIO {
00384     DOMIOImpl *impl;
00385   public:
00386     DOMIO();
00387     ~DOMIO();
00388 
00403     Frame *createFrame( int width, int height );
00404 
00417     Frame *readFrame( FILE *inputStream );
00418 
00426     void writeFrame( Frame *frame, FILE *outputStream );
00427 
00435     void freeFrame( Frame *frame );
00436   };
00437 
00438 
00439 
00444   struct FrameFile
00445   {
00446     FrameFile( FILE *fh, const char* fileName ): fh(fh), fileName( fileName )
00447     {
00448     }
00449 
00453     FILE *fh;
00454 
00458     const char *fileName;
00459   };
00460 
00461 
00462   class FrameFileIteratorImpl;
00463 
00471   class FrameFileIterator
00472     {
00473       FrameFileIteratorImpl *impl;
00474     public:
00499       FrameFileIterator( int &argc, char* argv[], const char *fopenMode,
00500         const char *fileNamePrefix = NULL, FILE *stdinout = NULL,
00501         const char *optstring = NULL, const struct option *getopt_long = NULL );
00502       ~FrameFileIterator();
00503 
00517       FrameFile getNextFrameFile( );
00518 
00524       void closeFrameFile( FrameFile &frameFile );
00525 
00526       static void printUsage( FILE *out, const char *progName );
00527 
00528     };
00529 
00530 
00532   enum ColorSpace
00533     {
00534       CS_XYZ = 0,         
00535       CS_RGB,             
00536       CS_SRGB,            
00537 
00538 
00539 
00540 
00541 
00542       CS_YUV,             
00543       CS_Yxy,              
00544       CS_LAST             
00545     };
00546 
00561   void transformColorSpace( ColorSpace inCS,
00562     const Array2D *inC1, const Array2D *inC2, const Array2D *inC3,
00563     ColorSpace outCS,
00564     Array2D *outC1, Array2D *outC2, Array2D *outC3 );
00565 
00566 
00570   class Exception
00571     {
00572       char msg[1024];
00573     public:
00581       Exception( const char* const message )
00582   {
00583           strcpy( msg, message );
00584   }
00585       
00586       ~Exception() {};
00587 
00593       const char* getMessage()
00594         {
00595           return msg;
00596   }
00597     };
00598 
00599 
00603   class CommandLineException: public Exception
00604     {
00605     public:
00606       CommandLineException( const char* const message ): Exception( message )
00607   {
00608   }
00609     };
00610 
00611 
00612 }
00613 
00614 
00615 
00616 #endif

Generated on Tue Nov 25 17:23:48 2008 for Portable Floating-point Streams (pfstools) by  doxygen 1.5.3