1 package tim.prune.jpeg;
4 import javax.swing.JOptionPane;
5 import tim.prune.I18nManager;
8 * Skeleton gateway to the Exif functions.
9 * This is required by Debian to divert Exif handling
10 * to the external libmetadata-extractor-java library
11 * instead of the included modified routines.
13 * Switching between internal and external libraries is
14 * handled by the ExifLibrarySwitch
16 public abstract class ExifGateway
18 /** Library object to call */
19 private static ExifLibrary _exifLibrary = null;
20 /** Flag to set whether failure warning has already been shown */
21 private static boolean _exifFailWarned = false;
23 /** Static block to initialise library */
26 String libraryClass = ExifLibrarySwitch.USE_INTERNAL_LIBRARY?"InternalExifLibrary":"ExternalExifLibrary";
29 _exifLibrary = (ExifLibrary) Class.forName("tim.prune.jpeg." + libraryClass).newInstance();
31 catch (Throwable nolib) {_exifLibrary = null;}
36 * Get the Jpeg data from the given file
37 * @param inFile file to read
38 * @return jpeg data, or null if none found
40 public static JpegData getJpegData(File inFile)
44 // Call library (if found)
45 if (_exifLibrary != null) {
46 JpegData data = _exifLibrary.getJpegData(inFile);
50 catch (LinkageError nolib) {}
51 // Not successful - warn if necessary
54 JOptionPane.showMessageDialog(null, I18nManager.getText("error.jpegload.exifreadfailed"),
55 I18nManager.getText("error.jpegload.dialogtitle"), JOptionPane.WARNING_MESSAGE);
56 _exifFailWarned = true;
62 * @return key to use to describe library, matching key for about dialog
64 public static String getDescriptionKey()
66 String key = ExifLibrarySwitch.USE_INTERNAL_LIBRARY?"internal":"external";
67 if (_exifLibrary == null || !_exifLibrary.looksOK()) {key = key + ".failed";}
74 * @param inNumerator numerator from Rational
75 * @param inDenominator denominator from Rational
76 * @return the value of the specified number as a positive <code>double</code>.
77 * Prevents interpretation of 32 bit numbers as negative, and forces a positive answer
79 public static final double convertToPositiveValue(int inNumerator, int inDenominator)
81 if (inDenominator == 0) return 0.0;
82 double numeratorDbl = inNumerator;
83 double denomDbl = inDenominator;
85 return numeratorDbl / denomDbl;
86 final double correction = Math.pow(2.0, 32);
87 numeratorDbl += correction;
88 if (inDenominator < 0) denomDbl += correction;
89 return numeratorDbl / denomDbl;