libopenraw
ciffcontainer.hpp
1/* -*- Mode: C++ -*- */
2/*
3 * libopenraw - ciffcontainer.h
4 *
5 * Copyright (C) 2006-2014 Hubert Figuiere
6 *
7 * This library is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This library 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 GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library. If not, see
19 * <http://www.gnu.org/licenses/>.
20 */
21
26
27
28#ifndef OR_INTERNALS_CIFFCONTAINER_H_
29#define OR_INTERNALS_CIFFCONTAINER_H_
30
31#include <stddef.h>
32#include <stdint.h>
33#include <sys/types.h>
34
35#include <vector>
36#include <memory>
37
38#include <libopenraw/debug.h>
39
40#include "io/stream.hpp"
41#include "rawcontainer.hpp"
42#include "trace.hpp"
43
44namespace OpenRaw {
45namespace Internals {
46
47class CIFFContainer;
48
49namespace CIFF {
50
52enum {
53 STORAGELOC_MASK = 0xc000,
54 FORMAT_MASK = 0x3800,
55 TAGCODE_MASK = 0x3fff
57};
62enum {
63 TAG_NULLRECORD = 0x0000,
64 TAG_FREEBYTES = 0x0001,
65 TAG_COLORINFO1 = 0x0032,
66 TAG_FILEDESCRIPTION = 0x0805,
67 TAG_RAWMAKEMODEL = 0x080a,
68 TAG_FIRMWAREVERSION = 0x080b,
69 TAG_COMPONENTVERSION = 0x080c,
70 TAG_ROMOPERATIONMODE = 0x080d,
71 TAG_OWNERNAME = 0x0810,
72 TAG_IMAGETYPE = 0x0815,
73 TAG_ORIGINALFILENAME = 0x0816,
74 TAG_THUMBNAILFILENAME = 0x0817,
75
76 TAG_TARGETIMAGETYPE = 0x100a,
77 TAG_SHUTTERRELEASEMETHOD = 0x1010,
78 TAG_SHUTTERRELEASETIMING = 0x1011,
79 TAG_RELEASESETTING = 0x1016,
80 TAG_BASEISO = 0x101c,
81 TAG_FOCALLENGTH = 0x1029,
82 TAG_SHOTINFO = 0x102a,
83 TAG_COLORINFO2 = 0x102c,
84 TAG_CAMERASETTINGS = 0x102d,
85 TAG_SENSORINFO = 0x1031,
86 TAG_CUSTOMFUNCTIONS = 0x1033,
87 TAG_PICTUREINFO = 0x1038,
88 TAG_WHITEBALANCETABLE = 0x10a9,
89 TAG_COLORSPACE = 0x10b4,
90
91 TAG_IMAGESPEC = 0x1803,
92 TAG_RECORDID = 0x1804,
93 TAG_SELFTIMERTIME = 0x1806,
94 TAG_TARGETDISTANCESETTING = 0x1807,
95 TAG_SERIALNUMBER = 0x180b,
96 TAG_CAPTUREDTIME = 0x180e,
97 TAG_IMAGEINFO = 0x1810,
98 TAG_FLASHINFO = 0x1813,
99 TAG_MEASUREDEV = 0x1814,
100 TAG_FILENUMBER = 0x1817,
101 TAG_EXPOSUREINFO = 0x1818,
102 TAG_DECODERTABLE = 0x1835,
103
104 TAG_RAWIMAGEDATA = 0x2005,
105 TAG_JPEGIMAGE = 0x2007,
106 TAG_JPEGTHUMBNAIL = 0x2008,
107
108 TAG_IMAGEDESCRIPTION = 0x2804,
109 TAG_CAMERAOBJECT = 0x2807,
110 TAG_SHOOTINGRECORD = 0x3002,
111 TAG_MEASUREDINFO = 0x3003,
112 TAG_CAMERASPECIFICATION = 0x3004,
113 TAG_IMAGEPROPS = 0x300a,
114 TAG_EXIFINFORMATION = 0x300b
115};
116
117class Heap;
118
119
120class ImageSpec
121{
122public:
123 ImageSpec()
124 : imageWidth(0), imageHeight(0),
125 pixelAspectRatio(0), rotationAngle(0),
126 componentBitDepth(0), colorBitDepth(0),
127 colorBW(0)
128 {
129 }
130
136 bool readFrom(off_t offset, CIFFContainer *container);
137 int32_t exifOrientation() const;
138
139 uint32_t imageWidth;
140 uint32_t imageHeight;
141 uint32_t /*float32*/pixelAspectRatio;
142 int32_t rotationAngle;
143 uint32_t componentBitDepth;
144 uint32_t colorBitDepth;
145 uint32_t colorBW;
146};
147
148
149class RecordEntry
150{
151public:
152 typedef std::vector<RecordEntry> List;
153
154 RecordEntry();
155
160 bool readFrom(CIFFContainer *container);
167 size_t fetchData(Heap* heap, void* buf, size_t size) const;
172 bool isA(uint16_t _typeCode) const
173 {
174 LOGDBG2("typeCode = %u\n", typeCode);
175 return typeCode == (TAGCODE_MASK & _typeCode);
176 }
177
178 uint16_t typeCode;/* type code of the record */
179 uint32_t length;/* record length */
180 uint32_t offset;/* offset of the record in the heap*/
181};
182
184class Heap
185{
186public:
187 typedef std::shared_ptr<Heap> Ref;
188
194 Heap(off_t start, off_t length, CIFFContainer * container);
195
196 Heap(const Heap &) = delete;
197 Heap & operator=(const Heap &) = delete;
198
199 RecordEntry::List & records();
200 CIFFContainer *container()
201 {
202 return m_container;
203 }
205 off_t offset()
206 {
207 return m_start;
208 }
209private:
210 bool _loadRecords();
211
212 off_t m_start;
213 off_t m_length;
214 CIFFContainer *m_container;
215 RecordEntry::List m_records;
216};
217
218
221{
222public:
223 bool readFrom(CIFFContainer *);
224 char byteOrder[2];/* 'MM' for Motorola,'II' for Intel */
225 uint32_t headerLength;/* length of header (in bytes) */
226 char type[4];
227 char subType[4];
228 uint32_t version; /* higher word: 0x0001, Lower word: 0x0002 */
229 //uint32_t reserved1;
230 //uint32_t reserved2;
232};
233
234} // namespace CIFF
235
239class CIFFContainer
240 : public RawContainer
241{
242public:
243 CIFFContainer(const IO::Stream::Ptr &file);
244 virtual ~CIFFContainer();
245
246 CIFFContainer(const CIFFContainer &) = delete;
247 CIFFContainer & operator=(const CIFFContainer &) = delete;
248
249 CIFF::Heap::Ref heap();
250
251 const CIFF::HeapFileHeader & header() const
252 {
253 return m_hdr;
254 }
255 CIFF::Heap::Ref getImageProps();
256 const CIFF::RecordEntry * getRawDataRecord() const;
257 const CIFF::ImageSpec * getImageSpec();
258 const CIFF::Heap::Ref getCameraProps();
259private:
260 bool _loadHeap();
261 EndianType _readHeader();
262
263 friend class CIFF::HeapFileHeader;
265 CIFF::Heap::Ref m_heap;
266 CIFF::Heap::Ref m_imageprops;
267 bool m_hasImageSpec;
268 CIFF::ImageSpec m_imagespec;
269 CIFF::Heap::Ref m_cameraprops;
270};
271
272
273}
274}
275
276
277
278#endif
Heap(off_t start, off_t length, CIFFContainer *container)
bool readFrom(off_t offset, CIFFContainer *container)
bool readFrom(CIFFContainer *container)
size_t fetchData(Heap *heap, void *buf, size_t size) const
bool isA(uint16_t _typeCode) const
RawContainer(const IO::Stream::Ptr &_file, off_t offset)
CIFF is the container for CRW files. It is an attempt from Canon to make this a standard....
Definition arwfile.cpp:30