mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-04 03:55:28 -04:00
TIFFImageMetadata: ImageOrientation in mergeTree (#667)
TIFFImageMetadata: ImageOrientation in mergeTree (cherry picked from commit b67d687761328f3a395ae8ba561131bb15660efa)
This commit is contained in:
parent
46bfdd93d8
commit
a12a1f73b5
@ -1004,12 +1004,12 @@ public final class TIFFImageMetadata extends AbstractMetadata {
|
|||||||
// - If set, set res unit to pixels per cm as this better reflects values?
|
// - If set, set res unit to pixels per cm as this better reflects values?
|
||||||
// - Or, convert to DPI, if we already had values in DPI??
|
// - Or, convert to DPI, if we already had values in DPI??
|
||||||
// Also, if we have only aspect, set these values, and use unknown as unit?
|
// Also, if we have only aspect, set these values, and use unknown as unit?
|
||||||
// TODO: ImageOrientation => Orientation
|
|
||||||
NodeList children = dimensionNode.getChildNodes();
|
NodeList children = dimensionNode.getChildNodes();
|
||||||
|
|
||||||
Float aspect = null;
|
Float aspect = null;
|
||||||
Float xRes = null;
|
Float xRes = null;
|
||||||
Float yRes = null;
|
Float yRes = null;
|
||||||
|
Integer orientation = null;
|
||||||
|
|
||||||
for (int i = 0; i < children.getLength(); i++) {
|
for (int i = 0; i < children.getLength(); i++) {
|
||||||
Node child = children.item(i);
|
Node child = children.item(i);
|
||||||
@ -1024,6 +1024,9 @@ public final class TIFFImageMetadata extends AbstractMetadata {
|
|||||||
else if ("VerticalPixelSize".equals(nodeName)) {
|
else if ("VerticalPixelSize".equals(nodeName)) {
|
||||||
yRes = Float.parseFloat(getAttribute(child, "value"));
|
yRes = Float.parseFloat(getAttribute(child, "value"));
|
||||||
}
|
}
|
||||||
|
else if ("ImageOrientation".equals(nodeName)) {
|
||||||
|
orientation = toTIFFOrientation(getAttribute(child, "value"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have one size compute the other
|
// If we have one size compute the other
|
||||||
@ -1070,6 +1073,11 @@ public final class TIFFImageMetadata extends AbstractMetadata {
|
|||||||
new TIFFEntry(TIFF.TAG_RESOLUTION_UNIT, TIFF.TYPE_SHORT, TIFFBaseline.RESOLUTION_UNIT_NONE));
|
new TIFFEntry(TIFF.TAG_RESOLUTION_UNIT, TIFF.TYPE_SHORT, TIFFBaseline.RESOLUTION_UNIT_NONE));
|
||||||
}
|
}
|
||||||
// Else give up...
|
// Else give up...
|
||||||
|
|
||||||
|
if (orientation != null) {
|
||||||
|
entries.put(TIFF.TAG_ORIENTATION,
|
||||||
|
new TIFFEntry(TIFF.TAG_ORIENTATION, TIFF.TYPE_SHORT, orientation.shortValue()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeFromStandardDocumentNode(final Node documentNode, final Map<Integer, Entry> entries) {
|
private void mergeFromStandardDocumentNode(final Node documentNode, final Map<Integer, Entry> entries) {
|
||||||
@ -1195,6 +1203,34 @@ public final class TIFFImageMetadata extends AbstractMetadata {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Integer toTIFFOrientation(String imageOrientation) {
|
||||||
|
if (imageOrientation == null) {
|
||||||
|
// malformed, empty or not readable value
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
switch (imageOrientation.toLowerCase()) {
|
||||||
|
case "normal":
|
||||||
|
return TIFFBaseline.ORIENTATION_TOPLEFT;
|
||||||
|
case "fliph":
|
||||||
|
return TIFFExtension.ORIENTATION_TOPRIGHT;
|
||||||
|
case "rotate180":
|
||||||
|
return TIFFExtension.ORIENTATION_BOTRIGHT;
|
||||||
|
case "flipv":
|
||||||
|
return TIFFExtension.ORIENTATION_BOTLEFT;
|
||||||
|
case "fliphrotate90":
|
||||||
|
return TIFFExtension.ORIENTATION_LEFTTOP;
|
||||||
|
case "rotate270":
|
||||||
|
return TIFFExtension.ORIENTATION_RIGHTTOP;
|
||||||
|
case "flipvrotate90":
|
||||||
|
return TIFFExtension.ORIENTATION_RIGHTBOT;
|
||||||
|
case "rotate90":
|
||||||
|
return TIFFExtension.ORIENTATION_LEFTBOT;
|
||||||
|
default:
|
||||||
|
// malformed, invalid value
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private short getTIFFType(final Node node) throws IIOInvalidTreeException {
|
private short getTIFFType(final Node node) throws IIOInvalidTreeException {
|
||||||
Node containerNode = node.getFirstChild();
|
Node containerNode = node.getFirstChild();
|
||||||
if (containerNode == null) {
|
if (containerNode == null) {
|
||||||
|
@ -324,6 +324,10 @@ public class TIFFImageMetadataTest {
|
|||||||
dimensionNode.appendChild(verticalPixelSize);
|
dimensionNode.appendChild(verticalPixelSize);
|
||||||
verticalPixelSize.setAttribute("value", String.valueOf(300 / 25.4));
|
verticalPixelSize.setAttribute("value", String.valueOf(300 / 25.4));
|
||||||
|
|
||||||
|
IIOMetadataNode orientation = new IIOMetadataNode("ImageOrientation");
|
||||||
|
dimensionNode.appendChild(orientation);
|
||||||
|
orientation.setAttribute("value", "FlipV");
|
||||||
|
|
||||||
metadata.mergeTree(standardFormat, newTree);
|
metadata.mergeTree(standardFormat, newTree);
|
||||||
|
|
||||||
Directory ifd = metadata.getIFD();
|
Directory ifd = metadata.getIFD();
|
||||||
@ -332,6 +336,8 @@ public class TIFFImageMetadataTest {
|
|||||||
assertEquals(new Rational(300), ifd.getEntryById(TIFF.TAG_X_RESOLUTION).getValue());
|
assertEquals(new Rational(300), ifd.getEntryById(TIFF.TAG_X_RESOLUTION).getValue());
|
||||||
assertNotNull(ifd.getEntryById(TIFF.TAG_Y_RESOLUTION));
|
assertNotNull(ifd.getEntryById(TIFF.TAG_Y_RESOLUTION));
|
||||||
assertEquals(new Rational(300), ifd.getEntryById(TIFF.TAG_Y_RESOLUTION).getValue());
|
assertEquals(new Rational(300), ifd.getEntryById(TIFF.TAG_Y_RESOLUTION).getValue());
|
||||||
|
assertNotNull(ifd.getEntryById(TIFF.TAG_ORIENTATION));
|
||||||
|
assertEquals(TIFFExtension.ORIENTATION_BOTLEFT, ((Number) ifd.getEntryById(TIFF.TAG_ORIENTATION).getValue()).intValue());
|
||||||
|
|
||||||
// Should keep DPI as unit
|
// Should keep DPI as unit
|
||||||
assertNotNull(ifd.getEntryById(TIFF.TAG_RESOLUTION_UNIT));
|
assertNotNull(ifd.getEntryById(TIFF.TAG_RESOLUTION_UNIT));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user