24
24
Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
25
25
History: 28-Aug-05, ahu: created
28
28
// *****************************************************************************
29
29
#include "rcsid.hpp"
30
EXIV2_RCSID("@(#) $Id: crwimage.cpp 754 2006-05-05 17:38:12Z ahuggel $");
30
EXIV2_RCSID("@(#) $Id: crwimage.cpp 861 2006-08-15 14:40:34Z ahuggel $")
32
32
// Define DEBUG to output debug information to std::cerr, e.g, by calling make
33
33
// like this: make DEFS=-DDEBUG crwimage.o
73
73
//! Helper class to map Exif orientation values to CRW rotation degrees
74
74
class RotationMap {
76
//! Get the orientation number for a degree value
76
77
static uint16_t orientation(int32_t degrees);
78
//! Get the degree value for an orientation number
77
79
static int32_t degrees(uint16_t orientation);
113
115
CrwMapping(0x102a, 0x300b, 0, 0x0004, canonIfdId, decodeArray, encodeArray),
114
116
CrwMapping(0x102d, 0x300b, 0, 0x0001, canonIfdId, decodeArray, encodeArray),
115
117
CrwMapping(0x1033, 0x300b, 0, 0x000f, canonIfdId, decodeArray, encodeArray),
116
CrwMapping(0x1038, 0x300b, 0, 0x0012, canonIfdId, decodeBasic, encodeBasic),
118
CrwMapping(0x1038, 0x300b, 0, 0x0012, canonIfdId, decodeArray, encodeArray),
117
119
CrwMapping(0x10a9, 0x300b, 0, 0x00a9, canonIfdId, decodeBasic, encodeBasic),
118
120
// Mapped to Exif.Photo.ColorSpace instead (see below)
119
121
//CrwMapping(0x10b4, 0x300b, 0, 0x00b4, canonIfdId, decodeBasic, encodeBasic),
240
// Read the image into a memory buffer
241
long len = io_->size();
243
io_->read(buf.pData_, len);
244
if (io_->error() || io_->eof()) throw Error(14);
246
CrwParser::decode(this, buf.pData_, buf.size_);
241
CrwParser::decode(this, io_->mmap(), io_->size());
247
243
} // CrwImage::readMetadata
249
245
void CrwImage::writeMetadata()
787
783
return doAdd(crwDirs, crwTagId);
788
784
} // CiffComponent::add
790
CiffComponent* CiffComponent::doAdd(CrwDirs& crwDirs, uint16_t crwTagId)
786
CiffComponent* CiffComponent::doAdd(CrwDirs& /*crwDirs*/, uint16_t /*crwTagId*/)
793
789
} // CiffComponent::doAdd
865
861
return doRemove(crwDirs, crwTagId);
866
862
} // CiffComponent::remove
868
void CiffComponent::doRemove(CrwDirs& crwDirs, uint16_t crwTagId)
864
void CiffComponent::doRemove(CrwDirs& /*crwDirs*/, uint16_t /*crwTagId*/)
871
867
} // CiffComponent::doRemove
949
945
} // CrwMap::decode0x0805
951
947
void CrwMap::decode0x080a(const CiffComponent& ciffComponent,
952
const CrwMapping* pCrwMapping,
948
const CrwMapping* /*pCrwMapping*/,
954
950
ByteOrder byteOrder)
993
989
IfdId ifdId = ifdIdNotSet;
994
990
switch (pCrwMapping->tag_) {
995
case 0x0001: ifdId = canonCs1IfdId; break;
996
case 0x0004: ifdId = canonCs2IfdId; break;
997
case 0x000f: ifdId = canonCfIfdId; break;
991
case 0x0001: ifdId = canonCsIfdId; break;
992
case 0x0004: ifdId = canonSiIfdId; break;
993
case 0x000f: ifdId = canonCfIfdId; break;
994
case 0x0012: ifdId = canonPiIfdId; break;
999
996
assert(ifdId != ifdIdNotSet);
1004
1001
uint16_t n = 1;
1005
1002
ExifKey key(c, ifdItem);
1006
1003
UShortValue value;
1007
if (ifdId == canonCs1IfdId && c == 23 && ciffComponent.size() > 50) n = 3;
1004
if (ifdId == canonCsIfdId && c == 23 && ciffComponent.size() > 50) n = 3;
1008
1005
value.read(ciffComponent.pData() + c*2, n*2, byteOrder);
1009
1006
image.exifData().add(key, &value);
1010
if (ifdId == canonCs2IfdId && c == 21) aperture = value.toLong();
1011
if (ifdId == canonCs2IfdId && c == 22) shutterSpeed = value.toLong();
1007
if (ifdId == canonSiIfdId && c == 21) aperture = value.toLong();
1008
if (ifdId == canonSiIfdId && c == 22) shutterSpeed = value.toLong();
1015
if (ifdId == canonCs2IfdId) {
1012
if (ifdId == canonSiIfdId) {
1016
1013
// Exif.Photo.FNumber
1017
1014
float f = fnumber(canonEv(aperture));
1018
1015
// Beware: primitive conversion algorithm
1145
1142
void CrwMap::encode(CiffHeader* pHead, const Image& image)
1147
for (const CrwMapping* cmi = crwMapping_;
1148
cmi->ifdId_ != ifdIdNotSet; ++cmi) {
1144
for (const CrwMapping* cmi = crwMapping_; cmi->ifdId_ != ifdIdNotSet; ++cmi) {
1149
1145
if (cmi->fromExif_ != 0) {
1150
1146
cmi->fromExif_(image, cmi, pHead);
1240
1236
IfdId ifdId = ifdIdNotSet;
1241
1237
switch (pCrwMapping->tag_) {
1242
case 0x0001: ifdId = canonCs1IfdId; break;
1243
case 0x0004: ifdId = canonCs2IfdId; break;
1244
case 0x000f: ifdId = canonCfIfdId; break;
1238
case 0x0001: ifdId = canonCsIfdId; break;
1239
case 0x0004: ifdId = canonSiIfdId; break;
1240
case 0x000f: ifdId = canonCfIfdId; break;
1241
case 0x0012: ifdId = canonPiIfdId; break;
1246
1243
assert(ifdId != ifdIdNotSet);
1247
1244
DataBuf buf = packIfdId(image.exifData(), ifdId, pHead->byteOrder());
1349
1346
Image::AutoPtr newCrwInstance(BasicIo::AutoPtr io, bool create)
1351
Image::AutoPtr image = Image::AutoPtr(new CrwImage(io, create));
1348
Image::AutoPtr image(new CrwImage(io, create));
1352
1349
if (!image->good()) {