[ 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.3.2, Jan 27 2005 ) */ 00008 /* You may use, modify, and distribute this software according */ 00009 /* to the terms stated in the LICENSE file included in */ 00010 /* the VIGRA distribution. */ 00011 /* */ 00012 /* The VIGRA Website is */ 00013 /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ 00014 /* Please direct questions, bug reports, and contributions to */ 00015 /* koethe@informatik.uni-hamburg.de */ 00016 /* */ 00017 /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ 00018 /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ 00019 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ 00020 /* */ 00021 /************************************************************************/ 00022 00023 #ifndef VIGRA_CODEC_HXX 00024 #define VIGRA_CODEC_HXX 00025 00026 #include <memory> 00027 #include <string> 00028 #include <vector> 00029 00030 // possible pixel types: 00031 // "undefined", "UINT8", "INT16", "INT32", "FLOAT", "DOUBLE" 00032 00033 // possible compression types: 00034 // "undefined", "RLE", "LZW", "LOSSLESS", "JPEG" 00035 00036 // possible file types: 00037 // "undefined", "TIFF", "VIFF", "JPEG", "PNG", "PNM", "BMP", "SUN", "XPM" 00038 00039 // possible name extensions: 00040 // "undefined", "tif", "tiff", "jpg", "jpeg", "png", "pnm", "bmp", "sun", 00041 // "xpm" (also capital forms) 00042 00043 namespace vigra 00044 { 00045 template <class T> 00046 struct TypeAsString 00047 { 00048 static std::string result() { return "undefined"; } 00049 }; 00050 00051 template <> 00052 struct TypeAsString<unsigned char> 00053 { 00054 static std::string result() { return "UINT8"; } 00055 }; 00056 00057 template <> 00058 struct TypeAsString<short> 00059 { 00060 static std::string result() { return "INT16"; } 00061 }; 00062 00063 template <> 00064 struct TypeAsString<int> 00065 { 00066 static std::string result() { return "INT32"; } 00067 }; 00068 00069 template <> 00070 struct TypeAsString<long> 00071 { 00072 static std::string result() { return "INT32"; } 00073 }; 00074 00075 template <> 00076 struct TypeAsString<float> 00077 { 00078 static std::string result() { return "FLOAT"; } 00079 }; 00080 00081 template <> 00082 struct TypeAsString<double> 00083 { 00084 static std::string result() { return "DOUBLE"; } 00085 }; 00086 00087 00088 // codec description 00089 struct CodecDesc 00090 { 00091 std::string fileType; 00092 std::vector<std::string> pixelTypes; 00093 std::vector<std::string> compressionTypes; 00094 std::vector<std::vector<char> > magicStrings; 00095 std::vector<std::string> fileExtensions; 00096 std::vector<int> bandNumbers; 00097 }; 00098 00099 // Decoder and Encoder are pure virtual types that define a common 00100 // interface for all image file formats impex supports. 00101 00102 struct Decoder 00103 { 00104 virtual ~Decoder() {}; 00105 virtual void init( const std::string & ) = 0; 00106 virtual void close() = 0; 00107 virtual void abort() = 0; 00108 00109 virtual std::string getFileType() const = 0; 00110 virtual std::string getPixelType() const = 0; 00111 00112 virtual unsigned int getWidth() const = 0; 00113 virtual unsigned int getHeight() const = 0; 00114 virtual unsigned int getNumBands() const = 0; 00115 virtual unsigned int getOffset() const = 0; 00116 00117 virtual const void * currentScanlineOfBand( unsigned int ) const = 0; 00118 virtual void nextScanline() = 0; 00119 }; 00120 00121 struct Encoder 00122 { 00123 virtual ~Encoder() {}; 00124 virtual void init( const std::string & ) = 0; 00125 virtual void close() = 0; 00126 virtual void abort() = 0; 00127 00128 virtual std::string getFileType() const = 0; 00129 virtual unsigned int getOffset() const = 0; 00130 00131 virtual void setWidth( unsigned int ) = 0; 00132 virtual void setHeight( unsigned int ) = 0; 00133 virtual void setNumBands( unsigned int ) = 0; 00134 virtual void setCompressionType( const std::string &, int = -1 ) = 0; 00135 virtual void setPixelType( const std::string & ) = 0; 00136 virtual void finalizeSettings() = 0; 00137 00138 virtual void * currentScanlineOfBand( unsigned int ) = 0; 00139 virtual void nextScanline() = 0; 00140 00141 struct TIFFNoLZWException {}; 00142 }; 00143 00144 // codec factory for registration at the codec manager 00145 00146 struct CodecFactory 00147 { 00148 virtual CodecDesc getCodecDesc() const = 0; 00149 virtual std::auto_ptr<Decoder> getDecoder() const = 0; 00150 virtual std::auto_ptr<Encoder> getEncoder() const = 0; 00151 }; 00152 00153 // factory functions to encapsulate the codec managers 00154 // 00155 // codecs are selected according to the following order: 00156 // - (if provided) the FileType 00157 // - (in case of decoders) the file's magic string 00158 // - the filename extension 00159 00160 std::auto_ptr<Decoder> 00161 getDecoder( const std::string &, const std::string & = "undefined" ); 00162 00163 std::auto_ptr<Encoder> 00164 getEncoder( const std::string &, const std::string & = "undefined" ); 00165 00166 // functions to query the capabilities of certain codecs 00167 00168 std::vector<std::string> queryCodecPixelTypes( const std::string & ); 00169 00170 bool negotiatePixelType( std::string const & codecname, 00171 std::string const & srcPixeltype, std::string & destPixeltype); 00172 00173 bool isPixelTypeSupported( const std::string &, const std::string & ); 00174 00175 bool isBandNumberSupported( const std::string &, int bands ); 00176 } 00177 00178 #endif // VIGRA_CODEC_HXX
© Ullrich Köthe (koethe@informatik.uni-hamburg.de) |
html generated using doxygen and Python
|