[8f0f49]: src / foreign / vigra / codec.hxx  Maximize  Restore  History

Download this file

255 lines (208 with data), 8.9 kB

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

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks