Skip to content

Commit dc4ae73

Browse files
Add tag description option to exiv2 app (#2279)
* Add `tagDesc()` to (Exif|Xmp|Iptc) Datums and Keys * Add `--Print d` option to exiv2 app * Add testing for all exiv2 application `--Print` options * Update manpage
1 parent 0558662 commit dc4ae73

File tree

18 files changed

+92
-26
lines changed

18 files changed

+92
-26
lines changed

app/actions.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,12 @@ bool Print::printMetadatum(const Exiv2::Metadatum& md, const Exiv2::Image* pImag
498498
first = false;
499499
std::cout << std::setw(30) << std::setfill(' ') << std::left << md.tagLabel();
500500
}
501+
if (Params::instance().printItems_ & Params::prDesc) {
502+
if (!first)
503+
std::cout << " ";
504+
first = false;
505+
std::cout << std::setw(30) << std::setfill(' ') << std::left << md.tagDesc();
506+
}
501507
if (Params::instance().printItems_ & Params::prType) {
502508
if (!first)
503509
std::cout << " ";

app/exiv2.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,16 @@ void Params::help(std::ostream& os) const {
283283
<< _(" X : Extract \"raw\" XMP\n")
284284
<< _(" -P flgs Print flags for fine control of tag lists ('print' action):\n")
285285
<< _(" E : Exif tags\n") << _(" I : IPTC tags\n") << _(" X : XMP tags\n")
286-
<< _(" x : Tag number (Exif and IPTC only)\n")
286+
<< _(" x : Tag number for Exif or IPTC tags (in hexadecimal)\n")
287287
<< _(" g : Group name (e.g. Exif.Photo.UserComment, Photo)\n")
288288
<< _(" k : Key (e.g. Exif.Photo.UserComment)\n")
289289
<< _(" l : Tag label (e.g. Exif.Photo.UserComment, 'User comment')\n")
290+
<< _(" d : Tag description\n")
290291
<< _(" n : Tag name (e.g. Exif.Photo.UserComment, UserComment)\n") << _(" y : Type\n")
291-
<< _(" c : Number of components (count)\n")
292-
<< _(" s : Size in bytes (Ascii and Comment types include NULL)\n")
293-
<< _(" v : Plain data value, untranslated (vanilla)\n")
292+
<< _(" y : Type\n") << _(" c : Number of components (count)\n")
293+
<< _(" s : Size in bytes of vanilla value (may include NULL)\n")
294+
<< _(" v : Plain data value of untranslated (vanilla)\n")
295+
<< _(" V : Plain data value, data type and the word 'set'\n")
294296
<< _(" t : Interpreted (translated) human readable values\n")
295297
<< _(" h : Hex dump of the data\n")
296298
<< _(" -d tgt1 Delete target(s) for the 'delete' action. Possible targets are:\n")
@@ -720,6 +722,9 @@ int Params::evalPrintFlags(const std::string& optArg) {
720722
case 'V':
721723
printItems_ |= prSet | prKey | prType | prValue;
722724
break;
725+
case 'd':
726+
printItems_ |= prDesc;
727+
break;
723728
default:
724729
std::cerr << progname() << ": " << _("Unrecognized print item") << " `" << i << "'\n";
725730
rc = 1;

app/exiv2app.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ class Params : public Util::Getopt {
151151
prValue = 256,
152152
prTrans = 512,
153153
prHex = 1024,
154-
prSet = 2048
154+
prSet = 2048,
155+
prDesc = 4096
155156
};
156157

157158
//! Enumerates common targets, bitmap

exiv2.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -566,34 +566,33 @@ as well as data columns included in the print output. Valid flags are:
566566
| g | Group name (e.g., for Exif.Photo.UserComment, outputs Photo) |
567567
| k | Key (e.g., Exif.Photo.UserComment) |
568568
| l | Tag label (human-readable tagname, e.g., for Exif.Photo.UserComment, outputs 'User comment') |
569-
| n | Tagname (e.g., for Exif.Photo.UserComment, outputs UserComment) |
569+
| d | Tag description |
570+
| n | Tag name (e.g., for Exif.Photo.UserComment, outputs UserComment) |
570571
| y | Type (for available types, see [Exif/IPTC/XMP types](#exiv2_types)) |
571572
| 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)) |
572573
| 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)) |
573574
| v | Plain data value (vanilla values, i.e., untranslated) |
574-
| V | Plain data value, data type and the word 'set ' (see ['MODIFY' COMMANDS](#modify_cmds))|
575+
| V | Plain data value, data type and the word 'set' (see ['MODIFY' COMMANDS](#modify_cmds))|
575576
| t | Interpreted (translated) human-readable data values (includes plain vanilla values) |
576577
| h | Hex dump of the data |
577578

579+
**--Print** *flgs* can be combined with [--grep str](#grep_str) or
580+
[--key key](#key_key) to further filter the output.
581+
578582
<div id="Print_flgs_order">
579583

580-
The order of the values in *flgs* is not respected. For example, the order
581-
of the columns, using some tags from *Stonehenge.jpg*, is as follows:
584+
The order of the values in *flgs* is not respected and is output as follows:
582585

583-
```
584-
$ curl --silent -O https://www.exiv2.org/Stonehenge.jpg
585-
$ exiv2 --Print xgknlycst Stonehenge.jpg
586-
```
586+
| Tag number<br>(x) | Plain 'set'<br>(V) | Group<br>(g) | Key<br>(k) | Tagname<br>(n) | Tagname label<br>(l) |Description<br>(d) | Type<br>(y) | Comp<br>(c) | Size<br>(s) | Value<br>(v) | Translated<br>(t) |
587+
|:------ |:---- |:------ |:------ |:------ |:------ |:------ |:------ |:------ |:------ |:--- |:------ |
587588

588-
| Tag number<br>(x) | Plain 'set'<br>(V) | Group<br>(g) | Key<br>(k) | Tagname<br>(n) | Tagname label<br>(l) | Type<br>(y) | Comp<br>(c) | Size<br>(s) | Value<br>(E, I, X, v, t) | Translated<br>(t) |
589-
|:------ |:---- |:------ |:------ |:------ |:------ |:------ |:------ |:------ |:------ |:------ |
590-
| 0x0110 | set | Image | Exif.Image.Model | Model | Model | Ascii | 12 | 12 | NIKON D5300 | NIKON D5300 |
591-
| 0x0006 | set | NikonIi | Exif.NikonIi.ISO2 | ISO2 | ISO 2 | Byte | 1 | 1 | 72 | 200 |
592-
| 0x0000 | set | xmp | Xmp.xmp.Rating | Rating | Rating | XmpText | 1 | 1 | 0 | 0 |
593-
| 0x0000 | set | dc | Xmp.dc.Family | Family | Family | XmpBag | 1 | 5 | Robin | Robin |
589+
For example,
594590

595-
**--Print** *flgs* can be combined with [--grep str](#grep_str) or
596-
[--key key](#key_key) to further filter the output.
591+
```bash
592+
$ curl --silent -O https://www.exiv2.org/Stonehenge.jpg
593+
$ exiv2 --Print xVgknldycsvt -K Exif.Nikon3.Quality Stonehenge.jpg
594+
0x0004 set Nikon3 Exif.Nikon3.Quality Quality Quality Image quality setting Ascii 8 8 NORMAL NORMAL
595+
```
597596

598597
<div id="delete_tgt1">
599598

include/exiv2/datasets.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ class EXIV2API IptcKey : public Key {
280280
[[nodiscard]] std::string groupName() const override;
281281
[[nodiscard]] std::string tagName() const override;
282282
[[nodiscard]] std::string tagLabel() const override;
283+
[[nodiscard]] std::string tagDesc() const override;
283284
[[nodiscard]] uint16_t tag() const override;
284285
[[nodiscard]] UniquePtr clone() const;
285286
//! Return the name of the record

include/exiv2/exif.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class EXIV2API Exifdatum : public Metadatum {
140140
[[nodiscard]] std::string groupName() const override;
141141
[[nodiscard]] std::string tagName() const override;
142142
[[nodiscard]] std::string tagLabel() const override;
143+
[[nodiscard]] std::string tagDesc() const override;
143144
[[nodiscard]] uint16_t tag() const override;
144145
//! Return the IFD id as an integer. (Do not use, this is meant for library internal use.)
145146
[[nodiscard]] IfdId ifdId() const;

include/exiv2/iptc.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class EXIV2API Iptcdatum : public Metadatum {
113113
*/
114114
[[nodiscard]] std::string tagName() const override;
115115
[[nodiscard]] std::string tagLabel() const override;
116+
[[nodiscard]] std::string tagDesc() const override;
116117
//! Return the tag (aka dataset) number
117118
[[nodiscard]] uint16_t tag() const override;
118119
[[nodiscard]] TypeId typeId() const override;

include/exiv2/metadatum.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class EXIV2API Key {
5252
[[nodiscard]] virtual std::string tagName() const = 0;
5353
//! Return a label for the tag
5454
[[nodiscard]] virtual std::string tagLabel() const = 0;
55+
//! Return a description for the tag
56+
[[nodiscard]] virtual std::string tagDesc() const = 0;
5557
//! Return the tag number
5658
[[nodiscard]] virtual uint16_t tag() const = 0;
5759
/*!
@@ -181,6 +183,8 @@ class EXIV2API Metadatum {
181183
[[nodiscard]] virtual std::string tagName() const = 0;
182184
//! Return a label for the tag
183185
[[nodiscard]] virtual std::string tagLabel() const = 0;
186+
//! Return a description for the tag
187+
[[nodiscard]] virtual std::string tagDesc() const = 0;
184188
//! Return the tag
185189
[[nodiscard]] virtual uint16_t tag() const = 0;
186190
//! Return the type id of the value

include/exiv2/properties.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class EXIV2API XmpKey : public Key {
263263
[[nodiscard]] std::string groupName() const override;
264264
[[nodiscard]] std::string tagName() const override;
265265
[[nodiscard]] std::string tagLabel() const override;
266+
[[nodiscard]] std::string tagDesc() const override;
266267
//! Properties don't have a tag number. Return 0.
267268
[[nodiscard]] uint16_t tag() const override;
268269

include/exiv2/tags.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,7 @@ class EXIV2API ExifKey : public Key {
339339
[[nodiscard]] std::string tagName() const override;
340340
[[nodiscard]] uint16_t tag() const override;
341341
[[nodiscard]] std::string tagLabel() const override;
342-
//! Return the tag description.
343-
[[nodiscard]] std::string tagDesc() const; // Todo: should be in the base class
342+
[[nodiscard]] std::string tagDesc() const override;
344343
//! Return the default type id for this tag.
345344
[[nodiscard]] TypeId defaultTypeId() const; // Todo: should be in the base class
346345

0 commit comments

Comments
 (0)