X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fjpeg%2FExifGateway.java;h=c11ba2e69ec7c3f1d7ead5bd7a549ec3ea6ce318;hb=8c8868ae29b3252f02e094c02307384cf61ba667;hp=5420ea6762fe9d0c534e2a7aa72a8f7dc4c43561;hpb=c0387c124840c9407e040600fda88f3c3e8f6aa6;p=GpsPrune.git
diff --git a/tim/prune/jpeg/ExifGateway.java b/tim/prune/jpeg/ExifGateway.java
index 5420ea6..c11ba2e 100644
--- a/tim/prune/jpeg/ExifGateway.java
+++ b/tim/prune/jpeg/ExifGateway.java
@@ -1,9 +1,7 @@
package tim.prune.jpeg;
import java.io.File;
-
import javax.swing.JOptionPane;
-
import tim.prune.I18nManager;
/**
@@ -12,19 +10,11 @@ import tim.prune.I18nManager;
* to the external libmetadata-extractor-java library
* instead of the included modified routines.
*
- * To use the internal routines, set the USE_INTERNAL_LIBRARY flag to true
- * and include the internal classes in the compiled jar.
- * To use the external library, set the USE_INTERNAL_LIBRARY flag to false
- * and do not export the internal classes.
+ * Switching between internal and external libraries is
+ * handled by the ExifLibrarySwitch
*/
public abstract class ExifGateway
{
- // *********************************************************
- // TODO: Check this exif library flag before releasing!
- /** Flag to specify internal or external library */
- private static final boolean USE_INTERNAL_LIBRARY = true;
- // *********************************************************
-
/** Library object to call */
private static ExifLibrary _exifLibrary = null;
/** Flag to set whether failure warning has already been shown */
@@ -33,7 +23,7 @@ public abstract class ExifGateway
/** Static block to initialise library */
static
{
- String libraryClass = USE_INTERNAL_LIBRARY?"InternalExifLibrary":"ExternalExifLibrary";
+ String libraryClass = ExifLibrarySwitch.USE_INTERNAL_LIBRARY?"InternalExifLibrary":"ExternalExifLibrary";
try
{
_exifLibrary = (ExifLibrary) Class.forName("tim.prune.jpeg." + libraryClass).newInstance();
@@ -57,7 +47,10 @@ public abstract class ExifGateway
return data;
}
}
- catch (LinkageError nolib) {}
+ catch (LinkageError nolib) {
+ System.err.println("Link: " + nolib.getMessage());
+ nolib.printStackTrace();
+ }
// Not successful - warn if necessary
if (!_exifFailWarned)
{
@@ -73,8 +66,43 @@ public abstract class ExifGateway
*/
public static String getDescriptionKey()
{
- String key = USE_INTERNAL_LIBRARY?"internal":"external";
+ String key = ExifLibrarySwitch.USE_INTERNAL_LIBRARY?"internal":"external";
if (_exifLibrary == null || !_exifLibrary.looksOK()) {key = key + ".failed";}
return key;
}
+
+
+ /**
+ * @param inNumerator numerator from Rational
+ * @param inDenominator denominator from Rational
+ * @return the value of the specified number as a positive double
.
+ * Prevents interpretation of 32 bit numbers as negative, and forces a positive answer
+ */
+ public static final double convertToPositiveValue(int inNumerator, int inDenominator)
+ {
+ if (inDenominator == 0) return 0.0;
+ double numeratorDbl = inNumerator;
+ double denomDbl = inDenominator;
+ if (inNumerator >= 0)
+ return numeratorDbl / denomDbl;
+ final double correction = Math.pow(2.0, 32);
+ numeratorDbl += correction;
+ if (inDenominator < 0) denomDbl += correction;
+ return numeratorDbl / denomDbl;
+ }
+
+
+ /**
+ * @param inNumerator numerator from Rational
+ * @param inDenominator denominator from Rational
+ * @return the value of the specified number as a positive double
.
+ * Forces a positive answer
+ */
+ public static final double convertToPositiveValue(long inNumerator, long inDenominator)
+ {
+ if (inDenominator == 0L) return 0.0;
+ final double numeratorDbl = inNumerator;
+ final double denomDbl = inDenominator;
+ return numeratorDbl / denomDbl;
+ }
}