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