libopenraw
ciffcontainer.h
1 /*
2  * libopenraw - ciffcontainer.h
3  *
4  * Copyright (C) 2006,2008 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 
27 #ifndef _CIFFCONTAINER_H_
28 #define _CIFFCONTAINER_H_
29 
30 #include <vector>
31 #include <boost/shared_ptr.hpp>
32 
33 #include "rawcontainer.h"
34 #include "trace.h"
35 
36 namespace OpenRaw {
37  namespace Internals {
38 
39  class CIFFContainer;
40 
41  namespace CIFF {
42 
44  enum {
45  STORAGELOC_MASK = 0xc000,
46  FORMAT_MASK = 0x3800,
47  TAGCODE_MASK = 0x3fff
49  };
54  enum {
55  TAG_NULLRECORD = 0x0000,
56  TAG_FREEBYTES = 0x0001,
57  TAG_COLORINFO1 = 0x0032,
58  TAG_FILEDESCRIPTION = 0x0805,
59  TAG_RAWMAKEMODEL = 0x080a,
60  TAG_FIRMWAREVERSION = 0x080b,
61  TAG_COMPONENTVERSION = 0x080c,
62  TAG_ROMOPERATIONMODE = 0x080d,
63  TAG_OWNERNAME = 0x0810,
64  TAG_IMAGETYPE = 0x0815,
65  TAG_ORIGINALFILENAME = 0x0816,
66  TAG_THUMBNAILFILENAME = 0x0817,
67 
68  TAG_TARGETIMAGETYPE = 0x100a,
69  TAG_SHUTTERRELEASEMETHOD = 0x1010,
70  TAG_SHUTTERRELEASETIMING = 0x1011,
71  TAG_RELEASESETTING = 0x1016,
72  TAG_BASEISO = 0x101c,
73  TAG_FOCALLENGTH = 0x1029,
74  TAG_SHOTINFO = 0x102a,
75  TAG_COLORINFO2 = 0x102c,
76  TAG_CAMERASETTINGS = 0x102d,
77  TAG_SENSORINFO = 0x1031,
78  TAG_CUSTOMFUNCTIONS = 0x1033,
79  TAG_PICTUREINFO = 0x1038,
80  TAG_WHITEBALANCETABLE = 0x10a9,
81  TAG_COLORSPACE = 0x10b4,
82 
83  TAG_IMAGESPEC = 0x1803,
84  TAG_RECORDID = 0x1804,
85  TAG_SELFTIMERTIME = 0x1806,
86  TAG_TARGETDISTANCESETTING = 0x1807,
87  TAG_SERIALNUMBER = 0x180b,
88  TAG_CAPTUREDTIME = 0x180e,
89  TAG_IMAGEINFO = 0x1810,
90  TAG_FLASHINFO = 0x1813,
91  TAG_MEASUREDEV = 0x1814,
92  TAG_FILENUMBER = 0x1817,
93  TAG_EXPOSUREINFO = 0x1818,
94  TAG_DECODERTABLE = 0x1835,
95 
96  TAG_RAWIMAGEDATA = 0x2005,
97  TAG_JPEGIMAGE = 0x2007,
98  TAG_JPEGTHUMBNAIL = 0x2008,
99 
100  TAG_IMAGEDESCRIPTION = 0x2804,
101  TAG_CAMERAOBJECT = 0x2807,
102  TAG_SHOOTINGRECORD = 0x3002,
103  TAG_MEASUREDINFO = 0x3003,
104  TAG_CAMERASPECIFICATION = 0x3004,
105  TAG_IMAGEPROPS = 0x300a,
106  TAG_EXIFINFORMATION = 0x300b
107  };
108 
109  class Heap;
110 
111 
112  class ImageSpec
113  {
114  public:
115  ImageSpec()
116  : imageWidth(0), imageHeight(0),
117  pixelAspectRatio(0), rotationAngle(0),
118  componentBitDepth(0), colorBitDepth(0),
119  colorBW(0)
120  {
121  }
122 
128  bool readFrom(off_t offset, CIFFContainer *container);
129  int32_t exifOrientation() const;
130 
131  uint32_t imageWidth;
132  uint32_t imageHeight;
133  uint32_t /*float32*/pixelAspectRatio;
134  int32_t rotationAngle;
135  uint32_t componentBitDepth;
136  uint32_t colorBitDepth;
137  uint32_t colorBW;
138  };
139 
140 
141  class RecordEntry
142  {
143  public:
144  typedef std::vector<RecordEntry> List;
145 
146  RecordEntry();
147 
152  bool readFrom(CIFFContainer *container);
159  size_t fetchData(Heap* heap, void* buf, size_t size) const;
164  bool isA(uint16_t _typeCode) const
165  {
166  Debug::Trace(DEBUG2) << "typeCode = " << typeCode << "\n";
167  return typeCode == (TAGCODE_MASK & _typeCode);
168  }
169 
170  uint16_t typeCode;/* type code of the record */
171  uint32_t length;/* record length */
172  uint32_t offset;/* offset of the record in the heap*/
173  };
174 
176  class Heap
177  {
178  public:
179  typedef boost::shared_ptr<Heap> Ref;
180 
186  Heap(off_t start, off_t length, CIFFContainer * container);
187 
188  RecordEntry::List & records();
189  CIFFContainer *container()
190  {
191  return m_container;
192  }
194  off_t offset()
195  {
196  return m_start;
197  }
198  private:
199  bool _loadRecords();
200 
201  Heap(const Heap &);
202  Heap & operator=(const Heap &);
203 
204  off_t m_start;
205  off_t m_length;
206  CIFFContainer *m_container;
207  RecordEntry::List m_records;
208  };
209 
210 
213  {
214  public:
215  bool readFrom(CIFFContainer *);
216  char byteOrder[2];/* 'MM' for Motorola,'II' for Intel */
217  uint32_t headerLength;/* length of header (in bytes) */
218  char type[4];
219  char subType[4];
220  uint32_t version; /* higher word: 0x0001, Lower word: 0x0002 */
221  //uint32_t reserved1;
222  //uint32_t reserved2;
223  RawContainer::EndianType endian;
224  };
225  }
226 
231  : public RawContainer
232  {
233  public:
234  CIFFContainer(IO::Stream *file);
235  virtual ~CIFFContainer();
236 
237  CIFF::Heap::Ref heap();
238 
239  const CIFF::HeapFileHeader & header() const
240  {
241  return m_hdr;
242  }
243  CIFF::Heap::Ref getImageProps();
244  const CIFF::RecordEntry * getRawDataRecord() const;
245  const CIFF::ImageSpec * getImageSpec();
246  const CIFF::Heap::Ref getCameraProps();
247  private:
248  bool _loadHeap();
249  EndianType _readHeader();
250 
251 
252  CIFFContainer(const CIFFContainer &);
253  CIFFContainer & operator=(const CIFFContainer &);
254 
255  friend class CIFF::HeapFileHeader;
256  CIFF::HeapFileHeader m_hdr;
257  CIFF::Heap::Ref m_heap;
258  CIFF::Heap::Ref m_imageprops;
259  bool m_hasImageSpec;
260  CIFF::ImageSpec m_imagespec;
261  CIFF::Heap::Ref m_cameraprops;
262  };
263 
264 
265  }
266 }
267 
268 
269 
270 #endif
bool readFrom(CIFFContainer *container)
Heap(off_t start, off_t length, CIFFContainer *container)
bool readFrom(off_t offset, CIFFContainer *container)
bool isA(uint16_t _typeCode) const
size_t fetchData(Heap *heap, void *buf, size_t size) const
base virtual class for IO
Definition: stream.h:40