| 178 | 
        kaklik | 
        1 | 
        #ifndef IMAGE_INPUT_H | 
      
      
         | 
         | 
        2 | 
        #define IMAGE_INPUT_H | 
      
      
         | 
         | 
        3 | 
          | 
      
      
         | 
         | 
        4 | 
        #include "mimasexception.h" | 
      
      
         | 
         | 
        5 | 
        #include "image.h" | 
      
      
         | 
         | 
        6 | 
          | 
      
      
         | 
         | 
        7 | 
        namespace mimas { | 
      
      
         | 
         | 
        8 | 
          | 
      
      
         | 
         | 
        9 | 
        /** @defgroup imageIO Image I/O | 
      
      
         | 
         | 
        10 | 
            The I/O-facilities for images of mimas are implemented using inheritance. | 
      
      
         | 
         | 
        11 | 
            This makes it possible to write programs, where the input-source and the | 
      
      
         | 
         | 
        12 | 
            output-target for an image (or several images) are exchangable. | 
      
      
         | 
         | 
        13 | 
            @{ */ | 
      
      
         | 
         | 
        14 | 
        /** @defgroup imageInput Image Input | 
      
      
         | 
         | 
        15 | 
            This group contains classes for retrieving image(s) from different input | 
      
      
         | 
         | 
        16 | 
            sources. | 
      
      
         | 
         | 
        17 | 
            @{ */ | 
      
      
         | 
         | 
        18 | 
        /** Abstract base-class for input sources. | 
      
      
         | 
         | 
        19 | 
            This is a base-class for input sources. It allows to implement a program, | 
      
      
         | 
         | 
        20 | 
            which retrieves an image from an arbitrary input-source. E.g.: | 
      
      
         | 
         | 
        21 | 
            \code | 
      
      
         | 
         | 
        22 | 
            using namespace mimas; | 
      
      
         | 
         | 
        23 | 
            ... | 
      
      
         | 
         | 
        24 | 
            void test( image_input< rgba< unsigned char > > &source ) { | 
      
      
         | 
         | 
        25 | 
               image< rgba< unsigned char > > image; | 
      
      
         | 
         | 
        26 | 
               if ( source >> image ) { | 
      
      
         | 
         | 
        27 | 
                 ... | 
      
      
         | 
         | 
        28 | 
               } else { | 
      
      
         | 
         | 
        29 | 
                 // End of input has been reached. | 
      
      
         | 
         | 
        30 | 
               } | 
      
      
         | 
         | 
        31 | 
               ... | 
      
      
         | 
         | 
        32 | 
            }; | 
      
      
         | 
         | 
        33 | 
            ... | 
      
      
         | 
         | 
        34 | 
            \endcode */ | 
      
      
         | 
         | 
        35 | 
        template< typename T > | 
      
      
         | 
         | 
        36 | 
        class image_input: public object | 
      
      
         | 
         | 
        37 | 
        { | 
      
      
         | 
         | 
        38 | 
         public: | 
      
      
         | 
         | 
        39 | 
          /** Constructor. | 
      
      
         | 
         | 
        40 | 
              The state is set to valid (end of stream not encountered yet). */ | 
      
      
         | 
         | 
        41 | 
          image_input(void): state( true ) {} | 
      
      
         | 
         | 
        42 | 
          /** Read image from arbitrary source. | 
      
      
         | 
         | 
        43 | 
              This function is virtual and has to be implemented by the inheriting | 
      
      
         | 
         | 
        44 | 
              class. | 
      
      
         | 
         | 
        45 | 
              @param img Object to store image in. */ | 
      
      
         | 
         | 
        46 | 
          virtual void read( image< T > &img ) throw (mimasexception) = 0; | 
      
      
         | 
         | 
        47 | 
          /// Indicator for input-source being alive. | 
      
      
         | 
         | 
        48 | 
          operator bool(void) const { return state; } | 
      
      
         | 
         | 
        49 | 
          /// Indicator for end of input-source. | 
      
      
         | 
         | 
        50 | 
          bool operator!(void) const { return !state; } | 
      
      
         | 
         | 
        51 | 
         protected: | 
      
      
         | 
         | 
        52 | 
          /// State variable. | 
      
      
         | 
         | 
        53 | 
          bool state; | 
      
      
         | 
         | 
        54 | 
        }; | 
      
      
         | 
         | 
        55 | 
          | 
      
      
         | 
         | 
        56 | 
        /// Stream-operator for arbitrary input-source. | 
      
      
         | 
         | 
        57 | 
        template< typename T > | 
      
      
         | 
         | 
        58 | 
        inline image_input< T > &operator>>( image_input< T > &input, | 
      
      
         | 
         | 
        59 | 
                                                image< T > &img ) | 
      
      
         | 
         | 
        60 | 
        { input.read( img ); return input; } | 
      
      
         | 
         | 
        61 | 
          | 
      
      
         | 
         | 
        62 | 
        ///@} | 
      
      
         | 
         | 
        63 | 
          | 
      
      
         | 
         | 
        64 | 
        ///@} | 
      
      
         | 
         | 
        65 | 
          | 
      
      
         | 
         | 
        66 | 
        }; | 
      
      
         | 
         | 
        67 | 
          | 
      
      
         | 
         | 
        68 | 
        #endif |