]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/jpeg/JpegData.java
Version 13, August 2011
[GpsPrune.git] / tim / prune / jpeg / JpegData.java
1 package tim.prune.jpeg;
2
3 import java.util.ArrayList;
4
5 /**
6  * Class to hold the GPS data extracted from a Jpeg including position and time
7  */
8 public class JpegData
9 {
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;
26
27
28         /**
29          * Set the exif data present flag
30          */
31         public void setExifDataPresent()
32         {
33                 _exifDataPresent = true;
34         }
35         /**
36          * @return true if exif data found
37          */
38         public boolean getExifDataPresent()
39         {
40                 return _exifDataPresent;
41         }
42
43         /**
44          * Set the latitude reference (N/S)
45          * @param inString string containing reference
46          */
47         public void setLatitudeRef(String inString)
48         {
49                 if (inString != null && inString.length() == 1)
50                         _latitudeRef = inString.charAt(0);
51         }
52
53         /**
54          * Set the latitude
55          * @param inValues array of three doubles for deg-min-sec
56          */
57         public void setLatitude(double[] inValues)
58         {
59                 if (inValues != null && inValues.length == 3)
60                         _latitude = inValues;
61         }
62
63         /**
64          * Set the longitude reference (E/W)
65          * @param inString string containing reference
66          */
67         public void setLongitudeRef(String inString)
68         {
69                 if (inString != null && inString.length() == 1)
70                         _longitudeRef = inString.charAt(0);
71         }
72
73         /**
74          * Set the longitude
75          * @param inValues array of three doubles for deg-min-sec
76          */
77         public void setLongitude(double[] inValues)
78         {
79                 if (inValues != null && inValues.length == 3)
80                         _longitude = inValues;
81         }
82
83         /**
84          * Set the altitude reference (sea level / not)
85          * @param inByte byte representing reference
86          */
87         public void setAltitudeRef(byte inByte)
88         {
89                 _altitudeRef = inByte;
90         }
91
92         /**
93          * Set the altitude
94          * @param inValue integer representing altitude
95          */
96         public void setAltitude(int inValue)
97         {
98                 _altitude = inValue;
99                 _altitudePresent = true;
100         }
101
102         /**
103          * Set the Gps timestamp
104          * @param inValues array of ints holding timestamp
105          */
106         public void setGpsTimestamp(int[] inValues)
107         {
108                 _gpsTimestamp = inValues;
109         }
110
111         /**
112          * Set the Gps datestamp
113          * @param inValues array of ints holding datestamp
114          */
115         public void setGpsDatestamp(int[] inValues)
116         {
117                 _gpsDatestamp = inValues;
118         }
119
120         /**
121          * Set the original timestamp
122          * @param inStamp original timestamp of photo
123          */
124         public void setOriginalTimestamp(String inStamp)
125         {
126                 _originalTimestamp = inStamp;
127         }
128
129         /**
130          * Set the digitized timestamp
131          * @param inStamp digitized (creation) timestamp of photo
132          */
133         public void setDigitizedTimestamp(String inStamp)
134         {
135                 _digitizedTimestamp = inStamp;
136         }
137
138         /**
139          * Set the orientation code
140          * @param inCode code from exif (1 to 8)
141          */
142         public void setOrientationCode(int inCode)
143         {
144                 if (inCode >= 1 && inCode <= 8) {
145                         _orientationCode = inCode;
146                 }
147         }
148
149         /**
150          * Set the bearing (0 - 360)
151          * @param inBearing bearing in degrees
152          */
153         public void setBearing(double inBearing)
154         {
155                 _bearing = inBearing;
156         }
157
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; }
184
185         /**
186          * Set the thumbnail
187          * @param inBytes byte array containing thumbnail
188          */
189         public void setThumbnailImage(byte[] inBytes) {
190                 _thumbnail = inBytes;
191         }
192         /** @return thumbnail as byte array */
193         public byte[] getThumbnailImage() {
194                 return _thumbnail;
195         }
196
197         /**
198          * @return rotation required to display photo properly (0 to 3)
199          */
200         public int getRequiredRotation()
201         {
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
206         }
207
208         /**
209          * @return true if data looks valid, ie has at least lat and long
210          *  (altitude and timestamp optional).
211          */
212         public boolean isGpsValid()
213         {
214                 return (_latitudeRef == 'N' || _latitudeRef == 'n' || _latitudeRef == 'S' || _latitudeRef == 's')
215                         && _latitude != null
216                         && (_longitudeRef == 'E' || _longitudeRef == 'e' || _longitudeRef == 'W' || _longitudeRef == 'w')
217                         && _longitude != null;
218         }
219
220         /**
221          * Add the given error message to the list of errors
222          * @param inError String containing error message
223          */
224         public void addError(String inError)
225         {
226                 if (_errors == null) _errors = new ArrayList<String>();
227                 _errors.add(inError);
228         }
229
230         /**
231          * @return the number of errors, if any
232          */
233         public int getNumErrors()
234         {
235                 if (_errors == null) return 0;
236                 return _errors.size();
237         }
238
239         /**
240          * @return true if errors occurred
241          */
242         public boolean hasErrors()
243         {
244                 return getNumErrors() > 0;
245         }
246
247         /**
248          * @return all errors as a list
249          */
250         public ArrayList<String> getErrors()
251         {
252                 return _errors;
253         }
254 }