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 ArrayList<String> _errors = null;
28 * Set the exif data present flag
30 public void setExifDataPresent()
32 _exifDataPresent = true;
35 * @return true if exif data found
37 public boolean getExifDataPresent()
39 return _exifDataPresent;
43 * Set the latitude reference (N/S)
44 * @param inString string containing reference
46 public void setLatitudeRef(String inString)
48 if (inString != null && inString.length() == 1)
49 _latitudeRef = inString.charAt(0);
54 * @param inValues array of three doubles for deg-min-sec
56 public void setLatitude(double[] inValues)
58 if (inValues != null && inValues.length == 3)
63 * Set the longitude reference (E/W)
64 * @param inString string containing reference
66 public void setLongitudeRef(String inString)
68 if (inString != null && inString.length() == 1)
69 _longitudeRef = inString.charAt(0);
74 * @param inValues array of three doubles for deg-min-sec
76 public void setLongitude(double[] inValues)
78 if (inValues != null && inValues.length == 3)
79 _longitude = inValues;
83 * Set the altitude reference (sea level / not)
84 * @param inByte byte representing reference
86 public void setAltitudeRef(byte inByte)
88 _altitudeRef = inByte;
93 * @param inValue integer representing altitude
95 public void setAltitude(int inValue)
98 _altitudePresent = true;
102 * Set the Gps timestamp
103 * @param inValues array of ints holding timestamp
105 public void setGpsTimestamp(int[] inValues)
107 _gpsTimestamp = inValues;
111 * Set the Gps datestamp
112 * @param inValues array of ints holding datestamp
114 public void setGpsDatestamp(int[] inValues)
116 _gpsDatestamp = inValues;
120 * Set the original timestamp
121 * @param inStamp original timestamp of photo
123 public void setOriginalTimestamp(String inStamp)
125 _originalTimestamp = inStamp;
129 * Set the digitized timestamp
130 * @param inStamp digitized (creation) timestamp of photo
132 public void setDigitizedTimestamp(String inStamp)
134 _digitizedTimestamp = inStamp;
138 * Set the orientation code
139 * @param inCode code from exif (1 to 8)
141 public void setOrientationCode(int inCode)
143 if (inCode >= 1 && inCode <= 8) {
144 _orientationCode = inCode;
148 /** @return latitude ref as char */
149 public char getLatitudeRef() { return _latitudeRef; }
150 /** @return latitude as array of 3 Rationals */
151 public double[] getLatitude() { return _latitude; }
152 /** @return longitude ref as char */
153 public char getLongitudeRef() { return _longitudeRef; }
154 /** @return longitude as array of 3 doubles */
155 public double[] getLongitude() { return _longitude; }
156 /** @return altitude ref as byte (should be 0) */
157 public byte getAltitudeRef() { return _altitudeRef; }
158 /** @return true if altitude present */
159 public boolean hasAltitude() { return _altitudePresent; }
160 /** @return altitude as int */
161 public int getAltitude() { return _altitude; }
162 /** @return Gps timestamp as array of 3 ints */
163 public int[] getGpsTimestamp() { return _gpsTimestamp; }
164 /** @return Gps datestamp as array of 3 ints */
165 public int[] getGpsDatestamp() { return _gpsDatestamp; }
166 /** @return orientation code (1 to 8) */
167 public int getOrientationCode() { return _orientationCode; }
168 /** @return original timestamp as string */
169 public String getOriginalTimestamp() { return _originalTimestamp; }
170 /** @return digitized timestamp as string */
171 public String getDigitizedTimestamp() { return _digitizedTimestamp; }
175 * @param inBytes byte array containing thumbnail
177 public void setThumbnailImage(byte[] inBytes) {
178 _thumbnail = inBytes;
180 /** @return thumbnail as byte array */
181 public byte[] getThumbnailImage() {
186 * @return rotation required to display photo properly (0 to 3)
188 public int getRequiredRotation()
190 if (_orientationCode <= 2) { return 0; } // no rotation required
191 if (_orientationCode <= 4) { return 2; } // 180 degrees
192 if (_orientationCode <= 6) { return 1; } // 270 degrees, so need to rotate by 90
193 return 3; // 90 degrees, so need to rotate by 270
197 * @return true if data looks valid, ie has at least lat and long
198 * (altitude and timestamp optional).
200 public boolean isGpsValid()
202 return (_latitudeRef == 'N' || _latitudeRef == 'n' || _latitudeRef == 'S' || _latitudeRef == 's')
204 && (_longitudeRef == 'E' || _longitudeRef == 'e' || _longitudeRef == 'W' || _longitudeRef == 'w')
205 && _longitude != null;
209 * Add the given error message to the list of errors
210 * @param inError String containing error message
212 public void addError(String inError)
214 if (_errors == null) _errors = new ArrayList<String>();
215 _errors.add(inError);
219 * @return the number of errors, if any
221 public int getNumErrors()
223 if (_errors == null) return 0;
224 return _errors.size();
228 * @return true if errors occurred
230 public boolean hasErrors()
232 return getNumErrors() > 0;
236 * @return all errors as a list
238 public ArrayList<String> getErrors()