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