From c9d2936dcbf43fa8823a1326b78928ef8a408bdf Mon Sep 17 00:00:00 2001 From: postscript-dev Date: Mon, 11 Jul 2022 22:01:20 +0100 Subject: [PATCH 1/5] Add tagDesc() to (Exif|Xmp|Iptc) Datums and Keys --- include/exiv2/datasets.hpp | 1 + include/exiv2/exif.hpp | 1 + include/exiv2/iptc.hpp | 1 + include/exiv2/metadatum.hpp | 4 ++++ include/exiv2/properties.hpp | 1 + include/exiv2/tags.hpp | 3 +-- include/exiv2/xmp_exiv2.hpp | 1 + src/datasets.cpp | 4 ++++ src/exif.cpp | 4 ++++ src/iptc.cpp | 4 ++++ src/properties.cpp | 7 +++++++ src/xmp.cpp | 4 ++++ 12 files changed, 33 insertions(+), 2 deletions(-) diff --git a/include/exiv2/datasets.hpp b/include/exiv2/datasets.hpp index 2d06e9e3ac..491a379d50 100644 --- a/include/exiv2/datasets.hpp +++ b/include/exiv2/datasets.hpp @@ -280,6 +280,7 @@ class EXIV2API IptcKey : public Key { [[nodiscard]] std::string groupName() const override; [[nodiscard]] std::string tagName() const override; [[nodiscard]] std::string tagLabel() const override; + [[nodiscard]] std::string tagDesc() const override; [[nodiscard]] uint16_t tag() const override; [[nodiscard]] UniquePtr clone() const; //! Return the name of the record diff --git a/include/exiv2/exif.hpp b/include/exiv2/exif.hpp index c052513a82..30e9c888ff 100644 --- a/include/exiv2/exif.hpp +++ b/include/exiv2/exif.hpp @@ -140,6 +140,7 @@ class EXIV2API Exifdatum : public Metadatum { [[nodiscard]] std::string groupName() const override; [[nodiscard]] std::string tagName() const override; [[nodiscard]] std::string tagLabel() const override; + [[nodiscard]] std::string tagDesc() const override; [[nodiscard]] uint16_t tag() const override; //! Return the IFD id as an integer. (Do not use, this is meant for library internal use.) [[nodiscard]] int ifdId() const; diff --git a/include/exiv2/iptc.hpp b/include/exiv2/iptc.hpp index 56dde0e566..64caba1017 100644 --- a/include/exiv2/iptc.hpp +++ b/include/exiv2/iptc.hpp @@ -113,6 +113,7 @@ class EXIV2API Iptcdatum : public Metadatum { */ [[nodiscard]] std::string tagName() const override; [[nodiscard]] std::string tagLabel() const override; + [[nodiscard]] std::string tagDesc() const override; //! Return the tag (aka dataset) number [[nodiscard]] uint16_t tag() const override; [[nodiscard]] TypeId typeId() const override; diff --git a/include/exiv2/metadatum.hpp b/include/exiv2/metadatum.hpp index d54b2ac309..982b641b1a 100644 --- a/include/exiv2/metadatum.hpp +++ b/include/exiv2/metadatum.hpp @@ -52,6 +52,8 @@ class EXIV2API Key { [[nodiscard]] virtual std::string tagName() const = 0; //! Return a label for the tag [[nodiscard]] virtual std::string tagLabel() const = 0; + //! Return a description for the tag + [[nodiscard]] virtual std::string tagDesc() const = 0; //! Return the tag number [[nodiscard]] virtual uint16_t tag() const = 0; /*! @@ -181,6 +183,8 @@ class EXIV2API Metadatum { [[nodiscard]] virtual std::string tagName() const = 0; //! Return a label for the tag [[nodiscard]] virtual std::string tagLabel() const = 0; + //! Return a description for the tag + [[nodiscard]] virtual std::string tagDesc() const = 0; //! Return the tag [[nodiscard]] virtual uint16_t tag() const = 0; //! Return the type id of the value diff --git a/include/exiv2/properties.hpp b/include/exiv2/properties.hpp index 36dc81790f..16132c2545 100644 --- a/include/exiv2/properties.hpp +++ b/include/exiv2/properties.hpp @@ -262,6 +262,7 @@ class EXIV2API XmpKey : public Key { [[nodiscard]] std::string groupName() const override; [[nodiscard]] std::string tagName() const override; [[nodiscard]] std::string tagLabel() const override; + [[nodiscard]] std::string tagDesc() const override; //! Properties don't have a tag number. Return 0. [[nodiscard]] uint16_t tag() const override; diff --git a/include/exiv2/tags.hpp b/include/exiv2/tags.hpp index d043cca41e..7e569c43e5 100644 --- a/include/exiv2/tags.hpp +++ b/include/exiv2/tags.hpp @@ -161,8 +161,7 @@ class EXIV2API ExifKey : public Key { [[nodiscard]] std::string tagName() const override; [[nodiscard]] uint16_t tag() const override; [[nodiscard]] std::string tagLabel() const override; - //! Return the tag description. - [[nodiscard]] std::string tagDesc() const; // Todo: should be in the base class + [[nodiscard]] std::string tagDesc() const; //! Return the default type id for this tag. [[nodiscard]] TypeId defaultTypeId() const; // Todo: should be in the base class diff --git a/include/exiv2/xmp_exiv2.hpp b/include/exiv2/xmp_exiv2.hpp index ec3d02c699..a012404873 100644 --- a/include/exiv2/xmp_exiv2.hpp +++ b/include/exiv2/xmp_exiv2.hpp @@ -108,6 +108,7 @@ class EXIV2API Xmpdatum : public Metadatum { //! Return the property name. [[nodiscard]] std::string tagName() const override; [[nodiscard]] std::string tagLabel() const override; + [[nodiscard]] std::string tagDesc() const override; //! Properties don't have a tag number. Return 0. [[nodiscard]] uint16_t tag() const override; [[nodiscard]] TypeId typeId() const override; diff --git a/src/datasets.cpp b/src/datasets.cpp index 02d64a511b..5cb5807ba3 100644 --- a/src/datasets.cpp +++ b/src/datasets.cpp @@ -531,6 +531,10 @@ std::string IptcKey::tagLabel() const { return IptcDataSets::dataSetTitle(tag_, record_); } +std::string IptcKey::tagDesc() const { + return IptcDataSets::dataSetDesc(tag_, record_); +} + uint16_t IptcKey::tag() const { return tag_; } diff --git a/src/exif.cpp b/src/exif.cpp index 8ca9f51765..c785bbed17 100644 --- a/src/exif.cpp +++ b/src/exif.cpp @@ -292,6 +292,10 @@ std::string Exifdatum::tagLabel() const { return key_ ? key_->tagLabel() : ""; } +std::string Exifdatum::tagDesc() const { + return key_ ? key_->tagDesc() : ""; +} + uint16_t Exifdatum::tag() const { return key_ ? key_->tag() : 0xffff; } diff --git a/src/iptc.cpp b/src/iptc.cpp index 39abd1f79b..0c70843fa8 100644 --- a/src/iptc.cpp +++ b/src/iptc.cpp @@ -101,6 +101,10 @@ std::string Iptcdatum::tagLabel() const { return key_ ? key_->tagLabel() : ""; } +std::string Iptcdatum::tagDesc() const { + return key_ ? key_->tagDesc() : ""; +} + uint16_t Iptcdatum::tag() const { return key_ ? key_->tag() : 0; } diff --git a/src/properties.cpp b/src/properties.cpp index ebe089b8b6..e341334268 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -5139,6 +5139,13 @@ std::string XmpKey::tagLabel() const { return pt; } +std::string XmpKey::tagDesc() const { + const char* pt = XmpProperties::propertyDesc(*this); + if (!pt) + return ""; + return pt; +} + uint16_t XmpKey::tag() const { return 0; } diff --git a/src/xmp.cpp b/src/xmp.cpp index cb4f422db6..ad7281b45b 100644 --- a/src/xmp.cpp +++ b/src/xmp.cpp @@ -326,6 +326,10 @@ std::string Xmpdatum::tagLabel() const { return p_->key_ ? p_->key_->tagLabel() : ""; } +std::string Xmpdatum::tagDesc() const { + return p_->key_ ? p_->key_->tagDesc() : ""; +} + uint16_t Xmpdatum::tag() const { return p_->key_ ? p_->key_->tag() : 0; } From ae98661da0592185b0c24832715a815e13eb60cf Mon Sep 17 00:00:00 2001 From: postscript-dev Date: Mon, 11 Jul 2022 22:04:18 +0100 Subject: [PATCH 2/5] Add `--Print d` to exiv2 app --- app/actions.cpp | 6 ++++ app/exiv2.cpp | 13 +++++--- app/exiv2app.hpp | 3 +- exiv2.md | 31 +++++++++---------- test/data/test_reference_files/exiv2-test.out | 9 ++++-- 5 files changed, 38 insertions(+), 24 deletions(-) diff --git a/app/actions.cpp b/app/actions.cpp index 1f5502ddba..0cb99382b6 100644 --- a/app/actions.cpp +++ b/app/actions.cpp @@ -498,6 +498,12 @@ bool Print::printMetadatum(const Exiv2::Metadatum& md, const Exiv2::Image* pImag first = false; std::cout << std::setw(30) << std::setfill(' ') << std::left << md.tagLabel(); } + if (Params::instance().printItems_ & Params::prDesc) { + if (!first) + std::cout << " "; + first = false; + std::cout << std::setw(30) << std::setfill(' ') << std::left << md.tagDesc(); + } if (Params::instance().printItems_ & Params::prType) { if (!first) std::cout << " "; diff --git a/app/exiv2.cpp b/app/exiv2.cpp index 65e86019bb..05b37e73bb 100644 --- a/app/exiv2.cpp +++ b/app/exiv2.cpp @@ -283,14 +283,16 @@ void Params::help(std::ostream& os) const { << _(" X : Extract \"raw\" XMP\n") << _(" -P flgs Print flags for fine control of tag lists ('print' action):\n") << _(" E : Exif tags\n") << _(" I : IPTC tags\n") << _(" X : XMP tags\n") - << _(" x : Tag number (Exif and IPTC only)\n") + << _(" x : Tag number for Exif or IPTC tags (in hexadecimal)\n") << _(" g : Group name (e.g. Exif.Photo.UserComment, Photo)\n") << _(" k : Key (e.g. Exif.Photo.UserComment)\n") << _(" l : Tag label (e.g. Exif.Photo.UserComment, 'User comment')\n") + << _(" d : Tag description\n") << _(" n : Tag name (e.g. Exif.Photo.UserComment, UserComment)\n") << _(" y : Type\n") - << _(" c : Number of components (count)\n") - << _(" s : Size in bytes (Ascii and Comment types include NULL)\n") - << _(" v : Plain data value, untranslated (vanilla)\n") + << _(" y : Type\n") << _(" c : Number of components (count)\n") + << _(" s : Size in bytes of vanilla value (may include NULL)\n") + << _(" v : Plain data value of untranslated (vanilla)\n") + << _(" V : Plain data value, data type and the word 'set'\n") << _(" t : Interpreted (translated) human readable values\n") << _(" h : Hex dump of the data\n") << _(" -d tgt1 Delete target(s) for the 'delete' action. Possible targets are:\n") @@ -720,6 +722,9 @@ int Params::evalPrintFlags(const std::string& optArg) { case 'V': printItems_ |= prSet | prKey | prType | prValue; break; + case 'd': + printItems_ |= prDesc; + break; default: std::cerr << progname() << ": " << _("Unrecognized print item") << " `" << i << "'\n"; rc = 1; diff --git a/app/exiv2app.hpp b/app/exiv2app.hpp index cae677704d..38a41e2b58 100644 --- a/app/exiv2app.hpp +++ b/app/exiv2app.hpp @@ -151,7 +151,8 @@ class Params : public Util::Getopt { prValue = 256, prTrans = 512, prHex = 1024, - prSet = 2048 + prSet = 2048, + prDesc = 4096 }; //! Enumerates common targets, bitmap diff --git a/exiv2.md b/exiv2.md index 6049327f4b..86dd7fd2a7 100644 --- a/exiv2.md +++ b/exiv2.md @@ -566,34 +566,33 @@ as well as data columns included in the print output. Valid flags are: | g | Group name (e.g., for Exif.Photo.UserComment, outputs Photo) | | k | Key (e.g., Exif.Photo.UserComment) | | l | Tag label (human-readable tagname, e.g., for Exif.Photo.UserComment, outputs 'User comment') | -| n | Tagname (e.g., for Exif.Photo.UserComment, outputs UserComment) | +| d | Tag description | +| n | Tag name (e.g., for Exif.Photo.UserComment, outputs UserComment) | | y | Type (for available types, see [Exif/IPTC/XMP types](#exiv2_types)) | | c | Number of components (for single entry types, the number of **sizeof('type')** in 'size'. For multi-entry types, the number of entries. See [Exif/IPTC/XMP types](#exiv2_types)) | | s | Size in bytes of vanilla output (see note in [Exif 'Comment' values](#exif_comment_values)). Some types include a *NULL* character in the size (see [Exif/IPTC/XMP types](#exiv2_types)) | | v | Plain data value (vanilla values, i.e., untranslated) | -| V | Plain data value, data type and the word 'set ' (see ['MODIFY' COMMANDS](#modify_cmds))| +| V | Plain data value, data type and the word 'set' (see ['MODIFY' COMMANDS](#modify_cmds))| | t | Interpreted (translated) human-readable data values (includes plain vanilla values) | | h | Hex dump of the data | +**--Print** *flgs* can be combined with [--grep str](#grep_str) or +[--key key](#key_key) to further filter the output. +