[ VIGRA Homepage | Class Index | Function Index | File Index | Main Page ]
![]() |
vigra/codec.hxx | ![]() |
---|
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.4.0, Dec 21 2005 ) */ 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 /* koethe@informatik.uni-hamburg.de or */ 00012 /* vigra@kogs1.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 #ifndef VIGRA_CODEC_HXX 00039 #define VIGRA_CODEC_HXX 00040 00041 #include <memory> 00042 #include <string> 00043 #include <vector> 00044 00045 // possible pixel types: 00046 // "undefined", "UINT8", "INT16", "INT32", "FLOAT", "DOUBLE" 00047 00048 // possible compression types: 00049 // "undefined", "RLE", "LZW", "LOSSLESS", "JPEG" 00050 00051 // possible file types: 00052 // "undefined", "TIFF", "VIFF", "JPEG", "PNG", "PNM", "BMP", "SUN", "XPM" 00053 00054 // possible name extensions: 00055 // "undefined", "tif", "tiff", "jpg", "jpeg", "png", "pnm", "bmp", "sun", 00056 // "xpm" (also capital forms) 00057 00058 namespace vigra 00059 { 00060 template <class T> 00061 struct TypeAsString 00062 { 00063 static std::string result() { return "undefined"; } 00064 }; 00065 00066 template <> 00067 struct TypeAsString<unsigned char> 00068 { 00069 static std::string result() { return "UINT8"; } 00070 }; 00071 00072 template <> 00073 struct TypeAsString<short> 00074 { 00075 static std::string result() { return "INT16"; } 00076 }; 00077 00078 template <> 00079 struct TypeAsString<int> 00080 { 00081 static std::string result() { return "INT32"; } 00082 }; 00083 00084 template <> 00085 struct TypeAsString<long> 00086 { 00087 static std::string result() { return "INT32"; } 00088 }; 00089 00090 template <> 00091 struct TypeAsString<float> 00092 { 00093 static std::string result() { return "FLOAT"; } 00094 }; 00095 00096 template <> 00097 struct TypeAsString<double> 00098 { 00099 static std::string result() { return "DOUBLE"; } 00100 }; 00101 00102 00103 // codec description 00104 struct CodecDesc 00105 { 00106 std::string fileType; 00107 std::vector<std::string> pixelTypes; 00108 std::vector<std::string> compressionTypes; 00109 std::vector<std::vector<char> > magicStrings; 00110 std::vector<std::string> fileExtensions; 00111 std::vector<int> bandNumbers; 00112 }; 00113 00114 // Decoder and Encoder are pure virtual types that define a common 00115 // interface for all image file formats impex supports. 00116 00117 struct Decoder 00118 { 00119 virtual ~Decoder() {}; 00120 virtual void init( const std::string & ) = 0; 00121 virtual void close() = 0; 00122 virtual void abort() = 0; 00123 00124 virtual std::string getFileType() const = 0; 00125 virtual std::string getPixelType() const = 0; 00126 00127 virtual unsigned int getWidth() const = 0; 00128 virtual unsigned int getHeight() const = 0; 00129 virtual unsigned int getNumBands() const = 0; 00130 virtual unsigned int getOffset() const = 0; 00131 00132 virtual const void * currentScanlineOfBand( unsigned int ) const = 0; 00133 virtual void nextScanline() = 0; 00134 }; 00135 00136 struct Encoder 00137 { 00138 virtual ~Encoder() {}; 00139 virtual void init( const std::string & ) = 0; 00140 virtual void close() = 0; 00141 virtual void abort() = 0; 00142 00143 virtual std::string getFileType() const = 0; 00144 virtual unsigned int getOffset() const = 0; 00145 00146 virtual void setWidth( unsigned int ) = 0; 00147 virtual void setHeight( unsigned int ) = 0; 00148 virtual void setNumBands( unsigned int ) = 0; 00149 virtual void setCompressionType( const std::string &, int = -1 ) = 0; 00150 virtual void setPixelType( const std::string & ) = 0; 00151 virtual void finalizeSettings() = 0; 00152 00153 virtual void * currentScanlineOfBand( unsigned int ) = 0; 00154 virtual void nextScanline() = 0; 00155 00156 struct TIFFNoLZWException {}; 00157 }; 00158 00159 // codec factory for registration at the codec manager 00160 00161 struct CodecFactory 00162 { 00163 virtual CodecDesc getCodecDesc() const = 0; 00164 virtual std::auto_ptr<Decoder> getDecoder() const = 0; 00165 virtual std::auto_ptr<Encoder> getEncoder() const = 0; 00166 }; 00167 00168 // factory functions to encapsulate the codec managers 00169 // 00170 // codecs are selected according to the following order: 00171 // - (if provided) the FileType 00172 // - (in case of decoders) the file's magic string 00173 // - the filename extension 00174 00175 std::auto_ptr<Decoder> 00176 getDecoder( const std::string &, const std::string & = "undefined" ); 00177 00178 std::auto_ptr<Encoder> 00179 getEncoder( const std::string &, const std::string & = "undefined" ); 00180 00181 // functions to query the capabilities of certain codecs 00182 00183 std::vector<std::string> queryCodecPixelTypes( const std::string & ); 00184 00185 bool negotiatePixelType( std::string const & codecname, 00186 std::string const & srcPixeltype, std::string & destPixeltype); 00187 00188 bool isPixelTypeSupported( const std::string &, const std::string & ); 00189 00190 bool isBandNumberSupported( const std::string &, int bands ); 00191 } 00192 00193 #endif // VIGRA_CODEC_HXX
© Ullrich Köthe (koethe@informatik.uni-hamburg.de) |
html generated using doxygen and Python
|