libopenraw
mrwcontainer.h
1 /*
2  * libopenraw - mrwcontainer.h
3  *
4  * Copyright (C) 2006 Hubert Figuiere
5  * Copyright (C) 2008 Bradley Broom
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 
22 
23 #ifndef _MRW_CONTAINER_H__
24 #define _MRW_CONTAINER_H__
25 
26 #include <string>
27 #include <boost/config.hpp>
28 #include <boost/shared_ptr.hpp>
29 
30 #include "ifdfilecontainer.h"
31 
32 namespace OpenRaw {
33  namespace Internals {
34 
35  class IOFile;
36 
37  class MRWContainer;
38 
39  namespace MRW {
40 
41  const int DataBlockHeaderLength = 8; /* Number of bytes in a block header. */
42 
45  class DataBlock
46  {
47  public:
48  typedef boost::shared_ptr<DataBlock> Ref;
49  typedef std::vector<Ref> RefVec;
50 
55  DataBlock(off_t start, MRWContainer * container);
56 
59  off_t offset()
60  {
61  return m_start;
62  }
63 
66  off_t length()
67  {
68  return m_length;
69  }
70 
73  std::string name()
74  {
75  char id[4];
76  id[0] = m_name[1];
77  id[1] = m_name[2];
78  id[2] = m_name[3];
79  id[3] = 0;
80  return std::string(id);
81  }
82 
85  int8_t int8_val (off_t offset);
86 
89  uint8_t uint8_val (off_t offset);
90 
93  uint16_t uint16_val (off_t offset);
94 
95  std::string string_val(off_t offset);
96 
97  bool loaded() const
98  {
99  return m_loaded;
100  }
101 
102  private:
103  /* DRM: protection from copies. */
104  DataBlock(const DataBlock &);
105  DataBlock & operator=(const DataBlock &);
106 
107  off_t m_start;
108  char m_name[4];
109  int32_t m_length;
110  MRWContainer *m_container;
111  bool m_loaded;
112  };
113 
114  /* Known offsets in PRD block.
115  */
116  enum {
117  PRD_VERSION = 0, /* 8 chars, version string */
118  PRD_SENSOR_LENGTH = 8, /* 2 bytes, Number of lines in raw data */
119  PRD_SENSOR_WIDTH = 10, /* 2 bytes, Number of pixels per line */
120  PRD_IMAGE_LENGTH = 12, /* 2 bytes, length of image after Divu processing */
121  PRD_IMAGE_WIDTH = 14, /* 2 bytes, width of image after Divu processing */
122  PRD_DATA_SIZE = 16, /* 1 byte, number of bits used to store each pixel */
123  PRD_PIXEL_SIZE = 17, /* 1 byte, number of valid bits per pixel */
124  PRD_STORAGE_TYPE = 18, /* 1 byte, storage method */
125  PRD_UNKNOWN1 = 19, /* 1 byte */
126  PRD_UNKNOWN2 = 20, /* 2 bytes */
127  PRD_BAYER_PATTERN = 22 /* 2 bytes, CFA pattern */
128  };
129 
130  enum {
131  STORAGE_TYPE_UNPACKED = 0x52, /* Unpacked storage (D5, D7xx) */
132  STORAGE_TYPE_PACKED = 0x59 /* Packed storage (A1, A2, Maxxum/Dynax) */
133  };
134 
135  enum {
136  BAYER_PATTERN_RGGB = 0x0001,
137  BAYER_PATTERN_GBRG = 0x0004 /* A200 */
138  };
139 
140  /* Known offsets in WBG block.
141  */
142  enum {
143  WBG_DENOMINATOR_R = 0, /* 1 byte, log2(denominator)-6 */
144  WBG_DENOMINATOR_G1 = 1, /* 1 byte, To get actual denominator, 1<<(val+6) */
145  WBG_DENOMINATOR_G2 = 2, /* 1 byte, */
146  WBG_DENOMINATOR_B = 3, /* 1 byte, */
147  WBG_NOMINATOR_R = 4, /* 2 bytes, */
148  WBG_NOMINATOR_G1 = 6, /* 2 bytes, */
149  WBG_NOMINATOR_G2 = 8, /* 2 bytes, */
150  WBG_NOMINATOR_B = 10 /* 2 bytes, */
151  };
152 
153  /* Known offsets in RIF block.
154  */
155  enum {
156  RIF_UNKNOWN1 = 0, /* 1 byte, */
157  RIF_SATURATION = 1, /* 1 byte, saturation setting from -3 to 3 */
158  RIF_CONTRAST = 2, /* 1 byte, contrast setting from -3 to 3 */
159  RIF_SHARPNESS = 3, /* 1 byte, sharpness setting from -1 (soft) to 1 (hard) */
160  RIF_WHITE_BALANCE = 4, /* 1 byte, white balance setting */
161  RIF_SUBJECT_PROGRAM = 5, /* 1 byte, subject program setting */
162  RIF_FILM_SPEED = 6, /* 1 byte, iso = 2^(value/8-1) * 3.125 */
163  RIF_COLOR_MODE = 7, /* 1 byte, color mode setting */
164  RIF_COLOR_FILTER = 56, /* 1 byte, color filter setting from -3 to 3 */
165  RIF_BANDW_FILTER = 57 /* 1 byte, black and white filter setting from 0 to 10 */
166  };
167 
168  enum {
169  WHITE_BALANCE_AUTO = 0,
170  WHITE_BALANCE_DAYLIGHT = 1,
171  WHITE_BALANCE_CLOUDY = 2,
172  WHITE_BALANCE_TUNGSTEN = 3,
173  WHITE_BALANCE_FLUORESCENT = 4
174  };
175 
176  enum {
177  SUBJECT_PROGRAM_NONE = 0,
178  SUBJECT_PROGRAM_PORTRAIT = 1,
179  SUBJECT_PROGRAM_TEXT = 2,
180  SUBJECT_PROGRAM_NIGHT_PORTRAIT = 3,
181  SUBJECT_PROGRAM_SUNSET = 4,
182  SUBJECT_PROGRAM_SPORTS_ACTION = 5
183  };
184 
185  enum {
186  COLOR_MODE_NORMAL = 0,
187  COLOR_MODE_BLACK_AND_WHITE = 1,
188  COLOR_MODE_VIVID_COLOR = 2, /* D7i, D7Hi */
189  COLOR_MODE_SOLARIZATION = 3, /* D7i, D7Hi */
190  COLOR_MODE_ADOBE_RGB = 4 /* D7Hi */
191  };
192 
193 
194  /* Known tags found in the main IFD directory.
195  */
196  enum {
197  IFDTAG_WIDTH = 0x0100, /* Image width. */
198  IFDTAG_HEIGHT = 0x0101, /* Image height. */
199  IFDTAG_COMPRESS = 0x0103, /* Compression. */
200  IFDTAG_DCFVER = 0x010E, /* DCF version (string). */
201  IFDTAG_MANUF = 0x010F, /* Manufacturer (string). */
202  IFDTAG_CAMERA = 0x0110, /* Camera name (string). */
203  IFDTAG_FIRMWARE = 0x0131, /* Firmware version (string). */
204  IFDTAG_DATETIME = 0x0132, /* Date time (string). */
205  IFDTAG_EXIFOFFSET = 0x8769, /* Offset of EXIF data (long). */
206  IFDTAG_PIMOFFSET = 0xC4A5 /* Offset of PIM info (some cameras only). */
207  };
208 
209  /* Known tags found in the Manufacturer's directory. */
210  enum {
211  MRWTAG_THUMBNAIL = 0x0081, /* Offset to Thumbnail data (early cameras only). */
212  MRWTAG_THUMBNAIL_OFFSET = 0x0088,
213  MRWTAG_THUMBNAIL_LENGTH = 0x0089
214  };
215 
216 
217  }
218 
222  : public IFDFileContainer
223  {
224  public:
225  MRWContainer(IO::Stream *file, off_t offset = 0);
227  virtual ~MRWContainer();
228 
233  isMagicHeader(const char *p, int len);
234 
235  /* Known datablocks within an MRW file.
236  */
237  MRW::DataBlock::Ref mrm;
238  MRW::DataBlock::Ref prd;
239  MRW::DataBlock::Ref ttw;
240  MRW::DataBlock::Ref wbg;
241  MRW::DataBlock::Ref rif;
242 
246  {
247  /* The pixel data immediately follows the MRM datablock. */
248  return mrm->offset() + MRW::DataBlockHeaderLength + mrm->length();
249  }
250  protected:
251  virtual bool locateDirsPreHook();
252  private:
253  std::string m_version;
254 
255  /* DRM: restrict copying. */
256  MRWContainer(const MRWContainer &);
257  MRWContainer & operator=(const MRWContainer &);
258  };
259 
260 
261  }
262 }
263 
264 #endif
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:33
virtual IFDFileContainer::EndianType isMagicHeader(const char *p, int len)
DataBlock(off_t start, MRWContainer *container)
uint16_t uint16_val(off_t offset)
base virtual class for IO
Definition: stream.h:40
uint8_t uint8_val(off_t offset)