1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
|
/*
* libopenraw - ciffcontainer.h
*
* Copyright (C) 2006,2008 Hubert Figuiere
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
/**
* @brief CIFF is the container for CRW files. It is an attempt from Canon to
* make this a standard. I guess it failed.
*/
#ifndef _CIFFCONTAINER_H_
#define _CIFFCONTAINER_H_
#include <vector>
#include <boost/shared_ptr.hpp>
#include "rawcontainer.h"
#include "debug.h"
namespace OpenRaw {
namespace Internals {
class CIFFContainer;
namespace CIFF {
/** mask for the typeCode */
enum {
STORAGELOC_MASK = 0xc000, /**< storage location bit mask */
FORMAT_MASK = 0x3800, /**< format of the data */
TAGCODE_MASK = 0x3fff /**< include the format, because the last
* part is non significant */
};
/** tags for the CIFF records.
* List made by a combination of the CIFF spec and
* what exifprobe by Duane H. Hesser has.
*/
enum {
TAG_NULLRECORD = 0x0000,
TAG_FREEBYTES = 0x0001,
TAG_COLORINFO1 = 0x0032,
TAG_FILEDESCRIPTION = 0x0805,
TAG_RAWMAKEMODEL = 0x080a,
TAG_FIRMWAREVERSION = 0x080b,
TAG_COMPONENTVERSION = 0x080c,
TAG_ROMOPERATIONMODE = 0x080d,
TAG_OWNERNAME = 0x0810,
TAG_IMAGETYPE = 0x0815,
TAG_ORIGINALFILENAME = 0x0816,
TAG_THUMBNAILFILENAME = 0x0817,
TAG_TARGETIMAGETYPE = 0x100a,
TAG_SHUTTERRELEASEMETHOD = 0x1010,
TAG_SHUTTERRELEASETIMING = 0x1011,
TAG_RELEASESETTING = 0x1016,
TAG_BASEISO = 0x101c,
TAG_FOCALLENGTH = 0x1029,
TAG_SHOTINFO = 0x102a,
TAG_COLORINFO2 = 0x102c,
TAG_CAMERASETTINGS = 0x102d,
TAG_SENSORINFO = 0x1031,
TAG_CUSTOMFUNCTIONS = 0x1033,
TAG_PICTUREINFO = 0x1038,
TAG_WHITEBALANCETABLE = 0x10a9,
TAG_COLORSPACE = 0x10b4,
TAG_IMAGESPEC = 0x1803,
TAG_RECORDID = 0x1804,
TAG_SELFTIMERTIME = 0x1806,
TAG_TARGETDISTANCESETTING = 0x1807,
TAG_SERIALNUMBER = 0x180b,
TAG_CAPTUREDTIME = 0x180e,
TAG_IMAGEINFO = 0x1810,
TAG_FLASHINFO = 0x1813,
TAG_MEASUREDEV = 0x1814,
TAG_FILENUMBER = 0x1817,
TAG_EXPOSUREINFO = 0x1818,
TAG_DECODERTABLE = 0x1835,
TAG_RAWIMAGEDATA = 0x2005,
TAG_JPEGIMAGE = 0x2007,
TAG_JPEGTHUMBNAIL = 0x2008,
TAG_IMAGEDESCRIPTION = 0x2804,
TAG_CAMERAOBJECT = 0x2807,
TAG_SHOOTINGRECORD = 0x3002,
TAG_MEASUREDINFO = 0x3003,
TAG_CAMERASPECIFICATION = 0x3004,
TAG_IMAGEPROPS = 0x300a,
TAG_EXIFINFORMATION = 0x300b
};
class Heap;
class ImageSpec
{
public:
ImageSpec()
: imageWidth(0), imageHeight(0),
pixelAspectRatio(0), rotationAngle(0),
componentBitDepth(0), colorBitDepth(0),
colorBW(0)
{
}
/** read the struct from container
* @param offset the offset to read from, relative
* to the begining of the container.
* @param container the container to read from.
*/
bool readFrom(off_t offset, CIFFContainer *container);
int32_t exifOrientation() const;
uint32_t imageWidth;
uint32_t imageHeight;
uint32_t /*float32*/pixelAspectRatio;
int32_t rotationAngle;
uint32_t componentBitDepth;
uint32_t colorBitDepth;
uint32_t colorBW;
};
class RecordEntry
{
public:
typedef std::vector<RecordEntry> List;
RecordEntry();
/** load record from container
* @param container the container
* @return true if success
*/
bool readFrom(CIFFContainer *container);
/** fetch data define by the record from the heap
* @param heap the heap to load from
* @param buf the allocated buffer to load into
* @param size the size of the allocated buffer
* @return the size actually fetched. MIN(size, this->length);
*/
size_t fetchData(Heap* heap, void* buf, size_t size) const;
/** determine if entry match type code
* @param _typeCode the code to check
* @return true if match
*/
bool isA(uint16_t _typeCode) const
{
Debug::Trace(DEBUG2) << "typeCode = " << typeCode << "\n";
return typeCode == (TAGCODE_MASK & _typeCode);
}
uint16_t typeCode;/* type code of the record */
uint32_t length;/* record length */
uint32_t offset;/* offset of the record in the heap*/
};
/** a CIFF Heap */
class Heap
{
public:
typedef boost::shared_ptr<Heap> Ref;
/** Construct a heap from a location in the container
* @param start the begin address relative to the container.
* @param length the length in bytes
* @param container the container to read from
*/
Heap(off_t start, off_t length, CIFFContainer * container);
RecordEntry::List & records();
CIFFContainer *container()
{
return m_container;
}
/** Eeturn the offset from the begining of the container. */
off_t offset()
{
return m_start;
}
private:
bool _loadRecords();
Heap(const Heap &);
Heap & operator=(const Heap &);
off_t m_start;
off_t m_length;
CIFFContainer *m_container;
RecordEntry::List m_records;
};
/** Heap Header of CIFF file*/
class HeapFileHeader
{
public:
bool readFrom(CIFFContainer *);
char byteOrder[2];/* 'MM' for Motorola,'II' for Intel */
uint32_t headerLength;/* length of header (in bytes) */
char type[4];
char subType[4];
uint32_t version; /* higher word: 0x0001, Lower word: 0x0002 */
//uint32_t reserved1;
//uint32_t reserved2;
RawContainer::EndianType endian;
};
}
/** CIFF container
* as described by the CIFF documentation
*/
class CIFFContainer
: public RawContainer
{
public:
CIFFContainer(IO::Stream *file);
virtual ~CIFFContainer();
CIFF::Heap::Ref heap();
const CIFF::HeapFileHeader & header() const
{
return m_hdr;
}
CIFF::Heap::Ref getImageProps();
const CIFF::RecordEntry * getRawDataRecord() const;
const CIFF::ImageSpec * getImageSpec();
const CIFF::Heap::Ref getCameraProps();
private:
bool _loadHeap();
EndianType _readHeader();
CIFFContainer(const CIFFContainer &);
CIFFContainer & operator=(const CIFFContainer &);
friend class CIFF::HeapFileHeader;
CIFF::HeapFileHeader m_hdr;
CIFF::Heap::Ref m_heap;
CIFF::Heap::Ref m_imageprops;
bool m_hasImageSpec;
CIFF::ImageSpec m_imagespec;
CIFF::Heap::Ref m_cameraprops;
};
}
}
#endif
|