KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > jwi > jgallery > EXIFInfo


1 package de.jwi.jgallery;
2
3 /*
4  * jGallery - Java web application to display image galleries
5  *
6  * Copyright (C) 2004 Juergen Weber
7  *
8  * This file is part of jGallery.
9  *
10  * jGallery is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * jGallery is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with jGallery; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston
23  */

24
25 import java.io.InputStream JavaDoc;
26 import java.io.Serializable JavaDoc;
27 import java.text.DecimalFormat JavaDoc;
28 import java.text.NumberFormat JavaDoc;
29
30 import com.drew.imaging.jpeg.JpegMetadataReader;
31 import com.drew.imaging.jpeg.JpegProcessingException;
32 import com.drew.metadata.Directory;
33 import com.drew.metadata.Metadata;
34 import com.drew.metadata.MetadataException;
35 import com.drew.metadata.exif.ExifDirectory;
36
37 /**
38  * @author Jürgen Weber
39  * Source file created on 29.02.2004
40  *
41  */

42 public class EXIFInfo implements Serializable JavaDoc
43 {
44
45     
46     // EXIF Data
47

48     private String JavaDoc imageWidth; // Width of image in Pixels
49

50     private String JavaDoc imageHeight; // Height of image in pixels
51

52     private String JavaDoc originalWidth; // Width of original image in pixels
53

54     private String JavaDoc originalHeight; // Height of original image in pixels
55

56     private String JavaDoc originalWidthDpi; //
57

58     private String JavaDoc originalHeightDpi; //
59

60     private String JavaDoc formatName; // Type of image
61

62     private String JavaDoc compressionLevel; //
63

64     private String JavaDoc originalDate; // Date written by camera
65

66     private String JavaDoc resolution; // Original image resolution as written by camera
67

68     private String JavaDoc flash; // If flash was used
69

70     private String JavaDoc focalLength; // Focal length
71

72     private String JavaDoc exposureTime;
73
74     private String JavaDoc isoEquivalent;
75
76     private String JavaDoc aperture = null; // Aperture
77

78     private String JavaDoc focusDistance;
79
80     private String JavaDoc meteringMode;
81
82     private String JavaDoc cameraMake;
83
84     private String JavaDoc cameraModel; // Camera model
85

86     private String JavaDoc sensorType; // Camera sensor type
87

88     private String JavaDoc comment; // Comment.
89

90     private static double ROOTTWO = Math.sqrt(2);
91
92     private static NumberFormat JavaDoc numberFormat = NumberFormat.getNumberInstance();
93
94     DecimalFormat JavaDoc decimalFormatter = new DecimalFormat JavaDoc("0.#");
95
96     static
97     {
98         numberFormat.setMaximumFractionDigits(1);
99     }
100
101     EXIFInfo(InputStream JavaDoc jpeg) throws GalleryException
102     {
103         try
104         {
105             setEXIFVariables(jpeg);
106         }
107         catch (MetadataException e)
108         {
109             throw new GalleryException(e.getMessage());
110         }
111         catch (JpegProcessingException e)
112         {
113             throw new GalleryException(e.getMessage());
114         }
115     }
116
117     public String JavaDoc getFlash()
118     {
119         return flash;
120     }
121
122     private void setFlash(String JavaDoc flash)
123     {
124         this.flash = flash;
125     }
126
127     public String JavaDoc getImageHeight()
128     {
129         return imageHeight;
130     }
131
132     public String JavaDoc getImageWidth()
133     {
134         return imageWidth;
135     }
136
137     public String JavaDoc getComment()
138     {
139         return comment;
140     }
141
142     public String JavaDoc getAperture()
143     {
144         return aperture;
145     }
146
147     private void setAperture(String JavaDoc aperture)
148     {
149         this.aperture = aperture;
150     }
151     
152  /* private void setAperture(float apertureApex)
153     {
154         double fStop = Math.pow(ROOTTWO, apertureApex);
155         this.aperture = decimalFormatter.format(fStop);
156     }
157 */

158     public String JavaDoc getCameraMake()
159     {
160         return cameraMake;
161     }
162
163     private void setCameraMake(String JavaDoc cameraMake)
164     {
165         this.cameraMake = cameraMake;
166     }
167
168     public String JavaDoc getCameraModel()
169     {
170         return cameraModel;
171     }
172
173     private void setCameraModel(String JavaDoc cameraModel)
174     {
175         this.cameraModel = cameraModel;
176     }
177
178     public String JavaDoc getCompressionLevel()
179     {
180         return compressionLevel;
181     }
182
183     private void setCompressionLevel(String JavaDoc compressionLevel)
184     {
185         this.compressionLevel = compressionLevel;
186     }
187
188     public String JavaDoc getExposureTime()
189     {
190         return exposureTime;
191     }
192
193     private void setExposureTime(String JavaDoc exposureTime)
194     {
195         this.exposureTime = exposureTime;
196     }
197
198     public String JavaDoc getFocalLength()
199     {
200         return focalLength;
201     }
202
203     private void setFocalLength(String JavaDoc focalLength)
204     {
205         this.focalLength = focalLength;
206     }
207
208     public String JavaDoc getFocusDistance()
209     {
210         return focusDistance;
211     }
212
213     private void setFocusDistance(String JavaDoc focusDistance)
214     {
215         this.focusDistance = focusDistance;
216     }
217
218     public String JavaDoc getFormatName()
219     {
220         return formatName;
221     }
222
223     private void setFormatName(String JavaDoc formatName)
224     {
225         this.formatName = formatName;
226     }
227
228     public String JavaDoc getIsoEquivalent()
229     {
230         return isoEquivalent;
231     }
232
233     private void setIsoEquivalent(String JavaDoc isoEquivalent)
234     {
235         this.isoEquivalent = isoEquivalent;
236     }
237
238     public String JavaDoc getMeteringMode()
239     {
240         return meteringMode;
241     }
242
243     private void setMeteringMode(String JavaDoc meteringMode)
244     {
245         this.meteringMode = meteringMode;
246     }
247
248     public String JavaDoc getOriginalDate()
249     {
250         return originalDate;
251     }
252
253     private void setOriginalDate(String JavaDoc originalDate)
254     {
255         this.originalDate = originalDate;
256     }
257
258     public String JavaDoc getOriginalHeight()
259     {
260         return originalHeight;
261     }
262
263     private void setOriginalHeight(String JavaDoc originalHeight)
264     {
265         this.originalHeight = originalHeight;
266     }
267
268     public String JavaDoc getOriginalHeightDpi()
269     {
270         return originalHeightDpi;
271     }
272
273     private void setOriginalHeightDpi(String JavaDoc originalHeightDpi)
274     {
275         this.originalHeightDpi = originalHeightDpi;
276     }
277
278     public String JavaDoc getOriginalWidth()
279     {
280         return originalWidth;
281     }
282
283     private void setOriginalWidth(String JavaDoc originalWidth)
284     {
285         this.originalWidth = originalWidth;
286     }
287
288     public String JavaDoc getOriginalWidthDpi()
289     {
290         return originalWidthDpi;
291     }
292
293     private void setOriginalWidthDpi(String JavaDoc originalWidthDpi)
294     {
295         this.originalWidthDpi = originalWidthDpi;
296     }
297
298     public String JavaDoc getResolution()
299     {
300         return resolution;
301     }
302
303     private void setResolution(String JavaDoc resolution)
304     {
305         this.resolution = resolution;
306     }
307
308     public String JavaDoc getSensorType()
309     {
310         return sensorType;
311     }
312
313     private void setSensorType(String JavaDoc sensorType)
314     {
315         this.sensorType = sensorType;
316     }
317
318     private void setComment(String JavaDoc comment)
319     {
320         if ("ASCII".equals(comment))
321         {
322             comment = "";
323             // Bug in metadata-extractor ?
324
}
325         else
326         {
327             this.comment = comment;
328         }
329     }
330
331     private void setImageHeight(String JavaDoc imageHeight)
332     {
333         this.imageHeight = imageHeight;
334     }
335
336     private void setImageWidth(String JavaDoc imageWidth)
337     {
338         this.imageWidth = imageWidth;
339     }
340
341     private void setEXIFVariables(InputStream JavaDoc jpeg) throws MetadataException,
342             JpegProcessingException
343     {
344         Metadata metadata;
345         Directory exifDirectory;
346
347         
348         metadata = JpegMetadataReader.readMetadata(jpeg);
349
350         exifDirectory = metadata.getDirectory(ExifDirectory.class);
351
352         setOriginalWidth(exifDirectory
353                 .getString(ExifDirectory.TAG_EXIF_IMAGE_WIDTH)); //TODO
354
setOriginalHeight(exifDirectory
355                 .getString(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT)); //TODO
356

357         setCompressionLevel(exifDirectory
358                 .getString(ExifDirectory.TAG_COMPRESSION_LEVEL));
359         setOriginalDate(exifDirectory
360                 .getString(ExifDirectory.TAG_DATETIME_ORIGINAL));
361
362         setResolution(exifDirectory.getString(ExifDirectory.TAG_X_RESOLUTION));
363         
364         setFlash(exifDirectory.getDescription(ExifDirectory.TAG_FLASH));
365         
366         setFocalLength(exifDirectory.getDescription(ExifDirectory.TAG_FOCAL_LENGTH));
367
368         setIsoEquivalent(exifDirectory
369                 .getDescription(ExifDirectory.TAG_ISO_EQUIVALENT));
370
371         setExposureTime(exifDirectory.getDescription(ExifDirectory.TAG_EXPOSURE_TIME));
372
373         setAperture(exifDirectory.getDescription(ExifDirectory.TAG_APERTURE));
374
375         setFocusDistance(exifDirectory
376                 .getString(ExifDirectory.TAG_SUBJECT_DISTANCE));
377
378         setMeteringMode(exifDirectory.getDescription(ExifDirectory.TAG_METERING_MODE));
379
380         setCameraMake(exifDirectory.getString(ExifDirectory.TAG_MAKE));
381
382         setCameraModel(exifDirectory.getString(ExifDirectory.TAG_MODEL));
383
384         setSensorType(exifDirectory.getString(ExifDirectory.TAG_SENSING_METHOD));
385
386         setComment(exifDirectory.getString(ExifDirectory.TAG_USER_COMMENT));
387
388     }
389
390 }
391
Popular Tags