~ubuntu-branches/debian/lenny/exiv2/lenny

« back to all changes in this revision

Viewing changes to src/pentaxmn.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2008-06-21 08:23:53 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080621082353-b1n4w08trwfwbfl4
Tags: 0.17.1-1
* New upstream release
  - Library transition cleared on debian-release/ d-d-a
* Version 0.17 also fixes:
  - CVE-2008-2696: DoS via metadata in images (Closes: #486328)
  - crashes when fed with wrong file (Closes: #485670)
* Urgency medium for CVE fix
* debian/patches/gcc4.3.diff unecessary for gcc-4.3
* Add /usr/share/bug/exiv2/presubj message for reportbug(1)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ***************************************************************** -*- C++ -*-
 
2
/*
 
3
 * Copyright (C) 2004-2008 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., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
 
20
 */
 
21
/*!
 
22
  @file    pentaxmn.hpp
 
23
  @brief   Pentax MakerNote implemented according to the specification
 
24
           http://www.gvsoft.homedns.org/exif/makernote-pentax-type3.html and
 
25
           based on ExifTool implementation and
 
26
           <a href="http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Pentax.html">Pentax Makernote list</a> by Phil Harvey<br>
 
27
  @version $Rev: 1366 $
 
28
  @author  Michal Cihar
 
29
           <a href="mailto:michal@cihar.com">michal@cihar.com</a>
 
30
  @date    27-Sep-07
 
31
 */
 
32
#ifndef PENTAXMN_HPP_
 
33
#define PENTAXMN_HPP_
 
34
 
 
35
// *****************************************************************************
 
36
// included header files
 
37
#include "types.hpp"
 
38
#include "makernote.hpp"
 
39
#include "tags.hpp"
 
40
 
 
41
// + standard includes
 
42
#include <string>
 
43
#include <iostream>
 
44
#include <iomanip>
 
45
#include <memory>
 
46
 
 
47
// *****************************************************************************
 
48
// namespace extensions
 
49
namespace Exiv2 {
 
50
 
 
51
// *****************************************************************************
 
52
// class declarations
 
53
    class Value;
 
54
 
 
55
// *****************************************************************************
 
56
// free functions
 
57
 
 
58
    /*!
 
59
      @brief Return an auto-pointer to a newly created empty MakerNote
 
60
             initialized to operate in the memory management model indicated.
 
61
             The caller owns this copy and the auto-pointer ensures that it
 
62
             will be deleted.
 
63
 
 
64
      @param alloc Memory management model for the new MakerNote. Determines if
 
65
             memory required to store data should be allocated and deallocated
 
66
             (true) or not (false). If false, only pointers to the buffer
 
67
             provided to read() will be kept. See Ifd for more background on
 
68
             this concept.
 
69
      @param buf Pointer to the makernote character buffer (not used).
 
70
      @param len Length of the makernote character buffer (not used).
 
71
      @param byteOrder Byte order in which the Exif data (and possibly the
 
72
             makernote) is encoded (not used).
 
73
      @param offset Offset from the start of the TIFF header of the makernote
 
74
             buffer (not used).
 
75
 
 
76
      @return An auto-pointer to a newly created empty MakerNote. The caller
 
77
             owns this copy and the auto-pointer ensures that it will be
 
78
             deleted.
 
79
     */
 
80
    MakerNote::AutoPtr createPentaxMakerNote(bool alloc,
 
81
                                             const byte* buf,
 
82
                                             long len,
 
83
                                             ByteOrder byteOrder,
 
84
                                             long offset);
 
85
 
 
86
// *****************************************************************************
 
87
// class definitions
 
88
 
 
89
    //! MakerNote for Pentaxfilm cameras
 
90
    class PentaxMakerNote : public IfdMakerNote {
 
91
    public:
 
92
        //! Shortcut for a %PentaxMakerNote auto pointer.
 
93
        typedef std::auto_ptr<PentaxMakerNote> AutoPtr;
 
94
 
 
95
        //! @name Creators
 
96
        //@{
 
97
        /*!
 
98
          @brief Constructor. Allows to choose whether or not memory management
 
99
                 is required for the makernote entries.
 
100
         */
 
101
        PentaxMakerNote(bool alloc =true);
 
102
        //! Copy constructor
 
103
        PentaxMakerNote(const PentaxMakerNote& rhs);
 
104
        //! Virtual destructor
 
105
        virtual ~PentaxMakerNote() {}
 
106
        //@}
 
107
 
 
108
        //! @name Manipulators
 
109
        //@{
 
110
        int readHeader(const byte* buf,
 
111
                       long len,
 
112
                       ByteOrder byteOrder);
 
113
        //@}
 
114
 
 
115
        //! @name Accessors
 
116
        //@{
 
117
        int checkHeader() const;
 
118
        AutoPtr create(bool alloc =true) const;
 
119
        AutoPtr clone() const;
 
120
        //! Return read-only list of built-in Pentaxfilm tags
 
121
        static const TagInfo* tagList();
 
122
        //@}
 
123
 
 
124
        //! @cond IGNORE
 
125
        // Public only so that we can create a static instance
 
126
        struct RegisterMn {
 
127
            RegisterMn();
 
128
        };
 
129
        //! @endcond
 
130
 
 
131
        //! Print Pentax version
 
132
        static std::ostream& printPentaxVersion(std::ostream& os, const Value& value);
 
133
        //! Print Pentax resolution
 
134
        static std::ostream& printPentaxResolution(std::ostream& os, const Value& value);
 
135
        //! Print Pentax date
 
136
        static std::ostream& printPentaxDate(std::ostream& os, const Value& value);
 
137
        //! Print Pentax time
 
138
        static std::ostream& printPentaxTime(std::ostream& os, const Value& value);
 
139
        //! Print Pentax exposure
 
140
        static std::ostream& printPentaxExposure(std::ostream& os, const Value& value);
 
141
        //! Print Pentax F value
 
142
        static std::ostream& printPentaxFValue(std::ostream& os, const Value& value);
 
143
        //! Print Pentax focal length
 
144
        static std::ostream& printPentaxFocalLength(std::ostream& os, const Value& value);
 
145
        //! Print Pentax compensation
 
146
        static std::ostream& printPentaxCompensation(std::ostream& os, const Value& value);
 
147
        //! Print Pentax temperature
 
148
        static std::ostream& printPentaxTemperature(std::ostream& os, const Value& value);
 
149
        //! Print Pentax flash compensation
 
150
        static std::ostream& printPentaxFlashCompensation(std::ostream& os, const Value& value);
 
151
        //! Print Pentax bracketing
 
152
        static std::ostream& printPentaxBracketing(std::ostream& os, const Value& value);
 
153
 
 
154
    private:
 
155
        //! Internal virtual create function.
 
156
        PentaxMakerNote* create_(bool alloc =true) const;
 
157
        //! Internal virtual copy constructor.
 
158
        PentaxMakerNote* clone_() const;
 
159
 
 
160
        //! Tag information
 
161
        static const TagInfo tagInfo_[];
 
162
    }; // class PentaxMakerNote
 
163
 
 
164
    static PentaxMakerNote::RegisterMn registerPentaxMakerNote;
 
165
 
 
166
    /*!
 
167
      @brief Print function to translate Pentax "combi-values" to a description
 
168
             by looking up a reference table.
 
169
     */
 
170
    template <int N, const TagDetails (&array)[N], int count, int ignoredcount>
 
171
    std::ostream& printCombiTag(std::ostream& os, const Value& value)
 
172
    {
 
173
        if ((value.count() != count && value.count() != (count + ignoredcount)) || count > 4) {
 
174
            return printValue(os, value);
 
175
        }
 
176
        unsigned long l = 0;
 
177
        for (int c = 0; c < count; ++c) {
 
178
            if (value.toLong(c) < 0 || value.toLong(c) > 255) {
 
179
                return printValue(os, value);
 
180
            }
 
181
            l += (value.toLong(c) << ((count - c - 1) * 8));
 
182
        }
 
183
        const TagDetails* td = find(array, l);
 
184
        if (td) {
 
185
            os << exvGettext(td->label_);
 
186
        }
 
187
        else {
 
188
            os << exvGettext("Unknown") << " (0x"
 
189
               << std::setw(2 * count) << std::setfill('0')
 
190
               << std::hex << l << std::dec << ")";
 
191
        }
 
192
 
 
193
        return os;
 
194
    }
 
195
 
 
196
//! Shortcut for the printCombiTag template which requires typing the array name only once.
 
197
#define EXV_PRINT_COMBITAG(array, count, ignoredcount) printCombiTag<EXV_COUNTOF(array), array, count, ignoredcount>
 
198
 
 
199
}                                       // namespace Exiv2
 
200
 
 
201
#endif                                  // #ifndef PENTAXMN_HPP_