1
// ***************************************************************** -*- C++ -*-
3
* Copyright (C) 2004, 2005 Andreas Huggel <ahuggel@gmx.net>
5
* This program is part of the Exiv2 distribution.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
@brief Exif tag and type information
25
@author Andreas Huggel (ahu)
26
<a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a>
27
@date 15-Jan-04, ahu: created<BR>
28
11-Feb-04, ahu: isolated as a component
33
// *****************************************************************************
34
// included header files
35
#include "metadatum.hpp"
38
// + standard includes
40
#include <utility> // for std::pair
44
// *****************************************************************************
45
// namespace extensions
48
// *****************************************************************************
53
// *****************************************************************************
56
//! Type for a function pointer for functions interpreting the tag value
57
typedef std::ostream& (*PrintFct)(std::ostream&, const Value&);
60
@brief Section identifiers to logically group tags. A section consists
61
of nothing more than a name, based on the Exif standard.
63
enum SectionId { sectionIdNotSet,
64
imgStruct, recOffset, imgCharacter, otherTags, exifFormat,
65
exifVersion, imgConfig, userInfo, relatedFile, dateTime,
66
captureCond, gpsTags, iopTags, makerTags,
69
// *****************************************************************************
72
//! Contains information pertaining to one IFD
75
IfdInfo(IfdId ifdId, const char* name, const char* item);
76
IfdId ifdId_; //!< IFD id
77
const char* name_; //!< IFD name
78
//! Related IFD item. This is also an IFD name, unique for each IFD.
82
//! Contains information pertaining to one section
85
SectionInfo(SectionId sectionId, const char* name, const char* desc);
86
SectionId sectionId_; //!< Section id
87
const char* name_; //!< Section name (one word)
88
const char* desc_; //!< Section description
103
uint16_t tag_; //!< Tag
104
const char* name_; //!< One word tag label
105
const char* desc_; //!< Short tag description
106
IfdId ifdId_; //!< Link to the (prefered) IFD
107
SectionId sectionId_; //!< Section id
108
TypeId typeId_; //!< Type id
109
PrintFct printFct_; //!< Pointer to tag print function
113
@brief Helper structure for lookup tables for translations of numeric
114
tag values to human readable labels.
117
long val_; //!< Tag value
118
const char* label_; //!< Translation of the tag value
119
}; // struct TagDetails
122
@brief Translation from numeric values from a lookup list to human
125
class TagTranslator {
129
//! Default constructor.
130
explicit TagTranslator(const TagDetails* pTagDetails)
131
: pTagDetails_(pTagDetails) {}
132
// No d'tor: Do not delete the list.
137
//! Translate the tag value and write it out to the provided stream
138
std::ostream& print(std::ostream& os, const Value& value) const;
141
const TagDetails* pTagDetails_;
142
}; // class TagTranslator
144
//! Container for Exif tag information. Implemented as a static class.
146
//! Prevent construction: not implemented.
148
//! Prevent copy-construction: not implemented.
149
ExifTags(const ExifTags& rhs);
150
//! Prevent assignment: not implemented.
151
ExifTags& operator=(const ExifTags& rhs);
155
@brief Return the name of the tag or a string with the hexadecimal
156
value of the tag in the form "0x01ff", if the tag is not
161
@return The name of the tag or a string containing the hexadecimal
162
value of the tag in the form "0x01ff", if this is an unknown
165
static std::string tagName(uint16_t tag, IfdId ifdId);
167
@brief Return the description of the tag.
170
@return The description of the tag or a string indicating that
173
static const char* tagDesc(uint16_t tag, IfdId ifdId);
175
@brief Return the tag for one combination of IFD id and tagName.
176
If the tagName is not known, it expects tag names in the
177
form "0x01ff" and converts them to unsigned integer.
179
@throw Error if the tagname or ifdId is invalid
181
static uint16_t tag(const std::string& tagName, IfdId ifdId);
182
//! Return the IFD id for an IFD item
183
static IfdId ifdIdByIfdItem(const std::string& ifdItem);
184
//! Return the name of the IFD
185
static const char* ifdName(IfdId ifdId);
186
//! Return the related image item (image or thumbnail)
187
static const char* ifdItem(IfdId ifdId);
188
//! Return the name of the section
189
static const char* sectionName(SectionId sectionId);
191
@brief Return the name of the section for a combination of
195
@return The name of the section or a string indicating that the
196
section or the tag is unknown.
198
static const char* sectionName(uint16_t tag, IfdId ifdId);
200
@brief Return the description of the section for a combination of
204
@return The description of the section or a string indicating that
205
the section or the tag is unknown.
207
static const char* sectionDesc(uint16_t tag, IfdId ifdId);
208
//! Return the section id for a section name
209
static SectionId sectionId(const std::string& sectionName);
210
//! Return the type for tag and IFD id
211
static TypeId tagType(uint16_t tag, IfdId ifdId);
212
//! Interpret and print the value of an Exif tag
213
static std::ostream& printTag(std::ostream& os,
217
//! Print a list of all standard Exif tags to output stream
218
static void taglist(std::ostream& os);
219
//! Print a list of all tags related to one makernote %IfdId
220
static void makerTaglist(std::ostream& os, IfdId ifdId);
221
//! Register an %IfdId with the base IFD %TagInfo list for a makernote
222
static void registerBaseTagInfo(IfdId ifdId);
224
@brief Register an %IfdId and %TagInfo list for a makernote
226
@throw Error if the MakerTagInfo registry is full
228
static void registerMakerTagInfo(IfdId ifdId, const TagInfo* tagInfo);
230
@brief Return true if \em ifdId is an %Ifd Id which is registered
231
as a makernote %Ifd id. Note: Calling this function with
232
makerIfd returns false.
234
static bool isMakerIfd(IfdId ifdId);
237
static int tagInfoIdx(uint16_t tag, IfdId ifdId);
238
static const TagInfo* makerTagInfo(uint16_t tag, IfdId ifdId);
239
static const TagInfo* makerTagInfo(const std::string& tagName,
242
static const IfdInfo ifdInfo_[];
243
static const SectionInfo sectionInfo_[];
245
static const TagInfo* tagInfos_[];
247
static const int MAX_MAKER_TAG_INFOS = 64;
248
static const TagInfo* makerTagInfos_[MAX_MAKER_TAG_INFOS];
249
static IfdId makerIfdIds_[MAX_MAKER_TAG_INFOS];
254
@brief Concrete keys for Exif metadata.
256
class ExifKey : public Key {
258
//! Shortcut for an %ExifKey auto pointer.
259
typedef std::auto_ptr<ExifKey> AutoPtr;
264
@brief Constructor to create an Exif key from a key string.
266
@param key The key string.
267
@throw Error if the first part of the key is not '<b>Exif</b>' or
268
the remainin parts of the key cannot be parsed and
269
converted to an ifd-item and tag name.
271
explicit ExifKey(const std::string& key);
273
@brief Constructor to create an Exif key from a tag and IFD item
275
@param tag The tag value
276
@param ifdItem The IFD string. For MakerNote tags, this must be the
277
IFD item of the specific MakerNote. "MakerNote" is not allowed.
278
@throw Error if the key cannot be constructed from the tag and IFD
281
ExifKey(uint16_t tag, const std::string& ifdItem);
282
//! Constructor to build an ExifKey from an IFD entry.
283
explicit ExifKey(const Entry& e);
285
ExifKey(const ExifKey& rhs);
289
//! @name Manipulators
292
@brief Assignment operator.
294
ExifKey& operator=(const ExifKey& rhs);
299
virtual std::string key() const { return key_; }
300
virtual const char* familyName() const { return familyName_; }
302
@brief Return the name of the group (the second part of the key).
303
For Exif keys, the group name is the IFD item.
305
virtual std::string groupName() const { return ifdItem(); }
306
virtual std::string tagName() const;
307
virtual uint16_t tag() const { return tag_; }
309
AutoPtr clone() const;
310
//! Return the IFD id
311
IfdId ifdId() const { return ifdId_; }
312
//! Return the name of the IFD
313
const char* ifdName() const { return ExifTags::ifdName(ifdId()); }
314
//! Return the related image item
315
std::string ifdItem() const { return ifdItem_; }
316
//! Return the name of the Exif section (deprecated)
317
std::string sectionName() const;
318
//! Return the index (unique id of this key within the original IFD)
319
int idx() const { return idx_; }
323
//! @name Manipulators
326
@brief Set the key corresponding to the tag and IFD id.
327
The key is of the form '<b>Exif</b>.ifdItem.tagName'.
331
@brief Parse and convert the key string into tag and IFD Id.
332
Updates data members if the string can be decomposed,
333
or throws \em Error .
335
@throw Error if the key cannot be decomposed.
341
//! Internal virtual copy constructor.
342
virtual ExifKey* clone_() const;
345
static const char* familyName_;
347
uint16_t tag_; //!< Tag value
348
IfdId ifdId_; //!< The IFD associated with this tag
349
std::string ifdItem_; //!< The IFD item
350
int idx_; //!< Unique id of an entry within one IFD
351
std::string key_; //!< Key
354
// *****************************************************************************
358
@brief Return true if \em ifdId is an Exif %Ifd Id, i.e., one of
359
ifd0Id, exifIfdId, gpsIfdId, iopIfdId or ifd1Id, else false.
360
This is used to differentiate between standard Exif %Ifds
361
and %Ifds associated with the makernote.
363
bool isExifIfd(IfdId ifdId);
365
//! Output operator for TagInfo
366
std::ostream& operator<<(std::ostream& os, const TagInfo& ti);
368
//! @name Functions printing interpreted tag values
370
//! Default print function, using the Value output operator
371
std::ostream& printValue(std::ostream& os, const Value& value);
372
//! Print the value converted to a long
373
std::ostream& printLong(std::ostream& os, const Value& value);
374
//! Print a Rational or URational value in floating point format
375
std::ostream& printFloat(std::ostream& os, const Value& value);
376
//! Print the unit for measuring X and Y resolution
377
std::ostream& printUnit(std::ostream& os, const Value& value);
379
//! Print the compression scheme used for the image data
380
std::ostream& print0x0103(std::ostream& os, const Value& value);
381
//! Print the pixel composition
382
std::ostream& print0x0106(std::ostream& os, const Value& value);
383
//! Print the orientation
384
std::ostream& print0x0112(std::ostream& os, const Value& value);
385
//! Print the YCbCrPositioning
386
std::ostream& print0x0213(std::ostream& os, const Value& value);
387
//! Print the Copyright
388
std::ostream& print0x8298(std::ostream& os, const Value& value);
389
//! Print the Exposure time
390
std::ostream& print0x829a(std::ostream& os, const Value& value);
391
//! Print the F number
392
std::ostream& print0x829d(std::ostream& os, const Value& value);
393
//! Print the Exposure mode
394
std::ostream& print0x8822(std::ostream& os, const Value& value);
395
//! Print ISO speed ratings
396
std::ostream& print0x8827(std::ostream& os, const Value& value);
397
//! Print components configuration specific to compressed data
398
std::ostream& print0x9101(std::ostream& os, const Value& value);
399
//! Print the exposure bias value
400
std::ostream& print0x9204(std::ostream& os, const Value& value);
401
//! Print the subject distance
402
std::ostream& print0x9206(std::ostream& os, const Value& value);
403
//! Print the metering mode
404
std::ostream& print0x9207(std::ostream& os, const Value& value);
405
//! Print the light source
406
std::ostream& print0x9208(std::ostream& os, const Value& value);
407
//! Print the flash status
408
std::ostream& print0x9209(std::ostream& os, const Value& value);
409
//! Print the actual focal length of the lens
410
std::ostream& print0x920a(std::ostream& os, const Value& value);
411
//! Print the user comment
412
std::ostream& print0x9286(std::ostream& os, const Value& value);
413
//! Print color space information
414
std::ostream& print0xa001(std::ostream& os, const Value& value);
415
//! Print info on image sensor type on the camera or input device
416
std::ostream& print0xa217(std::ostream& os, const Value& value);
417
//! Print file source
418
std::ostream& print0xa300(std::ostream& os, const Value& value);
420
std::ostream& print0xa301(std::ostream& os, const Value& value);
421
//! Print the exposure mode
422
std::ostream& print0xa402(std::ostream& os, const Value& value);
423
//! Print white balance information
424
std::ostream& print0xa403(std::ostream& os, const Value& value);
425
//! Print digital zoom ratio
426
std::ostream& print0xa404(std::ostream& os, const Value& value);
427
//! Print 35mm equivalent focal length
428
std::ostream& print0xa405(std::ostream& os, const Value& value);
429
//! Print scene capture type
430
std::ostream& print0xa406(std::ostream& os, const Value& value);
431
//! Print overall image gain adjustment
432
std::ostream& print0xa407(std::ostream& os, const Value& value);
433
//! Print contract adjustment
434
std::ostream& print0xa408(std::ostream& os, const Value& value);
435
//! Print saturation adjustment
436
std::ostream& print0xa409(std::ostream& os, const Value& value);
437
//! Print sharpness adjustment
438
std::ostream& print0xa40a(std::ostream& os, const Value& value);
439
//! Print subject distance range
440
std::ostream& print0xa40c(std::ostream& os, const Value& value);
444
#endif // #ifndef TAGS_HPP_