~ubuntu-branches/ubuntu/wily/exiv2/wily-proposed

« back to all changes in this revision

Viewing changes to src/tiffvisitor.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2009-04-29 21:53:40 UTC
  • mfrom: (1.1.9 upstream) (11.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090429215340-07gk8utx2w8rh0bo
* New upstream release
  - (Closes: #525535): "[libexiv2-5] New upstream version 0.18.1"
  - write-support for Adobe Photoshop PSD images
  - read-support for Panasonic RW2 images
  - Panasonic and Nikon makernote update
* Upload to unstable - discussed on debian-release
  - libexiv2-5 library transition
* Fix: package-lacks-versioned-build-depends-on-debhelper
* Add ${misc:Depends}

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// ***************************************************************** -*- C++ -*-
2
2
/*
3
 
 * Copyright (C) 2004-2008 Andreas Huggel <ahuggel@gmx.net>
 
3
 * Copyright (C) 2004-2009 Andreas Huggel <ahuggel@gmx.net>
4
4
 *
5
5
 * This program is part of the Exiv2 distribution.
6
6
 *
20
20
 */
21
21
/*
22
22
  File:      tiffvisitor.cpp
23
 
  Version:   $Rev: 1702 $
 
23
  Version:   $Rev: 1773 $
24
24
  Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
25
25
  History:   11-Apr-06, ahu: created
26
26
 */
27
27
// *****************************************************************************
28
28
#include "rcsid.hpp"
29
 
EXIV2_RCSID("@(#) $Id: tiffvisitor.cpp 1702 2008-12-15 15:16:33Z ahuggel $")
 
29
EXIV2_RCSID("@(#) $Id: tiffvisitor.cpp 1773 2009-03-21 10:03:38Z ahuggel $")
30
30
 
31
31
// *****************************************************************************
32
32
// included header files
56
56
// *****************************************************************************
57
57
namespace {
58
58
    //! Unary predicate that matches an Exifdatum with a given group and index.
59
 
    class FindExifdatum {
 
59
    class FindExifdatum2 {
60
60
    public:
61
61
        //! Constructor, initializes the object with the group and index to look for.
62
 
        FindExifdatum(uint16_t group, int idx)
 
62
        FindExifdatum2(uint16_t group, int idx)
63
63
            : groupName_(Exiv2::Internal::tiffGroupName(group)), idx_(idx) {}
64
64
        //! Returns true if group and index match.
65
65
        bool operator()(const Exiv2::Exifdatum& md) const
71
71
        const char* groupName_;
72
72
        int idx_;
73
73
 
74
 
    }; // class FindExifdatum
 
74
    }; // class FindExifdatum2
75
75
}
76
76
 
77
77
// *****************************************************************************
640
640
                    // Try to find exact match (in case of duplicate tags)
641
641
                    ExifData::iterator pos2 =
642
642
                        std::find_if(exifData_.begin(), exifData_.end(),
643
 
                                     FindExifdatum(object->group(), object->idx()));
 
643
                                     FindExifdatum2(object->group(), object->idx()));
644
644
                    if (pos2 != exifData_.end() && pos2->key() == key.key()) {
645
645
                        ed = &(*pos2);
646
646
                        pos = pos2; // make sure we delete the correct tag below
873
873
    }
874
874
 
875
875
    void TiffEncoder::add(
876
 
        TiffComponent*     pRootDir,
877
 
        TiffComponent*     pSourceDir,
878
 
        TiffCompFactoryFct createFct
 
876
        TiffComponent* pRootDir,
 
877
        TiffComponent* pSourceDir,
 
878
        uint32_t       root
879
879
    )
880
880
    {
881
881
        assert(pRootDir != 0);
894
894
            if (group == Group::mn) continue;
895
895
 
896
896
            // Assumption is that the corresponding TIFF entry doesn't exist
897
 
 
898
 
            // Todo: getPath depends on the Creator class, not the createFct
899
 
            //       how to get it through to here???
900
 
 
901
897
            TiffPath tiffPath;
902
 
            TiffCreator::getPath(tiffPath, i->tag(), group);
 
898
            TiffCreator::getPath(tiffPath, i->tag(), group, root);
903
899
            TiffComponent* tc = pRootDir->addPath(i->tag(), tiffPath);
904
900
            TiffEntryBase* object = dynamic_cast<TiffEntryBase*>(tc);
905
901
#ifdef DEBUG
916
912
        }
917
913
    } // TiffEncoder::add
918
914
 
919
 
    const std::string TiffPrinter::indent_("   ");
920
 
 
921
 
    void TiffPrinter::incIndent()
922
 
    {
923
 
        prefix_ += indent_;
924
 
    } // TiffPrinter::incIndent
925
 
 
926
 
    void TiffPrinter::decIndent()
927
 
    {
928
 
        if (prefix_.length() >= indent_.length()) {
929
 
            prefix_.erase(prefix_.length() - indent_.length(), indent_.length());
930
 
        }
931
 
    } // TiffPrinter::decIndent
932
 
 
933
 
    void TiffPrinter::visitEntry(TiffEntry* object)
934
 
    {
935
 
        printTiffEntry(object, prefix());
936
 
    } // TiffPrinter::visitEntry
937
 
 
938
 
    void TiffPrinter::visitDataEntry(TiffDataEntry* object)
939
 
    {
940
 
        printTiffEntry(object, prefix());
941
 
        if (object->pValue()) {
942
 
            os_ << prefix() << _("Data area") << " "
943
 
                << object->pValue()->sizeDataArea()
944
 
                << " " << _("bytes.\n");
945
 
        }
946
 
    } // TiffPrinter::visitDataEntry
947
 
 
948
 
    void TiffPrinter::visitImageEntry(TiffImageEntry* object)
949
 
    {
950
 
        printTiffEntry(object, prefix());
951
 
    } // TiffPrinter::visitImageEntry
952
 
 
953
 
    void TiffPrinter::visitSizeEntry(TiffSizeEntry* object)
954
 
    {
955
 
        printTiffEntry(object, prefix());
956
 
    }
957
 
 
958
 
    void TiffPrinter::visitDirectory(TiffDirectory* object)
959
 
    {
960
 
        assert(object != 0);
961
 
        os_ << prefix() << tiffGroupName(object->group())
962
 
            << " " << _("directory with") << " "
963
 
            // cast to make MSVC happy
964
 
            << std::dec << static_cast<unsigned int>(object->components_.size());
965
 
        if (object->components_.size() == 1) os_ << " " << _("entry:\n");
966
 
        else os_ << " " << _("entries:\n");
967
 
        incIndent();
968
 
 
969
 
    } // TiffPrinter::visitDirectory
970
 
 
971
 
    void TiffPrinter::visitDirectoryNext(TiffDirectory* object)
972
 
    {
973
 
        decIndent();
974
 
        if (object->hasNext()) {
975
 
            if (object->pNext_) os_ << prefix() << _("Next directory:\n");
976
 
            else os_ << prefix() << _("No next directory\n");
977
 
        }
978
 
    } // TiffPrinter::visitDirectoryNext
979
 
 
980
 
    void TiffPrinter::visitDirectoryEnd(TiffDirectory* /*object*/)
981
 
    {
982
 
        // Nothing to do
983
 
    } // TiffPrinter::visitDirectoryEnd
984
 
 
985
 
    void TiffPrinter::visitSubIfd(TiffSubIfd* object)
986
 
    {
987
 
        os_ << prefix() << _("Sub-IFD") << " ";
988
 
        printTiffEntry(object);
989
 
    } // TiffPrinter::visitSubIfd
990
 
 
991
 
    void TiffPrinter::visitMnEntry(TiffMnEntry* object)
992
 
    {
993
 
        if (!object->mn_) printTiffEntry(object, prefix());
994
 
        else os_ << prefix() << _("Makernote") << " ";
995
 
    } // TiffPrinter::visitMnEntry
996
 
 
997
 
    void TiffPrinter::visitIfdMakernote(TiffIfdMakernote* /*object*/)
998
 
    {
999
 
        // Nothing to do
1000
 
    } // TiffPrinter::visitIfdMakernote
1001
 
 
1002
 
    void TiffPrinter::printTiffEntry(TiffEntryBase* object,
1003
 
                                     const std::string& px) const
1004
 
    {
1005
 
        assert(object != 0);
1006
 
 
1007
 
        os_ << px << tiffGroupName(object->group())
1008
 
            << " " << _("tag") << " 0x" << std::setw(4) << std::setfill('0')
1009
 
            << std::hex << std::right << object->tag()
1010
 
            << ", " << _("type") << " 0x" << std::hex << object->tiffType()
1011
 
            << ", " << std::dec << object->count() << " "<< _("component");
1012
 
        if (object->count() > 1) os_ << "s";
1013
 
        os_ << " in " << object->size() << " " << _("bytes");
1014
 
        if (object->size() > 4) os_ << ", " << _("offset") << " " << object->offset();
1015
 
        os_ << "\n";
1016
 
        const Value* vp = object->pValue();
1017
 
        if (vp && vp->count() < 100) os_ << prefix() << *vp;
1018
 
        else os_ << prefix() << "...";
1019
 
        os_ << "\n";
1020
 
 
1021
 
    } // TiffPrinter::printTiffEntry
1022
 
 
1023
 
    void TiffPrinter::visitArrayEntry(TiffArrayEntry* object)
1024
 
    {
1025
 
        os_ << prefix() << _("Array Entry") << " " << tiffGroupName(object->group())
1026
 
            << " " << _("tag") << " 0x" << std::setw(4) << std::setfill('0')
1027
 
            << std::hex << std::right << object->tag() << " " << _("with")
1028
 
            << " " << std::dec << object->count() << " ";
1029
 
        if (object->count() > 1) os_ << _("elements");
1030
 
        else os_ << _("element");
1031
 
        os_ << "\n";
1032
 
    } // TiffPrinter::visitArrayEntry
1033
 
 
1034
 
    void TiffPrinter::visitArrayElement(TiffArrayElement* object)
1035
 
    {
1036
 
        printTiffEntry(object, prefix());
1037
 
    } // TiffPrinter::visitArrayElement
1038
 
 
1039
915
    TiffReader::TiffReader(const byte*    pData,
1040
916
                           uint32_t       size,
1041
917
                           TiffComponent* pRoot,
1067
943
    {
1068
944
        if (state.get() != 0) {
1069
945
            if (pOrigState_ != pState_) delete pState_;
1070
 
            // 0 for create function indicates 'no change'
1071
 
            if (state->createFct_ == 0) state->createFct_ = pState_->createFct_;
1072
946
            // invalidByteOrder indicates 'no change'
1073
947
            if (state->byteOrder_ == invalidByteOrder) state->byteOrder_ = pState_->byteOrder_;
1074
948
            pState_ = state.release();
1087
961
        return pState_->baseOffset_;
1088
962
    }
1089
963
 
1090
 
    TiffComponent::AutoPtr TiffReader::create(uint32_t extendedTag,
1091
 
                                              uint16_t group) const
1092
 
    {
1093
 
        assert(pState_);
1094
 
        assert(pState_->createFct_);
1095
 
        return pState_->createFct_(extendedTag, group);
1096
 
    }
1097
 
 
1098
964
    void TiffReader::readDataEntryBase(TiffDataEntryBase* object)
1099
965
    {
1100
966
        assert(object != 0);
1195
1061
                return;
1196
1062
            }
1197
1063
            uint16_t tag = getUShort(p, byteOrder());
1198
 
            TiffComponent::AutoPtr tc = create(tag, object->group());
 
1064
            TiffComponent::AutoPtr tc = TiffCreator::create(tag, object->group());
1199
1065
            // The assertion typically fails if a component is not configured in
1200
1066
            // the TIFF structure table
1201
1067
            assert(tc.get());
1216
1082
            TiffComponent::AutoPtr tc(0);
1217
1083
            uint32_t next = getLong(p, byteOrder());
1218
1084
            if (next) {
1219
 
                tc = create(Tag::next, object->group());
 
1085
                tc = TiffCreator::create(Tag::next, object->group());
1220
1086
#ifndef SUPPRESS_WARNINGS
1221
1087
                if (tc.get() == 0) {
1222
1088
                    std::cerr << "Warning: "
1447
1313
        const uint16_t sz = static_cast<uint16_t>(object->size_ / object->elSize());
1448
1314
        for (uint16_t i = 0; i < sz; ++i) {
1449
1315
            uint16_t tag = i;
1450
 
            TiffComponent::AutoPtr tc = create(tag, object->elGroup());
 
1316
            TiffComponent::AutoPtr tc = TiffCreator::create(tag, object->elGroup());
1451
1317
            assert(tc.get());
1452
1318
            tc->setStart(object->pData() + i * object->elSize());
1453
1319
            object->addChild(tc);