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 String _digitizedTimestamp = null;
22 private int _orientationCode = -1;
23 private byte[] _thumbnail = null;
24 private double _bearing = -1.0;
25 private ArrayList<String> _errors = null;
29 * Set the exif data present flag
31 public void setExifDataPresent()
33 _exifDataPresent = true;
36 * @return true if exif data found
38 public boolean getExifDataPresent()
40 return _exifDataPresent;
44 * Set the latitude reference (N/S)
45 * @param inString string containing reference
47 public void setLatitudeRef(String inString)
49 if (inString != null && inString.length() == 1)
50 _latitudeRef = inString.charAt(0);
55 * @param inValues array of three doubles for deg-min-sec
57 public void setLatitude(double[] inValues)
59 if (inValues != null && inValues.length == 3)
64 * Set the longitude reference (E/W)
65 * @param inString string containing reference
67 public void setLongitudeRef(String inString)
69 if (inString != null && inString.length() == 1)
70 _longitudeRef = inString.charAt(0);
75 * @param inValues array of three doubles for deg-min-sec
77 public void setLongitude(double[] inValues)
79 if (inValues != null && inValues.length == 3)
80 _longitude = inValues;
84 * Set the altitude reference (sea level / not)
85 * @param inByte byte representing reference
87 public void setAltitudeRef(byte inByte)
89 _altitudeRef = inByte;
94 * @param inValue integer representing altitude
96 public void setAltitude(int inValue)
99 _altitudePresent = true;
103 * Set the Gps timestamp
104 * @param inValues array of ints holding timestamp
106 public void setGpsTimestamp(int[] inValues)
108 _gpsTimestamp = inValues;
112 * Set the Gps datestamp
113 * @param inValues array of ints holding datestamp
115 public void setGpsDatestamp(int[] inValues)
117 _gpsDatestamp = inValues;
121 * Set the original timestamp
122 * @param inStamp original timestamp of photo
124 public void setOriginalTimestamp(String inStamp)
126 _originalTimestamp = inStamp;
130 * Set the digitized timestamp
131 * @param inStamp digitized (creation) timestamp of photo
133 public void setDigitizedTimestamp(String inStamp)
135 _digitizedTimestamp = inStamp;
139 * Set the orientation code
140 * @param inCode code from exif (1 to 8)
142 public void setOrientationCode(int inCode)
144 if (inCode >= 1 && inCode <= 8) {
145 _orientationCode = inCode;
150 * Set the bearing (0 - 360)
151 * @param inBearing bearing in degrees
153 public void setBearing(double inBearing)
155 _bearing = inBearing;
158 /** @return latitude ref as char */
159 public char getLatitudeRef() { return _latitudeRef; }
160 /** @return latitude as array of 3 Rationals */
161 public double[] getLatitude() { return _latitude; }
162 /** @return longitude ref as char */
163 public char getLongitudeRef() { return _longitudeRef; }
164 /** @return longitude as array of 3 doubles */
165 public double[] getLongitude() { return _longitude; }
166 /** @return altitude ref as byte (should be 0) */
167 public byte getAltitudeRef() { return _altitudeRef; }
168 /** @return true if altitude present */
169 public boolean hasAltitude() { return _altitudePresent; }
170 /** @return altitude as int */
171 public int getAltitude() { return _altitude; }
172 /** @return Gps timestamp as array of 3 ints */
173 public int[] getGpsTimestamp() { return _gpsTimestamp; }
174 /** @return Gps datestamp as array of 3 ints */
175 public int[] getGpsDatestamp() { return _gpsDatestamp; }
176 /** @return orientation code (1 to 8) */
177 public int getOrientationCode() { return _orientationCode; }
178 /** @return original timestamp as string */
179 public String getOriginalTimestamp() { return _originalTimestamp; }
180 /** @return digitized timestamp as string */
181 public String getDigitizedTimestamp() { return _digitizedTimestamp; }
182 /** @return bearing in degrees or -1 */
183 public double getBearing() { return _bearing; }
187 * @param inBytes byte array containing thumbnail
189 public void setThumbnailImage(byte[] inBytes) {
190 _thumbnail = inBytes;
192 /** @return thumbnail as byte array */
193 public byte[] getThumbnailImage() {
198 * @return rotation required to display photo properly (0 to 3)
200 public int getRequiredRotation()
202 if (_orientationCode <= 2) { return 0; } // no rotation required
203 if (_orientationCode <= 4) { return 2; } // 180 degrees
204 if (_orientationCode <= 6) { return 1; } // 270 degrees, so need to rotate by 90
205 return 3; // 90 degrees, so need to rotate by 270
209 * @return true if data looks valid, ie has at least lat and long
210 * (altitude and timestamp optional).
212 public boolean isGpsValid()
214 return (_latitudeRef == 'N' || _latitudeRef == 'n' || _latitudeRef == 'S' || _latitudeRef == 's')
216 && (_longitudeRef == 'E' || _longitudeRef == 'e' || _longitudeRef == 'W' || _longitudeRef == 'w')
217 && _longitude != null;
221 * Add the given error message to the list of errors
222 * @param inError String containing error message
224 public void addError(String inError)
226 if (_errors == null) _errors = new ArrayList<String>();
227 _errors.add(inError);
231 * @return the number of errors, if any
233 public int getNumErrors()
235 if (_errors == null) return 0;
236 return _errors.size();
240 * @return true if errors occurred
242 public boolean hasErrors()
244 return getNumErrors() > 0;
248 * @return all errors as a list
250 public ArrayList<String> getErrors()