1 package tim.prune.drew.jpeg;
3 import java.util.ArrayList;
7 * Class to hold the GPS data extracted from a Jpeg including position and time
11 private boolean _exifDataPresent = false;
12 private char _latitudeRef = '\0';
13 private char _longitudeRef = '\0';
14 private byte _altitudeRef = 0;
15 private Rational[] _latitude = null;
16 private Rational[] _longitude = null;
17 private Rational _altitude = null;
18 private Rational[] _gpsTimestamp = null;
19 private Rational[] _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 inChar character representing reference
45 public void setLatitudeRef(char inChar)
47 _latitudeRef = inChar;
51 * Set the latitude reference (N/S)
52 * @param inString string containing reference
54 public void setLatitudeRef(String inString)
56 if (inString != null && inString.length() == 1)
57 setLatitudeRef(inString.charAt(0));
62 * @param inValues array of three Rationals for deg-min-sec
64 public void setLatitude(Rational[] inValues)
66 if (inValues != null && inValues.length == 3)
71 * Set the longitude reference (E/W)
72 * @param inChar character representing reference
74 public void setLongitudeRef(char inChar)
76 _longitudeRef = inChar;
80 * Set the longitude reference (E/W)
81 * @param inString string containing reference
83 public void setLongitudeRef(String inString)
85 if (inString != null && inString.length() == 1)
86 setLongitudeRef(inString.charAt(0));
91 * @param inValues array of three Rationals for deg-min-sec
93 public void setLongitude(Rational[] inValues)
95 if (inValues != null && inValues.length == 3)
96 _longitude = inValues;
100 * Set the altitude reference (sea level / not)
101 * @param inByte byte representing reference
103 public void setAltitudeRef(byte inByte)
105 _altitudeRef = inByte;
110 * @param inRational Rational number representing altitude
112 public void setAltitude(Rational inRational)
114 _altitude = inRational;
118 * Set the Gps timestamp
119 * @param inValues array of Rationals holding timestamp
121 public void setGpsTimestamp(Rational[] inValues)
123 _gpsTimestamp = inValues;
127 * Set the Gps datestamp
128 * @param inValues array of Rationals holding datestamp
130 public void setGpsDatestamp(Rational[] inValues)
132 _gpsDatestamp = inValues;
136 * Set the original timestamp
137 * @param inStamp original timestamp of photo
139 public void setOriginalTimestamp(String inStamp)
141 _originalTimestamp = inStamp;
145 * Set the orientation code
146 * @param inCode code from exif (1 to 8)
148 public void setOrientationCode(int inCode)
150 if (inCode >= 1 && inCode <= 8) {
151 _orientationCode = inCode;
155 /** @return latitude ref as char */
156 public char getLatitudeRef() { return _latitudeRef; }
157 /** @return latitude as array of 3 Rationals */
158 public Rational[] getLatitude() { return _latitude; }
159 /** @return longitude ref as char */
160 public char getLongitudeRef() { return _longitudeRef; }
161 /** @return longitude as array of 3 Rationals */
162 public Rational[] getLongitude() { return _longitude; }
163 /** @return altitude ref as byte (should be 0) */
164 public byte getAltitudeRef() { return _altitudeRef; }
165 /** @return altitude as Rational */
166 public Rational getAltitude() { return _altitude; }
167 /** @return Gps timestamp as array of 3 Rationals */
168 public Rational[] getGpsTimestamp() { return _gpsTimestamp; }
169 /** @return Gps datestamp as array of 3 Rationals */
170 public Rational[] getGpsDatestamp() { return _gpsDatestamp; }
171 /** @return orientation code (1 to 8) */
172 public int getOrientationCode() { return _orientationCode; }
173 /** @return original timestamp as string */
174 public String getOriginalTimestamp() { return _originalTimestamp; }
178 * @param inBytes byte array containing thumbnail
180 public void setThumbnailImage(byte[] inBytes) {
181 _thumbnail = inBytes;
183 /** @return thumbnail as byte array */
184 public byte[] getThumbnailImage() {
189 * @return rotation required to display photo properly (0 to 3)
191 public int getRequiredRotation()
193 if (_orientationCode <= 2) { return 0; } // no rotation required
194 if (_orientationCode <= 4) { return 2; } // 180 degrees
195 if (_orientationCode <= 6) { return 1; } // 270 degrees, so need to rotate by 90
196 return 3; // 90 degrees, so need to rotate by 270
200 * @return true if data looks valid, ie has at least lat and long
201 * (altitude and timestamp optional).
203 public boolean isValid()
205 return (_latitudeRef == 'N' || _latitudeRef == 'n' || _latitudeRef == 'S' || _latitudeRef == 's')
207 && (_longitudeRef == 'E' || _longitudeRef == 'e' || _longitudeRef == 'W' || _longitudeRef == 'w')
208 && _longitude != null;
212 * Add the given error message to the list of errors
213 * @param inError String containing error message
215 public void addError(String inError)
217 if (_errors == null) _errors = new ArrayList<String>();
218 _errors.add(inError);
222 * @return the number of errors, if any
224 public int getNumErrors()
226 if (_errors == null) return 0;
227 return _errors.size();
231 * @return true if errors occurred
233 public boolean hasErrors()
235 return getNumErrors() > 0;
239 * @return all errors as a list
241 public List<String> getErrors()