~ubuntu-branches/ubuntu/natty/libextractor/natty

« back to all changes in this revision

Viewing changes to src/plugins/exiv2/sigmamn.cpp

  • 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:      sigmamn.cpp
23
 
  Version:   $Rev: 600 $
24
 
  Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
25
 
  History:   02-Apr-04, ahu: created
26
 
  Credits:   Sigma and Foveon MakerNote implemented according to the specification
27
 
             in "SIGMA and FOVEON EXIF MakerNote Documentation" by Foveon.
28
 
             <http://www.x3f.info/technotes/FileDocs/MakerNoteDoc.html>
29
 
 */
30
 
// *****************************************************************************
31
 
#include "rcsid.hpp"
32
 
EXIV2_RCSID("@(#) $Id: sigmamn.cpp 600 2005-07-09 10:38:09Z ahuggel $");
33
 
 
34
 
// *****************************************************************************
35
 
// included header files
36
 
#include "types.hpp"
37
 
#include "sigmamn.hpp"
38
 
#include "makernote.hpp"
39
 
#include "value.hpp"
40
 
 
41
 
// + standard includes
42
 
#include <string>
43
 
#include <sstream>
44
 
#include <iomanip>
45
 
#include <cassert>
46
 
 
47
 
// *****************************************************************************
48
 
// class member definitions
49
 
namespace Exiv2 {
50
 
 
51
 
    //! @cond IGNORE
52
 
    SigmaMakerNote::RegisterMn::RegisterMn()
53
 
    {
54
 
        MakerNoteFactory::registerMakerNote("SIGMA", "*", createSigmaMakerNote);
55
 
        MakerNoteFactory::registerMakerNote("FOVEON", "*", createSigmaMakerNote);
56
 
        MakerNoteFactory::registerMakerNote(
57
 
            sigmaIfdId, MakerNote::AutoPtr(new SigmaMakerNote));
58
 
 
59
 
        ExifTags::registerMakerTagInfo(sigmaIfdId, tagInfo_);
60
 
    }
61
 
    //! @endcond
62
 
 
63
 
    // Sigma (Foveon) MakerNote Tag Info
64
 
    const TagInfo SigmaMakerNote::tagInfo_[] = {
65
 
        TagInfo(0x0002, "SerialNumber", "Camera serial number", sigmaIfdId, makerTags, asciiString, printValue),
66
 
        TagInfo(0x0003, "DriveMode", "Drive Mode", sigmaIfdId, makerTags, asciiString, printValue),
67
 
        TagInfo(0x0004, "ResolutionMode", "Resolution Mode", sigmaIfdId, makerTags, asciiString, printValue),
68
 
        TagInfo(0x0005, "AutofocusMode", "Autofocus mode", sigmaIfdId, makerTags, asciiString, printValue),
69
 
        TagInfo(0x0006, "FocusSetting", "Focus setting", sigmaIfdId, makerTags, asciiString, printValue),
70
 
        TagInfo(0x0007, "WhiteBalance", "White balance", sigmaIfdId, makerTags, asciiString, printValue),
71
 
        TagInfo(0x0008, "ExposureMode", "Exposure mode", sigmaIfdId, makerTags, asciiString, print0x0008),
72
 
        TagInfo(0x0009, "MeteringMode", "Metering mode", sigmaIfdId, makerTags, asciiString, print0x0009),
73
 
        TagInfo(0x000a, "LensRange", "Lens focal length range", sigmaIfdId, makerTags, asciiString, printValue),
74
 
        TagInfo(0x000b, "ColorSpace", "Color space", sigmaIfdId, makerTags, asciiString, printValue),
75
 
        TagInfo(0x000c, "Exposure", "Exposure", sigmaIfdId, makerTags, asciiString, printStripLabel),
76
 
        TagInfo(0x000d, "Contrast", "Contrast", sigmaIfdId, makerTags, asciiString, printStripLabel),
77
 
        TagInfo(0x000e, "Shadow", "Shadow", sigmaIfdId, makerTags, asciiString, printStripLabel),
78
 
        TagInfo(0x000f, "Highlight", "Highlight", sigmaIfdId, makerTags, asciiString, printStripLabel),
79
 
        TagInfo(0x0010, "Saturation", "Saturation", sigmaIfdId, makerTags, asciiString, printStripLabel),
80
 
        TagInfo(0x0011, "Sharpness", "Sharpness", sigmaIfdId, makerTags, asciiString, printStripLabel),
81
 
        TagInfo(0x0012, "FillLight", "X3 Fill light", sigmaIfdId, makerTags, asciiString, printStripLabel),
82
 
        TagInfo(0x0014, "ColorAdjustment", "Color adjustment", sigmaIfdId, makerTags, asciiString, printStripLabel),
83
 
        TagInfo(0x0015, "AdjustmentMode", "Adjustment mode", sigmaIfdId, makerTags, asciiString, printValue),
84
 
        TagInfo(0x0016, "Quality", "Quality", sigmaIfdId, makerTags, asciiString, printStripLabel),
85
 
        TagInfo(0x0017, "Firmware", "Firmware", sigmaIfdId, makerTags, asciiString, printValue),
86
 
        TagInfo(0x0018, "Software", "Software", sigmaIfdId, makerTags, asciiString, printValue),
87
 
        TagInfo(0x0019, "AutoBracket", "Auto bracket", sigmaIfdId, makerTags, asciiString, printValue),
88
 
        // End of list marker
89
 
        TagInfo(0xffff, "(UnknownSigmaMakerNoteTag)", "Unknown SigmaMakerNote tag", sigmaIfdId, makerTags, invalidTypeId, printValue)
90
 
    };
91
 
 
92
 
    SigmaMakerNote::SigmaMakerNote(bool alloc)
93
 
        : IfdMakerNote(sigmaIfdId, alloc)
94
 
    {
95
 
        byte buf[] = {
96
 
            'S', 'I', 'G', 'M', 'A', '\0', '\0', '\0', 0x01, 0x00
97
 
        };
98
 
        readHeader(buf, 10, byteOrder_);
99
 
    }
100
 
 
101
 
    SigmaMakerNote::SigmaMakerNote(const SigmaMakerNote& rhs)
102
 
        : IfdMakerNote(rhs)
103
 
    {
104
 
    }
105
 
 
106
 
    int SigmaMakerNote::readHeader(const byte* buf,
107
 
                                   long len,
108
 
                                   ByteOrder byteOrder)
109
 
    {
110
 
        if (len < 10) return 1;
111
 
 
112
 
        // Copy the header. My one and only Sigma sample has two undocumented
113
 
        // extra bytes (0x01, 0x00) between the ID string and the start of the
114
 
        // Makernote IFD. So we copy 10 bytes into the header.
115
 
        header_.alloc(10);
116
 
        memcpy(header_.pData_, buf, header_.size_);
117
 
        // Adjust the offset of the IFD for the prefix
118
 
        adjOffset_ = 10;
119
 
        return 0;
120
 
    }
121
 
 
122
 
    int SigmaMakerNote::checkHeader() const
123
 
    {
124
 
        int rc = 0;
125
 
        // Check the SIGMA or FOVEON prefix
126
 
        if (   header_.size_ < 10
127
 
            || std::string(reinterpret_cast<char*>(header_.pData_), 8)
128
 
                        != std::string("SIGMA\0\0\0", 8)
129
 
            && std::string(reinterpret_cast<char*>(header_.pData_), 8)
130
 
                        != std::string("FOVEON\0\0", 8)) {
131
 
            rc = 2;
132
 
        }
133
 
        return rc;
134
 
    }
135
 
 
136
 
    SigmaMakerNote::AutoPtr SigmaMakerNote::create(bool alloc) const
137
 
    {
138
 
        return AutoPtr(create_(alloc));
139
 
    }
140
 
 
141
 
    SigmaMakerNote* SigmaMakerNote::create_(bool alloc) const
142
 
    {
143
 
        AutoPtr makerNote = AutoPtr(new SigmaMakerNote(alloc));
144
 
        assert(makerNote.get() != 0);
145
 
        makerNote->readHeader(header_.pData_, header_.size_, byteOrder_);
146
 
        return makerNote.release();
147
 
    }
148
 
 
149
 
    SigmaMakerNote::AutoPtr SigmaMakerNote::clone() const
150
 
    {
151
 
        return AutoPtr(clone_());
152
 
    }
153
 
 
154
 
    SigmaMakerNote* SigmaMakerNote::clone_() const
155
 
    {
156
 
        return new SigmaMakerNote(*this);
157
 
    }
158
 
 
159
 
    std::ostream& SigmaMakerNote::printStripLabel(std::ostream& os,
160
 
                                                  const Value& value)
161
 
    {
162
 
        std::string v = value.toString();
163
 
        std::string::size_type pos = v.find(':');
164
 
        if (pos != std::string::npos) {
165
 
            if (v[pos + 1] == ' ') ++pos;
166
 
            v = v.substr(pos + 1);
167
 
        }
168
 
        return os << v;
169
 
    }
170
 
 
171
 
    std::ostream& SigmaMakerNote::print0x0008(std::ostream& os,
172
 
                                              const Value& value)
173
 
    {
174
 
        switch (value.toString()[0]) {
175
 
        case 'P': os << "Program"; break;
176
 
        case 'A': os << "Aperture priority"; break;
177
 
        case 'S': os << "Shutter priority"; break;
178
 
        case 'M': os << "Manual"; break;
179
 
        default: os << "(" << value << ")"; break;
180
 
        }
181
 
        return os;
182
 
    }
183
 
 
184
 
    std::ostream& SigmaMakerNote::print0x0009(std::ostream& os,
185
 
                                              const Value& value)
186
 
    {
187
 
        switch (value.toString()[0]) {
188
 
        case 'A': os << "Average"; break;
189
 
        case 'C': os << "Center"; break;
190
 
        case '8': os << "8-Segment"; break;
191
 
        default: os << "(" << value << ")"; break;
192
 
        }
193
 
        return os;
194
 
    }
195
 
 
196
 
// *****************************************************************************
197
 
// free functions
198
 
 
199
 
    MakerNote::AutoPtr createSigmaMakerNote(bool alloc,
200
 
                                            const byte* buf,
201
 
                                            long len,
202
 
                                            ByteOrder byteOrder,
203
 
                                            long offset)
204
 
    {
205
 
        return MakerNote::AutoPtr(new SigmaMakerNote(alloc));
206
 
    }
207
 
 
208
 
}                                       // namespace Exiv2