#628 TIFF metadata fix, now always outputs denominator for rationals.

+ Bonus: Added JAI TIFF interop module with test and other minor fixes.
This commit is contained in:
Harald Kuhr
2021-09-17 16:26:03 +02:00
parent 62ba73a30e
commit 11227a68a0
6 changed files with 181 additions and 16 deletions

View File

@@ -100,7 +100,7 @@ public final class TIFFImageMetadata extends AbstractMetadata {
* {@link #setFromTree(String, Node)}
* or {@link #mergeTree(String, Node)} methods.
*/
public TIFFImageMetadata(final Collection<Entry> entries) {
public TIFFImageMetadata(final Collection<? extends Entry> entries) {
this(new IFD(entries));
}
@@ -196,7 +196,12 @@ public final class TIFFImageMetadata extends AbstractMetadata {
elementNode.setAttribute("value", String.valueOf((Short) value & 0xFFFF));
}
else if (unsigned && value instanceof Integer) {
elementNode.setAttribute("value", String.valueOf((Integer) value & 0xFFFFFFFFl));
elementNode.setAttribute("value", String.valueOf((Integer) value & 0xFFFFFFFFL));
}
else if (value instanceof Rational) {
// For compatibility with JAI format, we need denominator
String rational = String.valueOf(value);
elementNode.setAttribute("value", rational.indexOf('/') < 0 && !"NaN".equals(rational) ? rational + "/1" : rational);
}
else {
elementNode.setAttribute("value", String.valueOf(value));

View File

@@ -238,8 +238,8 @@ public class TIFFImageMetadataTest {
assertSingleNodeWithValue(entries, TIFF.TAG_ROWS_PER_STRIP, TIFF.TYPE_LONG, "5");
assertSingleNodeWithValue(entries, TIFF.TAG_STRIP_BYTE_COUNTS, TIFF.TYPE_LONG, stripByteCounts);
assertSingleNodeWithValue(entries, TIFF.TAG_PLANAR_CONFIGURATION, TIFF.TYPE_SHORT, "1");
assertSingleNodeWithValue(entries, TIFF.TAG_X_POSITION, TIFF.TYPE_RATIONAL, "0");
assertSingleNodeWithValue(entries, TIFF.TAG_Y_POSITION, TIFF.TYPE_RATIONAL, "0");
assertSingleNodeWithValue(entries, TIFF.TAG_X_POSITION, TIFF.TYPE_RATIONAL, "0/1");
assertSingleNodeWithValue(entries, TIFF.TAG_Y_POSITION, TIFF.TYPE_RATIONAL, "0/1");
assertSingleNodeWithValue(entries, 32995, TIFF.TYPE_SHORT, "0"); // Matteing tag, obsoleted by ExtraSamples tag in TIFF 6.0
}
@@ -299,7 +299,7 @@ public class TIFFImageMetadataTest {
// Validate there's one and only one resolution unit, x res and y res
// Validate resolution unit == 1, x res & y res
assertSingleNodeWithValue(fields, TIFF.TAG_RESOLUTION_UNIT, TIFF.TYPE_SHORT, String.valueOf(TIFFBaseline.RESOLUTION_UNIT_DPI));
assertSingleNodeWithValue(fields, TIFF.TAG_X_RESOLUTION, TIFF.TYPE_RATIONAL, "300");
assertSingleNodeWithValue(fields, TIFF.TAG_X_RESOLUTION, TIFF.TYPE_RATIONAL, "300/1");
assertSingleNodeWithValue(fields, TIFF.TAG_Y_RESOLUTION, TIFF.TYPE_RATIONAL, "30001/100");
}