1 package tim.prune.jpeg;
3 import java.util.ArrayList;
6 * Class to hold the GPS data extracted from a Jpeg including position and time
10 private boolean _exifDataPresent = false;
11 private char _latitudeRef = '\0';
12 private char _longitudeRef = '\0';
13 private byte _altitudeRef = 0;
14 private double[] _latitude = null;
15 private double[] _longitude = null;
16 private int _altitude = -1;
17 private boolean _altitudePresent = false;
18 private int[] _gpsTimestamp = null;
19 private int[] _gpsDatestamp = null;
20 private String _originalTimestamp = null;
21 private int _orientationCode = -1;
22 private byte[] _thumbnail = null;
23 private ArrayList<String> _errors = null;
27 * Set the exif data present flag
29 public void setExifDataPresent()
31 _exifDataPresent = true;
34 * @return true if exif data found
36 public boolean getExifDataPresent()
38 return _exifDataPresent;
42 * Set the latitude reference (N/S)
43 * @param inString string containing reference
45 public void setLatitudeRef(String inString)
47 if (inString != null && inString.length() == 1)
48 _latitudeRef = inString.charAt(0);
53 * @param inValues array of three doubles for deg-min-sec
55 public void setLatitude(double[] inValues)
57 if (inValues != null && inValues.length == 3)
62 * Set the longitude reference (E/W)
63 * @param inString string containing reference
65 public void setLongitudeRef(String inString)
67 if (inString != null && inString.length() == 1)
68 _longitudeRef = inString.charAt(0);
73 * @param inValues array of three doubles for deg-min-sec
75 public void setLongitude(double[] inValues)
77 if (inValues != null && inValues.length == 3)
78 _longitude = inValues;
82 * Set the altitude reference (sea level / not)
83 * @param inByte byte representing reference
85 public void setAltitudeRef(byte inByte)
87 _altitudeRef = inByte;
92 * @param inValue integer representing altitude
94 public void setAltitude(int inValue)
97 _altitudePresent = true;
101 * Set the Gps timestamp
102 * @param inValues array of ints holding timestamp
104 public void setGpsTimestamp(int[] inValues)
106 _gpsTimestamp = inValues;
110 * Set the Gps datestamp
111 * @param inValues array of ints holding datestamp
113 public void setGpsDatestamp(int[] inValues)
115 _gpsDatestamp = inValues;
119 * Set the original timestamp
120 * @param inStamp original timestamp of photo
122 public void setOriginalTimestamp(String inStamp)
124 _originalTimestamp = inStamp;
128 * Set the orientation code
129 * @param inCode code from exif (1 to 8)
131 public void setOrientationCode(int inCode)
133 if (inCode >= 1 && inCode <= 8) {
134 _orientationCode = inCode;
138 /** @return latitude ref as char */
139 public char getLatitudeRef() { return _latitudeRef; }
140 /** @return latitude as array of 3 Rationals */
141 public double[] getLatitude() { return _latitude; }
142 /** @return longitude ref as char */
143 public char getLongitudeRef() { return _longitudeRef; }
144 /** @return longitude as array of 3 doubles */
145 public double[] getLongitude() { return _longitude; }
146 /** @return altitude ref as byte (should be 0) */
147 public byte getAltitudeRef() { return _altitudeRef; }
148 /** @return true if altitude present */
149 public boolean hasAltitude() { return _altitudePresent; }
150 /** @return altitude as int */
151 public int getAltitude() { return _altitude; }
152 /** @return Gps timestamp as array of 3 ints */
153 public int[] getGpsTimestamp() { return _gpsTimestamp; }
154 /** @return Gps datestamp as array of 3 ints */
155 public int[] getGpsDatestamp() { return _gpsDatestamp; }
156 /** @return orientation code (1 to 8) */
157 public int getOrientationCode() { return _orientationCode; }
158 /** @return original timestamp as string */
159 public String getOriginalTimestamp() { return _originalTimestamp; }
163 * @param inBytes byte array containing thumbnail
165 public void setThumbnailImage(byte[] inBytes) {
166 _thumbnail = inBytes;
168 /** @return thumbnail as byte array */
169 public byte[] getThumbnailImage() {
174 * @return rotation required to display photo properly (0 to 3)
176 public int getRequiredRotation()
178 if (_orientationCode <= 2) { return 0; } // no rotation required
179 if (_orientationCode <= 4) { return 2; } // 180 degrees
180 if (_orientationCode <= 6) { return 1; } // 270 degrees, so need to rotate by 90
181 return 3; // 90 degrees, so need to rotate by 270
185 * @return true if data looks valid, ie has at least lat and long
186 * (altitude and timestamp optional).
188 public boolean isGpsValid()
190 return (_latitudeRef == 'N' || _latitudeRef == 'n' || _latitudeRef == 'S' || _latitudeRef == 's')
192 && (_longitudeRef == 'E' || _longitudeRef == 'e' || _longitudeRef == 'W' || _longitudeRef == 'w')
193 && _longitude != null;
197 * Add the given error message to the list of errors
198 * @param inError String containing error message
200 public void addError(String inError)
202 if (_errors == null) _errors = new ArrayList<String>();
203 _errors.add(inError);
207 * @return the number of errors, if any
209 public int getNumErrors()
211 if (_errors == null) return 0;
212 return _errors.size();
216 * @return true if errors occurred
218 public boolean hasErrors()
220 return getNumErrors() > 0;
224 * @return all errors as a list
226 public ArrayList<String> getErrors()