Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Which Image structure does Image.setComment() set? #1445

Closed
LeoHsiao1 opened this issue Jan 3, 2021 · 6 comments
Closed

Which Image structure does Image.setComment() set? #1445

LeoHsiao1 opened this issue Jan 3, 2021 · 6 comments
Labels
documentation support Anything related to a user needing help with exiv2

Comments

@LeoHsiao1
Copy link
Contributor

LeoHsiao1 commented Jan 3, 2021

Happy New Year!

Exiv2 provides this method:

virtual void setComment(const std::string& comment);

But which Image structure does Image.setComment() set?

According to this document, JPEG images contain the Comment segment:

The metadata in JPEG file is stored in APPn (0xFF, 0xEn) segment and the comment is stored in COM segment (0xFF, 0xFE).

Images in other formats don't have the Comment segment. So are they not suitable for Image.setComment()?
I tried to modify an PNG image with Image.setComment(), but the Comment text was saved in a block called iTXt.

By the way, there's no introduction that Exiv2 can modify image comments, on the homepage of Exiv2, or in @clanmills 's book.
I used to think that Exiv2 could not modify the image comments.

@LeoHsiao1 LeoHsiao1 added support Anything related to a user needing help with exiv2 documentation labels Jan 3, 2021
@clanmills
Copy link
Collaborator

@LeoHsiao1

Happy New Year.

Image.setComment() sets the COM block in a JPEG.

(base) rmillsmm-local:~ rmills$ cp ~/Stonehenge.jpg S.jpg ; exiv2 --comment "Happy New Year" ~/S.jpg ; exiv2 -pS ~/S.jpg 
STRUCTURE OF JPEG FILE: /Users/rmills/S.jpg
 address | marker       |  length | data
       0 | 0xffd8 SOI  
       2 | 0xffe1 APP1  |   15272 | Exif..II*......................
   15276 | 0xffe1 APP1  |    2786 | http://ns.adobe.com/xap/1.0/.<?x
   18064 | 0xffed APP13 |      96 | Photoshop 3.0.8BIM.......'.....
   18162 | 0xffe2 APP2  |    4094 | MPF.II*...............0100.....
   22258 | 0xffdb DQT   |     132 
   22392 | 0xfffe COM   |      17 | Happy New Year
   22411 | 0xffc0 SOF0  |      17 
   22430 | 0xffc4 DHT   |     418 
   22850 | 0xffda SOS  
(base) rmillsmm-local:~ rmills$ 

For a PNG file, the comment is an iTXt chunk with Title==Description

508 rmills@rmillsmm-local:~/gnu/exiv2/team/book $ exiv2 --comment "Happy New Year" ~/exif.png 
509 rmills@rmillsmm-local:~/gnu/exiv2/team/book $ exiv2 -pS ~/exif.png 
STRUCTURE OF PNG FILE: /Users/rmills/exif.png
 address | chunk |  length | data                           | checksum
       8 | IHDR  |      13 | ............                   | 0xc2e5cf34
      33 | iTXt  |      38 | Description.....x..H,(.T.K-W.L | 0x5cc5f642
      83 | zTXt  |     139 | Raw profile type exif..x.]O[.. | 0xf519b9ff
     234 | iTXt  |    2497 | XML:com.adobe.xmp.....<?xpacke | 0x96bc54b4
    2743 | sRGB  |       1 |                                | 0xaece1ce9
    2756 | pHYs  |       9 | .........                      | 0x6ed0753e
    2777 | IDAT  |   16384 | x.....\U......;.H.....A.t..... | 0x1c1292d9
   19173 | IDAT  |   16384 | ...-q.....@....@....@....@.... | 0x040f899c
   35569 | IDAT  |   16384 | ..k.H...(.|..R....j.Z...i..... | 0x8fc977f0
   51965 | IDAT  |   16384 | ...2H......z3............./.4` | 0x6818e0e3
   68361 | IDAT  |   16384 | ..~p..B.#x.L.G'.o!....<$.9M8.. | 0xe19c59ad
   84757 | IDAT  |   16384 | .c..}.._##.......%_...!.b...N. | 0x7ec3bdec
  101153 | IDAT  |   16384 | ....~..s:}`...t.,..#'U}..u.7.. | 0x44de4afb
  117549 | IDAT  |   16384 | .PWe'......i[>\..V.j.`.....f.. | 0xacedd039
  133945 | IDAT  |   16384 | ..>.<........O..E..5....?..N`. | 0x94f68569
  150341 | IDAT  |   11348 | @........:................?.>. | 0x8dc2aec9
  161701 | IEND  |       0 |                                | 0xae426082
510 rmills@rmillsmm-local:~/gnu/exiv2/team/book $ 

This is documented in the book AND the exiv2 man page.

I think it's rather regrettable that Exiv2 offers this feature as it cannot be applied to every image format. It's not Exif, IPTC, or XMP metadata. I suspect it was added early in the life of Exiv2 and has remained ever since.

@LeoHsiao1
Copy link
Contributor Author

Thank you for your help.
I guess Comment is rarely used. I used to know only Exif.Photo.UserComment.
Wish you all the best in the New Year!

@clanmills
Copy link
Collaborator

clanmills commented Jan 4, 2021

Thanks for closing this, @LeoHsiao1

Exif.Photo.UserComment is different from JPEG/COM. The key Exif.Photo.UserComment means:

Exif = It's defined in the Exif metadata
Photo = It's in the Exif 2.x spec
UserComment = It's tag 0x9286

$ grep UserComment tvisitor.cpp 
    exifDict  [ 0x9286 ] = "UserComment";
$ taglist ALL | csv - | grep Photo.UserComment
[Photo.UserComment]	[37510]	[0x9286]	[Photo]	[Exif.Photo.UserComment]	[Comment]	[A tag for Exif users to write keywords or comments on the image besides those in <ImageDescription>, and without the character code limitations of the <ImageDescription> tag.]	
$ 

There are different Groups in the Exif Metadata such as Image (defined in TIFF/EP spec), Photo (defined in Exif 2.X spec), GPSInfo (also defined in Exif 2.X spec) and Nikon, or Canon etc (decoded from the MakerNote).

Here's a drawing from the book that I hope clarifies the design of the file that comes out of the camera. Exiv2 (and tvisitor.cpp) provide the code to successfully navigate the file.

exif

@clanmills
Copy link
Collaborator

@LeoHsiao1 Other thoughts about this.

The drawing above illustrates how the data is stored in a TIFF (the .NEF Nikon Raw File is a TIFF). All the different formats (JPEG, PNG, ISOBMFF etc) have slightly different schemes to store Exif, IPTC, XMP and ICC data. And some file formats can store data that is not part of Exif, IPTC, XMP and ICC. JPEG/COM is a good example. It's a relic from the early 1990s and unique to JPEG.

I can't explain how/why all those different formats came about. For sure they are a software challenge to say the least. Adobe have tried to provide leadership with both the XMP and DNG standards. The manufacturers seem to prefer chaos. Canon have had 3 totally different "Raw" formats in less that 20 years. I know of no manufacturer who has documented their MakerNote.

You asked me once if there will be new metadata standards in the future. I hope not. I wish the manufacturers would agree and stick to a few standards.

@LeoHsiao1
Copy link
Contributor Author

Thank you for your detailed explanation.
Without your book, some of the rarely used metadata might be forgotten.

@clanmills
Copy link
Collaborator

I have tried to put everything I know about both Metadata and Exiv2 into the book. I hope Exiv2 will survive. Exiv2 is 100% documented and 100% free of defects. It's in good shape with one exception which is that nobody seems willing to work on Exiv2 maintenance. The Community does not have a viable C++ replacement for Exiv2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation support Anything related to a user needing help with exiv2
Projects
None yet
Development

No branches or pull requests

2 participants