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