mrwcontainer.h

00001 /*
00002  * libopenraw - mrwcontainer.h
00003  *
00004  * Copyright (C) 2006 Hubert Figuiere
00005  * Copyright (C) 2008 Bradley Broom
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
00020  */
00021 
00022 
00023 #ifndef _MRW_CONTAINER_H__
00024 #define _MRW_CONTAINER_H__
00025 
00026 #include <string>
00027 #include <boost/config.hpp>
00028 #include <boost/shared_ptr.hpp>
00029 
00030 #include "ifdfilecontainer.h"
00031 
00032 namespace OpenRaw {
00033     namespace Internals {
00034 
00035         class IOFile;
00036 
00037         class MRWContainer;
00038 
00039         namespace MRW {
00040 
00041             const int DataBlockHeaderLength = 8;    /* Number of bytes in a block header. */
00042 
00045             class DataBlock
00046             {
00047             public:
00048                 typedef boost::shared_ptr<DataBlock> Ref;
00049                 typedef std::vector<Ref> RefVec;
00050 
00055                 DataBlock(off_t start, MRWContainer * container);
00056 
00059                 off_t offset()
00060                     {
00061                         return m_start;
00062                     }
00063 
00066                 off_t length()
00067                     {
00068                         return m_length;
00069                     }
00070 
00073                 std::string name()
00074                     {
00075                         char id[4];
00076                         id[0] = m_name[1];
00077                         id[1] = m_name[2];
00078                         id[2] = m_name[3];
00079                         id[3] = 0;
00080                         return std::string(id);
00081                     }
00082 
00085                 int8_t int8_val (off_t offset);
00086 
00089                 uint8_t uint8_val (off_t offset);
00090 
00093                 uint16_t uint16_val (off_t offset);
00094                 bool loaded() const
00095                     {
00096                         return m_loaded;
00097                     }
00098 
00099             private:
00100                 /* DRM: protection from copies. */
00101                 DataBlock(const DataBlock &);
00102                 DataBlock & operator=(const DataBlock &);
00103 
00104                 off_t m_start;
00105                 char m_name[4];
00106                 int32_t m_length;
00107                 MRWContainer *m_container;
00108                 bool m_loaded;
00109             };
00110 
00111             /* Known offsets in PRD block.
00112              */
00113             enum {
00114                 PRD_VERSION     = 0,    /* 8 chars, version string */
00115                 PRD_SENSOR_LENGTH   = 8,    /* 2 bytes, Number of lines in raw data */
00116                 PRD_SENSOR_WIDTH    = 10,   /* 2 bytes, Number of pixels per line */
00117                 PRD_IMAGE_LENGTH    = 12,   /* 2 bytes, length of image after Divu processing */
00118                 PRD_IMAGE_WIDTH     = 14,   /* 2 bytes, width of image after Divu processing */
00119                 PRD_DATA_SIZE       = 16,   /* 1 byte,  number of bits used to store each pixel */
00120                 PRD_PIXEL_SIZE      = 17,   /* 1 byte,  number of valid bits per pixel */
00121                 PRD_STORAGE_TYPE    = 18,   /* 1 byte,  storage method */
00122                 PRD_UNKNOWN1        = 19,   /* 1 byte */
00123                 PRD_UNKNOWN2        = 20,   /* 2 bytes */
00124                 PRD_BAYER_PATTERN   = 22    /* 2 bytes, CFA pattern */
00125             };
00126 
00127             enum {
00128                 STORAGE_TYPE_UNPACKED   = 0x52, /* Unpacked storage (D5, D7xx) */
00129                 STORAGE_TYPE_PACKED = 0x59  /* Packed storage (A1, A2, Maxxum/Dynax) */
00130             };
00131 
00132             enum {
00133                 BAYER_PATTERN_RGGB  = 0x0001,
00134                 BAYER_PATTERN_GBRG  = 0x0004    /* A200 */
00135             };
00136 
00137             /* Known offsets in WBG block.
00138              */
00139             enum {
00140                 WBG_DENOMINATOR_R   = 0,    /* 1 byte,  log2(denominator)-6 */
00141                 WBG_DENOMINATOR_G1  = 1,    /* 1 byte,  To get actual denominator, 1<<(val+6) */
00142                 WBG_DENOMINATOR_G2  = 2,    /* 1 byte, */
00143                 WBG_DENOMINATOR_B   = 3,    /* 1 byte, */
00144                 WBG_NOMINATOR_R     = 4,    /* 2 bytes, */
00145                 WBG_NOMINATOR_G1    = 6,    /* 2 bytes, */
00146                 WBG_NOMINATOR_G2    = 8,    /* 2 bytes, */
00147                 WBG_NOMINATOR_B     = 10    /* 2 bytes, */
00148             };
00149 
00150             /* Known offsets in RIF block.
00151              */
00152             enum {
00153                 RIF_UNKNOWN1        = 0,    /* 1 byte,  */
00154                 RIF_SATURATION      = 1,    /* 1 byte,  saturation setting from -3 to 3 */
00155                 RIF_CONTRAST        = 2,    /* 1 byte,  contrast setting from -3 to 3 */
00156                 RIF_SHARPNESS       = 3,    /* 1 byte,  sharpness setting from -1 (soft) to 1 (hard) */
00157                 RIF_WHITE_BALANCE   = 4,    /* 1 byte,  white balance setting */
00158                 RIF_SUBJECT_PROGRAM = 5,    /* 1 byte,  subject program setting */
00159                 RIF_FILM_SPEED      = 6,    /* 1 byte,  iso = 2^(value/8-1) * 3.125 */
00160                 RIF_COLOR_MODE      = 7,    /* 1 byte,  color mode setting */
00161                 RIF_COLOR_FILTER    = 56,   /* 1 byte,  color filter setting from -3 to 3 */
00162                 RIF_BANDW_FILTER    = 57    /* 1 byte,  black and white filter setting from 0 to 10 */
00163             };
00164 
00165             enum {
00166                 WHITE_BALANCE_AUTO  = 0,
00167                 WHITE_BALANCE_DAYLIGHT  = 1,
00168                 WHITE_BALANCE_CLOUDY    = 2,
00169                 WHITE_BALANCE_TUNGSTEN  = 3,
00170                 WHITE_BALANCE_FLUORESCENT = 4
00171             };
00172 
00173             enum {
00174                 SUBJECT_PROGRAM_NONE        = 0,
00175                 SUBJECT_PROGRAM_PORTRAIT    = 1,
00176                 SUBJECT_PROGRAM_TEXT        = 2,
00177                 SUBJECT_PROGRAM_NIGHT_PORTRAIT  = 3,
00178                 SUBJECT_PROGRAM_SUNSET      = 4,
00179                 SUBJECT_PROGRAM_SPORTS_ACTION   = 5
00180             };
00181 
00182             enum {
00183                 COLOR_MODE_NORMAL       = 0,
00184                 COLOR_MODE_BLACK_AND_WHITE  = 1,
00185                 COLOR_MODE_VIVID_COLOR      = 2,    /* D7i, D7Hi */
00186                 COLOR_MODE_SOLARIZATION     = 3,    /* D7i, D7Hi */
00187                 COLOR_MODE_ADOBE_RGB        = 4     /* D7Hi */
00188             };
00189 
00190 
00191             /* Known tags found in the main IFD directory.
00192              */
00193             enum {
00194                 IFDTAG_WIDTH            = 0x0100,  /* Image width. */
00195                 IFDTAG_HEIGHT           = 0x0101,  /* Image height. */
00196                 IFDTAG_COMPRESS         = 0x0103,  /* Compression. */
00197                 IFDTAG_DCFVER           = 0x010E,  /* DCF version (string). */
00198                 IFDTAG_MANUF            = 0x010F,  /* Manufacturer (string). */
00199                 IFDTAG_CAMERA           = 0x0110,  /* Camera name (string). */
00200                 IFDTAG_FIRMWARE         = 0x0131,  /* Firmware version (string). */
00201                 IFDTAG_DATETIME         = 0x0132,  /* Date time (string). */
00202                 IFDTAG_EXIFOFFSET       = 0x8769,  /* Offset of EXIF data (long). */
00203                 IFDTAG_PIMOFFSET        = 0xC4A5   /* Offset of PIM info (some cameras only). */
00204             };
00205 
00206             /* Known tags found in the Manufacturer's directory. */
00207             enum {
00208                 MRWTAG_THUMBNAIL    = 0x0081,   /* Offset to Thumbnail data (early cameras only). */
00209                 MRWTAG_THUMBNAIL_OFFSET = 0x0088,
00210                 MRWTAG_THUMBNAIL_LENGTH = 0x0089
00211             };
00212 
00213 
00214         }
00215 
00218         class MRWContainer
00219             : public IFDFileContainer
00220         {
00221         public:
00222             MRWContainer(IO::Stream *file, off_t offset = 0);
00224             virtual ~MRWContainer();
00225 
00229             virtual IFDFileContainer::EndianType 
00230             isMagicHeader(const char *p, int len);
00231 
00232             /* Known datablocks within an MRW file.
00233              */
00234             MRW::DataBlock::Ref mrm;
00235             MRW::DataBlock::Ref prd;
00236             MRW::DataBlock::Ref ttw;
00237             MRW::DataBlock::Ref wbg;
00238             MRW::DataBlock::Ref rif;
00239 
00242             off_t pixelDataOffset()
00243                 {
00244                     /* The pixel data immediately follows the MRM datablock. */
00245                     return mrm->offset() + MRW::DataBlockHeaderLength + mrm->length();
00246                 }
00247         protected:
00248             virtual bool locateDirsPreHook();
00249         private:
00250             std::string m_version;
00251 
00252             /* DRM: restrict copying. */
00253             MRWContainer(const MRWContainer &);
00254             MRWContainer & operator=(const MRWContainer &);
00255         };
00256 
00257 
00258     }
00259 }
00260 
00261 #endif

Generated on Sat Nov 7 19:23:18 2009 for libopenraw by  doxygen 1.5.8