[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]
vigra/codec.hxx | ![]() |
00001 /************************************************************************/ 00002 /* */ 00003 /* Copyright 2001-2002 by Gunnar Kedenburg */ 00004 /* */ 00005 /* This file is part of the VIGRA computer vision library. */ 00006 /* The VIGRA Website is */ 00007 /* http://hci.iwr.uni-heidelberg.de/vigra/ */ 00008 /* Please direct questions, bug reports, and contributions to */ 00009 /* ullrich.koethe@iwr.uni-heidelberg.de or */ 00010 /* vigra@informatik.uni-hamburg.de */ 00011 /* */ 00012 /* Permission is hereby granted, free of charge, to any person */ 00013 /* obtaining a copy of this software and associated documentation */ 00014 /* files (the "Software"), to deal in the Software without */ 00015 /* restriction, including without limitation the rights to use, */ 00016 /* copy, modify, merge, publish, distribute, sublicense, and/or */ 00017 /* sell copies of the Software, and to permit persons to whom the */ 00018 /* Software is furnished to do so, subject to the following */ 00019 /* conditions: */ 00020 /* */ 00021 /* The above copyright notice and this permission notice shall be */ 00022 /* included in all copies or substantial portions of the */ 00023 /* Software. */ 00024 /* */ 00025 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */ 00026 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */ 00027 /* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */ 00028 /* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */ 00029 /* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */ 00030 /* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */ 00031 /* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */ 00032 /* OTHER DEALINGS IN THE SOFTWARE. */ 00033 /* */ 00034 /************************************************************************/ 00035 00036 /* Modifications by Pablo d'Angelo 00037 * updated to vigra 1.4 by Douglas Wilkins 00038 * as of 18 February 2006: 00039 * - Added UINT16 and UINT32 pixel types. 00040 * - Added support for obtaining extra bands beyond RGB. 00041 * - Added support for a position field that indicates the start of this 00042 * image relative to some global origin. 00043 * - Added support for x and y resolution fields. 00044 * - Added support for ICC Profiles 00045 */ 00046 00047 #ifndef VIGRA_CODEC_HXX 00048 #define VIGRA_CODEC_HXX 00049 00050 #include <memory> 00051 #include <string> 00052 #include <vector> 00053 00054 #include "array_vector.hxx" 00055 #include "config.hxx" 00056 #include "diff2d.hxx" 00057 #include "sized_int.hxx" 00058 00059 // possible pixel types: 00060 // "undefined", "UINT8", "UINT16", "INT16", "UINT32", "INT32", "FLOAT", "DOUBLE" 00061 00062 // possible compression types: 00063 // "undefined", "RLE", "LZW", "LOSSLESS", "JPEG", "DEFLATE" 00064 00065 // possible file types: 00066 // "undefined", "TIFF", "VIFF", "JPEG", "PNG", "PNM", "BMP", "SUN", "XPM", "EXR" 00067 00068 // possible name extensions: 00069 // "undefined", "tif", "tiff", "jpg", "jpeg", "png", "pnm", "bmp", "sun", 00070 // "xpm", "exr" (also capital forms) 00071 00072 namespace vigra 00073 { 00074 template <class T> 00075 struct TypeAsString 00076 { 00077 static std::string result() { return "undefined"; } 00078 }; 00079 00080 template <> 00081 struct TypeAsString<Int8> 00082 { 00083 static std::string result() { return "INT8"; } 00084 }; 00085 00086 template <> 00087 struct TypeAsString<UInt8> 00088 { 00089 static std::string result() { return "UINT8"; } 00090 }; 00091 00092 template <> 00093 struct TypeAsString<Int16> 00094 { 00095 static std::string result() { return "INT16"; } 00096 }; 00097 00098 template <> 00099 struct TypeAsString<UInt16> 00100 { 00101 static std::string result() { return "UINT16"; } 00102 }; 00103 00104 template <> 00105 struct TypeAsString<Int32> 00106 { 00107 static std::string result() { return "INT32"; } 00108 }; 00109 00110 template <> 00111 struct TypeAsString<UInt32> 00112 { 00113 static std::string result() { return "UINT32"; } 00114 }; 00115 00116 template <> 00117 struct TypeAsString<float> 00118 { 00119 static std::string result() { return "FLOAT"; } 00120 }; 00121 00122 template <> 00123 struct TypeAsString<double> 00124 { 00125 static std::string result() { return "DOUBLE"; } 00126 }; 00127 00128 00129 // codec description 00130 struct CodecDesc 00131 { 00132 std::string fileType; 00133 std::vector<std::string> pixelTypes; 00134 std::vector<std::string> compressionTypes; 00135 std::vector<std::vector<char> > magicStrings; 00136 std::vector<std::string> fileExtensions; 00137 std::vector<int> bandNumbers; 00138 }; 00139 00140 // Decoder and Encoder are virtual types that define a common 00141 // interface for all image file formats impex supports. 00142 00143 struct Decoder 00144 { 00145 virtual ~Decoder() {}; 00146 virtual void init( const std::string & ) = 0; 00147 00148 // initialize with an image index. For codecs that do not support this feature, the standard init is called. 00149 virtual void init( const std::string & fileName, unsigned int imageIndex) 00150 { 00151 init(fileName); 00152 } 00153 00154 virtual void close() = 0; 00155 virtual void abort() = 0; 00156 00157 virtual std::string getFileType() const = 0; 00158 virtual std::string getPixelType() const = 0; 00159 00160 virtual unsigned int getNumImages() const 00161 { 00162 return 1; 00163 } 00164 00165 virtual void setImageIndex(unsigned int) 00166 { 00167 } 00168 00169 virtual unsigned int getImageIndex() const 00170 { 00171 return 0; 00172 } 00173 00174 virtual unsigned int getWidth() const = 0; 00175 virtual unsigned int getHeight() const = 0; 00176 virtual unsigned int getNumBands() const = 0; 00177 virtual unsigned int getNumExtraBands() const 00178 { 00179 return 0; 00180 } 00181 00182 virtual vigra::Diff2D getPosition() const 00183 { 00184 return vigra::Diff2D(); 00185 } 00186 00187 virtual float getXResolution() const 00188 { 00189 return 0.0f; 00190 } 00191 virtual float getYResolution() const 00192 { 00193 return 0.0f; 00194 } 00195 00196 virtual vigra::Size2D getCanvasSize() const 00197 { 00198 return vigra::Size2D(this->getWidth(), this->getHeight()); 00199 } 00200 00201 virtual unsigned int getOffset() const = 0; 00202 00203 virtual const void * currentScanlineOfBand( unsigned int ) const = 0; 00204 virtual void nextScanline() = 0; 00205 00206 typedef ArrayVector<unsigned char> ICCProfile; 00207 00208 const ICCProfile & getICCProfile() const 00209 { 00210 return iccProfile_; 00211 } 00212 00213 ICCProfile iccProfile_; 00214 }; 00215 00216 struct Encoder 00217 { 00218 virtual ~Encoder() {}; 00219 virtual void init( const std::string & ) = 0; 00220 00221 // initialize with file access mode. For codecs that do not support this feature, the standard init is called. 00222 virtual void init( const std::string & fileName, const std::string & mode ) 00223 { 00224 init(fileName); 00225 } 00226 00227 virtual void close() = 0; 00228 virtual void abort() = 0; 00229 00230 virtual std::string getFileType() const = 0; 00231 virtual unsigned int getOffset() const = 0; 00232 00233 virtual void setWidth( unsigned int ) = 0; 00234 virtual void setHeight( unsigned int ) = 0; 00235 virtual void setNumBands( unsigned int ) = 0; 00236 virtual void setCompressionType( const std::string &, int = -1 ) = 0; 00237 virtual void setPixelType( const std::string & ) = 0; 00238 virtual void finalizeSettings() = 0; 00239 00240 virtual void setPosition( const vigra::Diff2D & /*pos*/ ) 00241 { 00242 } 00243 virtual void setCanvasSize( const vigra::Size2D & /*size*/) 00244 { 00245 } 00246 virtual void setXResolution( float /*xres*/ ) 00247 { 00248 } 00249 virtual void setYResolution( float /*yres*/ ) 00250 { 00251 } 00252 00253 typedef ArrayVector<unsigned char> ICCProfile; 00254 00255 virtual void setICCProfile(const ICCProfile & /* data */) 00256 { 00257 } 00258 00259 virtual void * currentScanlineOfBand( unsigned int ) = 0; 00260 virtual void nextScanline() = 0; 00261 00262 struct TIFFCompressionException {}; 00263 }; 00264 00265 // codec factory for registration at the codec manager 00266 00267 struct CodecFactory 00268 { 00269 virtual CodecDesc getCodecDesc() const = 0; 00270 virtual std::auto_ptr<Decoder> getDecoder() const = 0; 00271 virtual std::auto_ptr<Encoder> getEncoder() const = 0; 00272 virtual ~CodecFactory() {}; 00273 }; 00274 00275 // factory functions to encapsulate the codec managers 00276 // 00277 // codecs are selected according to the following order: 00278 // - (if provided) the FileType 00279 // - (in case of decoders) the file's magic string 00280 // - the filename extension 00281 00282 VIGRA_EXPORT std::auto_ptr<Decoder> 00283 getDecoder( const std::string &, const std::string & = "undefined", unsigned int = 0 ); 00284 00285 VIGRA_EXPORT std::auto_ptr<Encoder> 00286 getEncoder( const std::string &, const std::string & = "undefined", const std::string & = "w" ); 00287 00288 VIGRA_EXPORT std::string 00289 getEncoderType( const std::string &, const std::string & = "undefined" ); 00290 00291 // functions to query the capabilities of certain codecs 00292 00293 VIGRA_EXPORT std::vector<std::string> queryCodecPixelTypes( const std::string & ); 00294 00295 VIGRA_EXPORT bool negotiatePixelType( std::string const & codecname, 00296 std::string const & srcPixeltype, std::string & destPixeltype); 00297 00298 VIGRA_EXPORT bool isPixelTypeSupported( const std::string &, const std::string & ); 00299 00300 VIGRA_EXPORT bool isBandNumberSupported( const std::string &, int bands ); 00301 } 00302 00303 #endif // VIGRA_CODEC_HXX
© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) |
html generated using doxygen and Python
|