00001 #ifndef IMAGE_FILEINPUT_H 00002 #define IMAGE_FILEINPUT_H 00003 00004 #include <list> 00005 #include <map> 00006 #include <Magick++.h> 00007 #include "image_input.h" 00008 #include "rgba.h" 00009 00010 namespace mimas { 00011 00045 template< typename T > 00046 class image_fileinput: public image_input< T > 00047 { 00048 public: 00052 explicit image_fileinput( std::istream &_stream ): stream( &_stream ) {} 00058 virtual void read( image< T > &image ) throw (mimasexception); 00063 static std::map< std::string, bool > formats(void); 00064 protected: 00068 static const char *mapString(void); 00070 std::istream *stream; 00072 boost::shared_ptr< std::list< Magick::Image > > images; 00073 }; 00074 00075 template<> 00076 const char *image_fileinput< unsigned char >::mapString(void); 00077 00078 template<> 00079 const char *image_fileinput< rgba< unsigned char > >::mapString(void); 00080 00082 template< typename T, typename U > 00083 inline image_fileinput< T > &operator>>( image_fileinput< T > &input, 00084 image< U > &im ) 00085 { 00086 if ( typeid( T ) == typeid( U ) ) 00087 input.read( (image< T > &)im ); 00088 else { 00089 image< T > temp; 00090 input.read( temp ); 00091 im = image< U >( temp ); 00092 }; 00093 return input; 00094 } 00095 00097 inline std::istream &operator>>( std::istream &stream, image< unsigned char > &im ) 00098 { 00099 image_fileinput< unsigned char > input( stream ); 00100 try { 00101 input >> im; 00102 } catch ( mimasexception & ) { 00103 stream.setstate( std::ios_base::failbit ); 00104 }; 00105 return stream; 00106 } 00107 00109 inline std::istream &operator>>( std::istream &stream, 00110 image< int > &im ) 00111 { 00112 image_fileinput< unsigned char > input( stream ); 00113 try { 00114 input >> im; 00115 } catch ( mimasexception & ) { 00116 stream.setstate( std::ios_base::failbit ); 00117 }; 00118 return stream; 00119 } 00120 00122 inline std::istream &operator>>( std::istream &stream, 00123 image< float > &im ) 00124 { 00125 image_fileinput< unsigned char > input( stream ); 00126 try { 00127 input >> im; 00128 } catch ( mimasexception & ) { 00129 stream.setstate( std::ios_base::failbit ); 00130 }; 00131 return stream; 00132 } 00133 00135 inline std::istream &operator>>( std::istream &stream, 00136 image< double > &im ) 00137 { 00138 image_fileinput< unsigned char > input( stream ); 00139 try { 00140 input >> im; 00141 } catch ( mimasexception & ) { 00142 stream.setstate( std::ios_base::failbit ); 00143 }; 00144 return stream; 00145 } 00146 00148 inline std::istream &operator>>( std::istream &stream, 00149 image< rgba< unsigned char > > 00150 &im ) 00151 { 00152 image_fileinput< rgba< unsigned char > > input( stream ); 00153 try { 00154 input >> im; 00155 } catch ( mimasexception & ) { 00156 stream.setstate( std::ios_base::failbit ); 00157 }; 00158 return stream; 00159 } 00160 00162 inline std::istream &operator>>( std::istream &stream, 00163 image< rgba< int > > 00164 &im ) 00165 { 00166 image_fileinput< rgba< unsigned char > > input( stream ); 00167 try { 00168 input >> im; 00169 } catch ( mimasexception & ) { 00170 stream.setstate( std::ios_base::failbit ); 00171 }; 00172 return stream; 00173 } 00174 00176 inline std::istream &operator>>( std::istream &stream, 00177 image< rgba< double > > 00178 &im ) 00179 { 00180 image_fileinput< rgba< unsigned char > > input( stream ); 00181 try { 00182 input >> im; 00183 } catch ( mimasexception & ) { 00184 stream.setstate( std::ios_base::failbit ); 00185 }; 00186 return stream; 00187 } 00188 00190 inline std::istream &operator>>( std::istream &stream, 00191 image< rgba< float > > 00192 &im ) 00193 { 00194 image_fileinput< rgba< unsigned char > > input( stream ); 00195 try { 00196 input >> im; 00197 } catch ( mimasexception & ) { 00198 stream.setstate( std::ios_base::failbit ); 00199 }; 00200 return stream; 00201 } 00202 00204 00206 00207 }; 00208 00209 #include "image_fileinput.tcc" 00210 00211 #endif