~ubuntu-branches/ubuntu/precise/exiv2/precise

« back to all changes in this revision

Viewing changes to src/crwimage.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2006-12-07 18:40:10 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20061207184010-0ouu8v0dr8nznob9
Tags: 0.12-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 */
21
21
/*
22
22
  File:      crwimage.cpp
23
 
  Version:   $Rev: 754 $
 
23
  Version:   $Rev: 861 $
24
24
  Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
25
25
  History:   28-Aug-05, ahu: created
26
26
 
27
27
 */
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 $")
31
31
 
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 {
75
75
    public:
 
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);
78
80
    private:
79
81
        // DATA
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),
236
238
            throw Error(33);
237
239
        }
238
240
        clearMetadata();
239
 
 
240
 
        // Read the image into a memory buffer
241
 
        long len = io_->size();
242
 
        DataBuf buf(len);
243
 
        io_->read(buf.pData_, len);
244
 
        if (io_->error() || io_->eof()) throw Error(14);
245
 
 
246
 
        CrwParser::decode(this, buf.pData_, buf.size_);
 
241
        CrwParser::decode(this, io_->mmap(), io_->size());
 
242
 
247
243
    } // CrwImage::readMetadata
248
244
 
249
245
    void CrwImage::writeMetadata()
343
339
        doAdd(component);
344
340
    }
345
341
 
346
 
    void CiffEntry::doAdd(AutoPtr component)
 
342
    void CiffEntry::doAdd(AutoPtr /*component*/)
347
343
    {
348
344
        throw Error(34, "CiffEntry::add");
349
345
    } // CiffEntry::doAdd
787
783
        return doAdd(crwDirs, crwTagId);
788
784
    } // CiffComponent::add
789
785
 
790
 
    CiffComponent* CiffComponent::doAdd(CrwDirs& crwDirs, uint16_t crwTagId)
 
786
    CiffComponent* CiffComponent::doAdd(CrwDirs& /*crwDirs*/, uint16_t /*crwTagId*/)
791
787
    {
792
788
        return 0;
793
789
    } // CiffComponent::doAdd
865
861
        return doRemove(crwDirs, crwTagId);
866
862
    } // CiffComponent::remove
867
863
 
868
 
    void CiffComponent::doRemove(CrwDirs& crwDirs, uint16_t crwTagId)
 
864
    void CiffComponent::doRemove(CrwDirs& /*crwDirs*/, uint16_t /*crwTagId*/)
869
865
    {
870
866
        // do nothing
871
867
    } // CiffComponent::doRemove
949
945
    } // CrwMap::decode0x0805
950
946
 
951
947
    void CrwMap::decode0x080a(const CiffComponent& ciffComponent,
952
 
                              const CrwMapping*    pCrwMapping,
 
948
                              const CrwMapping*    /*pCrwMapping*/,
953
949
                                    Image&         image,
954
950
                                    ByteOrder      byteOrder)
955
951
    {
992
988
 
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;
998
995
        }
999
996
        assert(ifdId != ifdIdNotSet);
1000
997
 
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();
1012
1009
            c += n;
1013
1010
        }
1014
1011
 
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
1144
1141
 
1145
1142
    void CrwMap::encode(CiffHeader* pHead, const Image& image)
1146
1143
    {
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);
1151
1147
            }
1239
1235
 
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;
1245
1242
        }
1246
1243
        assert(ifdId != ifdIdNotSet);
1247
1244
        DataBuf buf = packIfdId(image.exifData(), ifdId, pHead->byteOrder());
1348
1345
 
1349
1346
    Image::AutoPtr newCrwInstance(BasicIo::AutoPtr io, bool create)
1350
1347
    {
1351
 
        Image::AutoPtr image = Image::AutoPtr(new CrwImage(io, create));
 
1348
        Image::AutoPtr image(new CrwImage(io, create));
1352
1349
        if (!image->good()) {
1353
1350
            image.reset();
1354
1351
        }
1412
1409
        { 8,   90 },
1413
1410
        { 8, -270 },
1414
1411
        // last entry
1415
 
        { 0,    0 },
 
1412
        { 0,    0 }
1416
1413
    };
1417
1414
 
1418
1415
    uint16_t RotationMap::orientation(int32_t degrees)