Skip to content

Commit

Permalink
Better Apple makernote support
Browse files Browse the repository at this point in the history
  • Loading branch information
drewnoakes committed May 12, 2020
1 parent 05f850d commit 75c5f5e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Source/com/drew/lang/Rational.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ public Rational getReciprocal()
return new Rational(this._denominator, this._numerator);
}

/**
* Returns the absolute value of this object as a new Rational.
*
* @return the absolute value in a new object
*/
public Rational getAbsolute()
{
return new Rational(Math.abs(this._numerator), Math.abs(this._denominator));
}

/** Checks if this {@link Rational} number is an Integer, either positive or negative. */
public boolean isInteger()
{
Expand All @@ -181,6 +191,12 @@ public boolean isZero()
return _numerator == 0 || _denominator == 0;
}

/** True if the value is non-zero and numerator and denominator are either both positive or both negative. */
public boolean isPositive()
{
return !isZero() && (_numerator > 0 == _denominator > 0);
}

/**
* Returns a string representation of the object of form <code>numerator/denominator</code>.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
package com.drew.metadata.exif.makernotes;

import com.drew.lang.Rational;
import com.drew.lang.annotations.NotNull;
import com.drew.lang.annotations.Nullable;
import com.drew.metadata.TagDescriptor;
Expand All @@ -46,6 +47,8 @@ public String getDescription(int tagType)
switch (tagType) {
case AppleMakernoteDirectory.TAG_HDR_IMAGE_TYPE:
return getHdrImageTypeDescription();
case AppleMakernoteDirectory.TAG_ACCELERATION_VECTOR:
return getAccelerationVectorDescription();
default:
return super.getDescription(tagType);
}
Expand All @@ -56,4 +59,15 @@ public String getHdrImageTypeDescription()
{
return getIndexedDescription(AppleMakernoteDirectory.TAG_HDR_IMAGE_TYPE, 3, "HDR Image", "Original Image");
}

@Nullable
public String getAccelerationVectorDescription()
{
Rational[] values = _directory.getRationalArray(AppleMakernoteDirectory.TAG_ACCELERATION_VECTOR);
if (values == null || values.length != 3)
return null;
return String.format("%.2fg %s, ", values[0].getAbsolute().doubleValue(), values[0].isPositive() ? "left" : "right") +
String.format("%.2fg %s, ", values[1].getAbsolute().doubleValue(), values[1].isPositive() ? "down" : "up") +
String.format("%.2fg %s", values[2].getAbsolute().doubleValue(), values[2].isPositive() ? "forward" : "backward");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,23 @@
public class AppleMakernoteDirectory extends Directory
{
public static final int TAG_RUN_TIME = 0x0003;
public static final int TAG_ACCELERATION_VECTOR = 0x0008;
public static final int TAG_HDR_IMAGE_TYPE = 0x000a;
public static final int TAG_BURST_UUID = 0x000b;
public static final int TAG_CONTENT_IDENTIFIER = 0x0011;
public static final int TAG_IMAGE_UNIQUE_ID = 0x0015;

@NotNull
private static final HashMap<Integer, String> _tagNameMap = new HashMap<Integer, String>();

static
{
_tagNameMap.put(TAG_RUN_TIME, "Run Time");
_tagNameMap.put(TAG_ACCELERATION_VECTOR, "Acceleration Vector");
_tagNameMap.put(TAG_HDR_IMAGE_TYPE, "HDR Image Type");
_tagNameMap.put(TAG_BURST_UUID, "Burst UUID");
_tagNameMap.put(TAG_CONTENT_IDENTIFIER, "Content Identifier");
_tagNameMap.put(TAG_IMAGE_UNIQUE_ID, "Image Unique ID");
}

public AppleMakernoteDirectory()
Expand Down

0 comments on commit 75c5f5e

Please sign in to comment.