drewnoakes / metadata-extractor

Extracts Exif, IPTC, XMP, ICC and other metadata from image, video and audio files
Apache License 2.0
2.57k stars 481 forks source link

Rational numbers can show sign in denominator rather than numerator (e.g. "1/-2" vs "-1/2") #638

Open ColibriP2 opened 10 months ago

ColibriP2 commented 10 months ago

I noticed in JAlbum which uses Metadata-extractor that Exposure Bias Value is displayed 1/-3 EV instead of -1/3 EV. The -2/3 value is well handled. I have attached a jpeg showing the problem. PAPO8138

jefftucker1952 commented 10 months ago

I can add that Windows File Explorer Properties displays it as -0.3 step, as expected. If I take ColibriP2's image and "change" the value in something like EXIF Pilot, just re-entering the same value, metadata-extractor no longer chokes on it, and shows -0.3 EV. Not sure what's buried in the original that's throwing it for a loop.

drewnoakes commented 10 months ago

Exif stores rational numbers as two signed integers. In your original image, the denominator must be negative.

We could have the Rational toString method normalise the signs.

drewnoakes commented 10 months ago

Also discussed in https://jalbum.net/forum/thread.jspa?messageID=364782&tstart=0

drewnoakes commented 10 months ago

Note that in general, a nicer presentation of Rational values can be obtained via Rational.toSimpleString. That's not the default, however, as it can lose some information relative to toString, and it has a longer running time (https://en.wikipedia.org/wiki/Euclidean_algorithm).

In the original issue, JAlbum could sniff for instances of Rational values and call toSimpleString, which will handle the above case and others (such as converting 0/100 to 0, 7/21 to 1/3, and 1/5 to 0.2 etc.).