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