libopenraw
makernotedir.cpp
1 /*
2  * libopenraw - makernotedir.cpp
3  *
4  * Copyright (C) Hubert Figuiere
5  *
6  * This library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3 of
9  * the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <fcntl.h>
22 
23 #include <string.h>
24 
25 #include "makernotedir.hpp"
26 #include "io/stream.hpp"
27 #include "ifdfilecontainer.hpp"
28 #include "trace.hpp"
29 
30 namespace OpenRaw {
31 namespace Internals {
32 
33 /*
34  * For Makernote detection, see:
35  * http://owl.phy.queensu.ca/~phil/exiftool/makernote_types.html
36  * http://www.exiv2.org/makernote.html
37  */
38 MakerNoteDir::Ref
40  IfdFileContainer & container)
41 {
42  LOGDBG1("createMakerNote()\n");
43  char data[18];
44  auto file = container.file();
45  file->seek(offset, SEEK_SET);
46  file->read(&data, 18);
47 
48  if (memcmp("Nikon\0", data, 6) == 0) {
49  if (data[6] == 1) {
50  return std::make_shared<MakerNoteDir>(
51  offset + 8, container, offset + 8, "Nikon2");
52  }
53  else if (data[6] == 2) {
54  // this one has an endian / TIFF header after the magic
55  return std::make_shared<MakerNoteDir>(
56  offset + 18, container, offset + 10, "Nikon");
57  }
58  else {
59  return std::make_shared<MakerNoteDir>(
60  offset, container, offset, "");
61  }
62  }
63 
64  if (memcmp("OLYMPUS\0", data, 8) == 0) {
65  return std::make_shared<MakerNoteDir>(
66  offset + 12, container, offset, "Olympus2");
67  }
68 
69  if (memcmp("OLYMP\0", data, 6) == 0) {
70  return std::make_shared<MakerNoteDir>(
71  offset + 8, container, offset + 8, "Olympus");
72  }
73 
74  if (memcmp("MLT0", data + 10, 4) == 0) {
75  return std::make_shared<MakerNoteDir>(
76  offset, container, offset, "Minolta");
77  }
78 
79  return std::make_shared<MakerNoteDir>(offset, container, offset, "");
80 }
81 
82 MakerNoteDir::MakerNoteDir(off_t _offset,
83  IfdFileContainer & _container,
84  off_t mnote_offset,
85  const std::string & id)
86  : MakerNoteDir("", 0, _offset, _container, mnote_offset, id)
87 {
88 }
89 
90 MakerNoteDir::MakerNoteDir(const char* magic, size_t hlen,
91  off_t _offset,
92  IfdFileContainer & _container,
93  off_t mnote_offset,
94  const std::string & id)
95  : IfdDir(_offset, _container)
96  , m_magic(magic ? magic : "")
97  , m_hlen(hlen)
98  , m_mnote_offset(mnote_offset)
99  , m_id(id)
100 {
101 }
102 
103 MakerNoteDir::~MakerNoteDir()
104 {
105 }
106 
107 }
108 }
109 
110 /*
111  Local Variables:
112  mode:c++
113  c-file-style:"stroustrup"
114  c-file-offsets:((innamespace . 0))
115  indent-tabs-mode:nil
116  fill-column:80
117  End:
118 */
CIFF is the container for CRW files. It is an attempt from Canon to make this a standard. I guess it failed.
Definition: arwfile.cpp:30
static Ref createMakerNote(off_t offset, IfdFileContainer &container)
off_t offset() const
Definition: ifddir.hpp:56