[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

codec.hxx
1 /************************************************************************/
2 /* */
3 /* Copyright 2001-2002 by Gunnar Kedenburg */
4 /* */
5 /* This file is part of the VIGRA computer vision library. */
6 /* The VIGRA Website is */
7 /* http://hci.iwr.uni-heidelberg.de/vigra/ */
8 /* Please direct questions, bug reports, and contributions to */
9 /* ullrich.koethe@iwr.uni-heidelberg.de or */
10 /* vigra@informatik.uni-hamburg.de */
11 /* */
12 /* Permission is hereby granted, free of charge, to any person */
13 /* obtaining a copy of this software and associated documentation */
14 /* files (the "Software"), to deal in the Software without */
15 /* restriction, including without limitation the rights to use, */
16 /* copy, modify, merge, publish, distribute, sublicense, and/or */
17 /* sell copies of the Software, and to permit persons to whom the */
18 /* Software is furnished to do so, subject to the following */
19 /* conditions: */
20 /* */
21 /* The above copyright notice and this permission notice shall be */
22 /* included in all copies or substantial portions of the */
23 /* Software. */
24 /* */
25 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
26 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
27 /* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
28 /* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
29 /* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
30 /* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
31 /* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
32 /* OTHER DEALINGS IN THE SOFTWARE. */
33 /* */
34 /************************************************************************/
35 
36 /* Modifications by Pablo d'Angelo
37  * updated to vigra 1.4 by Douglas Wilkins
38  * as of 18 Febuary 2006:
39  * - Added UINT16 and UINT32 pixel types.
40  * - Added support for obtaining extra bands beyond RGB.
41  * - Added support for a position field that indicates the start of this
42  * image relative to some global origin.
43  * - Added support for x and y resolution fields.
44  * - Added support for ICC Profiles
45  */
46 
47 #ifndef VIGRA_CODEC_HXX
48 #define VIGRA_CODEC_HXX
49 
50 #include <memory>
51 #include <string>
52 #include <vector>
53 
54 #include "array_vector.hxx"
55 #include "config.hxx"
56 #include "diff2d.hxx"
57 #include "sized_int.hxx"
58 
59 // possible pixel types:
60 // "undefined", "UINT8", "UINT16", "INT16", "UINT32", "INT32", "FLOAT", "DOUBLE"
61 
62 // possible compression types:
63 // "undefined", "RLE", "LZW", "LOSSLESS", "JPEG", "DEFLATE"
64 
65 // possible file types:
66 // "undefined", "TIFF", "VIFF", "JPEG", "PNG", "PNM", "BMP", "SUN", "XPM"
67 
68 // possible name extensions:
69 // "undefined", "tif", "tiff", "jpg", "jpeg", "png", "pnm", "bmp", "sun",
70 // "xpm" (also capital forms)
71 
72 namespace vigra
73 {
74  template <class T>
75  struct TypeAsString
76  {
77  static std::string result() { return "undefined"; }
78  };
79 
80  template <>
81  struct TypeAsString<Int8>
82  {
83  static std::string result() { return "INT8"; }
84  };
85 
86  template <>
87  struct TypeAsString<UInt8>
88  {
89  static std::string result() { return "UINT8"; }
90  };
91 
92  template <>
93  struct TypeAsString<Int16>
94  {
95  static std::string result() { return "INT16"; }
96  };
97 
98  template <>
99  struct TypeAsString<UInt16>
100  {
101  static std::string result() { return "UINT16"; }
102  };
103 
104  template <>
105  struct TypeAsString<Int32>
106  {
107  static std::string result() { return "INT32"; }
108  };
109 
110  template <>
111  struct TypeAsString<UInt32>
112  {
113  static std::string result() { return "UINT32"; }
114  };
115 
116  template <>
117  struct TypeAsString<float>
118  {
119  static std::string result() { return "FLOAT"; }
120  };
121 
122  template <>
123  struct TypeAsString<double>
124  {
125  static std::string result() { return "DOUBLE"; }
126  };
127 
128 
129  // codec description
130  struct CodecDesc
131  {
132  std::string fileType;
133  std::vector<std::string> pixelTypes;
134  std::vector<std::string> compressionTypes;
135  std::vector<std::vector<char> > magicStrings;
136  std::vector<std::string> fileExtensions;
137  std::vector<int> bandNumbers;
138  };
139 
140  // Decoder and Encoder are virtual types that define a common
141  // interface for all image file formats impex supports.
142 
143  struct Decoder
144  {
145  virtual ~Decoder() {};
146  virtual void init( const std::string & ) = 0;
147  virtual void close() = 0;
148  virtual void abort() = 0;
149 
150  virtual std::string getFileType() const = 0;
151  virtual std::string getPixelType() const = 0;
152 
153  virtual unsigned int getWidth() const = 0;
154  virtual unsigned int getHeight() const = 0;
155  virtual unsigned int getNumBands() const = 0;
156  virtual unsigned int getNumExtraBands() const
157  {
158  return 0;
159  }
160 
161  virtual vigra::Diff2D getPosition() const
162  {
163  return vigra::Diff2D();
164  }
165 
166  virtual float getXResolution() const
167  {
168  return 0.0f;
169  }
170  virtual float getYResolution() const
171  {
172  return 0.0f;
173  }
174 
175  virtual unsigned int getOffset() const = 0;
176 
177  virtual const void * currentScanlineOfBand( unsigned int ) const = 0;
178  virtual void nextScanline() = 0;
179 
180  typedef ArrayVector<unsigned char> ICCProfile;
181 
182  const ICCProfile & getICCProfile() const
183  {
184  return iccProfile_;
185  }
186 
187  ICCProfile iccProfile_;
188  };
189 
190  struct Encoder
191  {
192  virtual ~Encoder() {};
193  virtual void init( const std::string & ) = 0;
194  virtual void close() = 0;
195  virtual void abort() = 0;
196 
197  virtual std::string getFileType() const = 0;
198  virtual unsigned int getOffset() const = 0;
199 
200  virtual void setWidth( unsigned int ) = 0;
201  virtual void setHeight( unsigned int ) = 0;
202  virtual void setNumBands( unsigned int ) = 0;
203  virtual void setCompressionType( const std::string &, int = -1 ) = 0;
204  virtual void setPixelType( const std::string & ) = 0;
205  virtual void finalizeSettings() = 0;
206 
207  virtual void setPosition( const vigra::Diff2D & /*pos*/ )
208  {
209  }
210  virtual void setXResolution( float /*xres*/ )
211  {
212  }
213  virtual void setYResolution( float /*yres*/ )
214  {
215  }
216 
217  typedef ArrayVector<unsigned char> ICCProfile;
218 
219  virtual void setICCProfile(const ICCProfile & /* data */)
220  {
221  }
222 
223  virtual void * currentScanlineOfBand( unsigned int ) = 0;
224  virtual void nextScanline() = 0;
225 
226  struct TIFFCompressionException {};
227  };
228 
229  // codec factory for registration at the codec manager
230 
231  struct CodecFactory
232  {
233  virtual CodecDesc getCodecDesc() const = 0;
234  virtual std::auto_ptr<Decoder> getDecoder() const = 0;
235  virtual std::auto_ptr<Encoder> getEncoder() const = 0;
236  virtual ~CodecFactory() {};
237  };
238 
239  // factory functions to encapsulate the codec managers
240  //
241  // codecs are selected according to the following order:
242  // - (if provided) the FileType
243  // - (in case of decoders) the file's magic string
244  // - the filename extension
245 
246  VIGRA_EXPORT std::auto_ptr<Decoder>
247  getDecoder( const std::string &, const std::string & = "undefined" );
248 
249  VIGRA_EXPORT std::auto_ptr<Encoder>
250  getEncoder( const std::string &, const std::string & = "undefined" );
251 
252  VIGRA_EXPORT std::string
253  getEncoderType( const std::string &, const std::string & = "undefined" );
254 
255  // functions to query the capabilities of certain codecs
256 
257  VIGRA_EXPORT std::vector<std::string> queryCodecPixelTypes( const std::string & );
258 
259  VIGRA_EXPORT bool negotiatePixelType( std::string const & codecname,
260  std::string const & srcPixeltype, std::string & destPixeltype);
261 
262  VIGRA_EXPORT bool isPixelTypeSupported( const std::string &, const std::string & );
263 
264  VIGRA_EXPORT bool isBandNumberSupported( const std::string &, int bands );
265 }
266 
267 #endif // VIGRA_CODEC_HXX

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de)
Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany

html generated using doxygen and Python
vigra 1.7.1 (Wed Mar 12 2014)