~noskcaj/ubuntu/trusty/libextractor/merge

« back to all changes in this revision

Viewing changes to src/plugins/exiv2/tags.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-11-17 20:27:32 UTC
  • mfrom: (1.10.4 upstream) (5.2.5 sid)
  • Revision ID: james.westby@ubuntu.com-20091117202732-ipm2h3gks5bdw2vx
Tags: 0.5.23+dfsg-3
* Building against libltdl7.
* Updating to standards version 3.8.3.
* Adding maintainer homepage field to control.
* Marking maintainer homepage field to be also included in binary
  packages and changelog.
* Adding README.source.
* Simplifying autotools handling in rules.
* Updating README.source.
* Moving maintainer homepage field from control to copyright.
* Dropping la files.
* Simplyfing debhelper install files.
* Bumping versioned build-depends on debhelper.
* Adding depends to dpkg install info.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// ***************************************************************** -*- C++ -*-
2
 
/*
3
 
 * Copyright (C) 2004, 2005 Andreas Huggel <ahuggel@gmx.net>
4
 
 *
5
 
 * This program is part of the Exiv2 distribution.
6
 
 *
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.
11
 
 *
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.
16
 
 *
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.
20
 
 */
21
 
/*!
22
 
  @file    tags.hpp
23
 
  @brief   Exif tag and type information
24
 
  @version $Rev: 580 $
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
29
 
 */
30
 
#ifndef TAGS_HPP_
31
 
#define TAGS_HPP_
32
 
 
33
 
// *****************************************************************************
34
 
// included header files
35
 
#include "metadatum.hpp"
36
 
#include "types.hpp"
37
 
 
38
 
// + standard includes
39
 
#include <string>
40
 
#include <utility>                              // for std::pair
41
 
#include <iosfwd>
42
 
#include <memory>
43
 
 
44
 
// *****************************************************************************
45
 
// namespace extensions
46
 
namespace Exiv2 {
47
 
 
48
 
// *****************************************************************************
49
 
// class declarations
50
 
    class Value;
51
 
    class Entry;
52
 
 
53
 
// *****************************************************************************
54
 
// type definitions
55
 
 
56
 
    //! Type for a function pointer for functions interpreting the tag value
57
 
    typedef std::ostream& (*PrintFct)(std::ostream&, const Value&);
58
 
 
59
 
    /*!
60
 
      @brief Section identifiers to logically group tags. A section consists
61
 
             of nothing more than a name, based on the Exif standard.
62
 
     */
63
 
    enum SectionId { sectionIdNotSet,
64
 
                     imgStruct, recOffset, imgCharacter, otherTags, exifFormat,
65
 
                     exifVersion, imgConfig, userInfo, relatedFile, dateTime,
66
 
                     captureCond, gpsTags, iopTags, makerTags,
67
 
                     lastSectionId };
68
 
 
69
 
// *****************************************************************************
70
 
// class definitions
71
 
 
72
 
    //! Contains information pertaining to one IFD
73
 
    struct IfdInfo {
74
 
        //! Constructor
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.
79
 
        const char* item_;
80
 
    };
81
 
 
82
 
    //! Contains information pertaining to one section
83
 
    struct SectionInfo {
84
 
        //! Constructor
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
89
 
    };
90
 
 
91
 
    //! Tag information
92
 
    struct TagInfo {
93
 
        //! Constructor
94
 
        TagInfo(
95
 
            uint16_t tag,
96
 
            const char* name,
97
 
            const char* desc,
98
 
            IfdId ifdId,
99
 
            SectionId sectionId,
100
 
            TypeId typeId,
101
 
            PrintFct printFct
102
 
        );
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
110
 
    }; // struct TagInfo
111
 
 
112
 
    /*!
113
 
      @brief Helper structure for lookup tables for translations of numeric
114
 
             tag values to human readable labels.
115
 
     */
116
 
    struct TagDetails {
117
 
        long val_;                              //!< Tag value
118
 
        const char* label_;                           //!< Translation of the tag value
119
 
    }; // struct TagDetails
120
 
 
121
 
    /*!
122
 
      @brief Translation from numeric values from a lookup list to human
123
 
             readable labels
124
 
     */
125
 
    class TagTranslator {
126
 
    public:
127
 
        //! @name Creators
128
 
        //@{
129
 
        //! Default constructor.
130
 
        explicit TagTranslator(const TagDetails* pTagDetails)
131
 
            : pTagDetails_(pTagDetails) {}
132
 
        // No d'tor: Do not delete the list.
133
 
        //@}
134
 
 
135
 
        //! @name Accessors
136
 
        //@{
137
 
        //! Translate the tag value and write it out to the provided stream
138
 
        std::ostream& print(std::ostream& os, const Value& value) const;
139
 
        //@}
140
 
    private:
141
 
        const TagDetails* pTagDetails_;
142
 
    }; // class TagTranslator
143
 
 
144
 
    //! Container for Exif tag information. Implemented as a static class.
145
 
    class ExifTags {
146
 
        //! Prevent construction: not implemented.
147
 
        ExifTags() {}
148
 
        //! Prevent copy-construction: not implemented.
149
 
        ExifTags(const ExifTags& rhs);
150
 
        //! Prevent assignment: not implemented.
151
 
        ExifTags& operator=(const ExifTags& rhs);
152
 
 
153
 
    public:
154
 
        /*!
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
157
 
                 a known Exif tag.
158
 
 
159
 
          @param tag The tag
160
 
          @param ifdId IFD id
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
163
 
                  tag.
164
 
         */
165
 
        static std::string tagName(uint16_t tag, IfdId ifdId);
166
 
        /*!
167
 
          @brief Return the description of the tag.
168
 
          @param tag The tag
169
 
          @param ifdId IFD id
170
 
          @return The description of the tag or a string indicating that
171
 
                 the tag is unknown.
172
 
         */
173
 
        static const char* tagDesc(uint16_t tag, IfdId ifdId);
174
 
        /*!
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.
178
 
 
179
 
          @throw Error if the tagname or ifdId is invalid
180
 
         */
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);
190
 
        /*!
191
 
          @brief Return the name of the section for a combination of
192
 
                 tag and IFD id.
193
 
          @param tag The tag
194
 
          @param ifdId IFD id
195
 
          @return The name of the section or a string indicating that the
196
 
                  section or the tag is unknown.
197
 
         */
198
 
        static const char* sectionName(uint16_t tag, IfdId ifdId);
199
 
        /*!
200
 
          @brief Return the description of the section for a combination of
201
 
                 tag and IFD id.
202
 
          @param tag The tag
203
 
          @param ifdId IFD id
204
 
          @return The description of the section or a string indicating that
205
 
                 the section or the tag is unknown.
206
 
         */
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,
214
 
                                      uint16_t tag,
215
 
                                      IfdId ifdId,
216
 
                                      const Value& value);
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);
223
 
        /*!
224
 
          @brief Register an %IfdId and %TagInfo list for a makernote
225
 
 
226
 
          @throw Error if the MakerTagInfo registry is full
227
 
         */
228
 
        static void registerMakerTagInfo(IfdId ifdId, const TagInfo* tagInfo);
229
 
        /*!
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.
233
 
        */
234
 
        static bool isMakerIfd(IfdId ifdId);
235
 
 
236
 
    private:
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,
240
 
                                           IfdId ifdId);
241
 
 
242
 
        static const IfdInfo     ifdInfo_[];
243
 
        static const SectionInfo sectionInfo_[];
244
 
 
245
 
        static const TagInfo*    tagInfos_[];
246
 
 
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];
250
 
 
251
 
    }; // class ExifTags
252
 
 
253
 
    /*!
254
 
      @brief Concrete keys for Exif metadata.
255
 
     */
256
 
    class ExifKey : public Key {
257
 
    public:
258
 
        //! Shortcut for an %ExifKey auto pointer.
259
 
        typedef std::auto_ptr<ExifKey> AutoPtr;
260
 
 
261
 
        //! @name Creators
262
 
        //@{
263
 
        /*!
264
 
          @brief Constructor to create an Exif key from a key string.
265
 
 
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.
270
 
        */
271
 
        explicit ExifKey(const std::string& key);
272
 
        /*!
273
 
          @brief Constructor to create an Exif key from a tag and IFD item
274
 
                 string.
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
279
 
                 item parameters.
280
 
         */
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);
284
 
        //! Copy constructor
285
 
        ExifKey(const ExifKey& rhs);
286
 
        virtual ~ExifKey();
287
 
        //@}
288
 
 
289
 
        //! @name Manipulators
290
 
        //@{
291
 
        /*!
292
 
          @brief Assignment operator.
293
 
         */
294
 
        ExifKey& operator=(const ExifKey& rhs);
295
 
        //@}
296
 
 
297
 
        //! @name Accessors
298
 
        //@{
299
 
        virtual std::string key() const { return key_; }
300
 
        virtual const char* familyName() const { return familyName_; }
301
 
        /*!
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.
304
 
        */
305
 
        virtual std::string groupName() const { return ifdItem(); }
306
 
        virtual std::string tagName() const;
307
 
        virtual uint16_t tag() const { return tag_; }
308
 
 
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_; }
320
 
        //@}
321
 
 
322
 
    protected:
323
 
        //! @name Manipulators
324
 
        //@{
325
 
        /*!
326
 
          @brief Set the key corresponding to the tag and IFD id.
327
 
                 The key is of the form '<b>Exif</b>.ifdItem.tagName'.
328
 
         */
329
 
        void makeKey();
330
 
        /*!
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 .
334
 
 
335
 
          @throw Error if the key cannot be decomposed.
336
 
         */
337
 
        void decomposeKey();
338
 
        //@}
339
 
 
340
 
    private:
341
 
        //! Internal virtual copy constructor.
342
 
        virtual ExifKey* clone_() const;
343
 
 
344
 
        // DATA
345
 
        static const char* familyName_;
346
 
 
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
352
 
    }; // class ExifKey
353
 
 
354
 
// *****************************************************************************
355
 
// free functions
356
 
 
357
 
    /*!
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.
362
 
     */
363
 
    bool isExifIfd(IfdId ifdId);
364
 
 
365
 
    //! Output operator for TagInfo
366
 
    std::ostream& operator<<(std::ostream& os, const TagInfo& ti);
367
 
 
368
 
    //! @name Functions printing interpreted tag values
369
 
    //@{
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);
378
 
 
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);
419
 
    //! Print scene type
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);
441
 
    //@}
442
 
}                                       // namespace Exiv2
443
 
 
444
 
#endif                                  // #ifndef TAGS_HPP_