magoffin.matt.meta.image
Class EXIFJpegMetadataResource

java.lang.Object
  extended by magoffin.matt.meta.support.AbstractMetadataResource
      extended by magoffin.matt.meta.support.AbstractEnumMetadataResource<ImageMetadataType>
          extended by magoffin.matt.meta.image.EXIFJpegMetadataResource
All Implemented Interfaces:
MetadataResource
Direct Known Subclasses:
Canon

public class EXIFJpegMetadataResource
extends AbstractEnumMetadataResource<ImageMetadataType>
implements MetadataResource

MetadataResource implementation for JPEG+EXIF resources.

This implementation relies on Metadata Extractor, available from http://drewnoakes.com/code/exif/

Version:
$Revision: 3 $ $Date: 2008-12-27 08:09:28 +1300 (Sat, 27 Dec 2008) $
Author:
Matt Magoffin (spamsqr@msqr.us)

Field Summary
static java.lang.String EXIF_BASIC_DATE_FORMAT
          A date format in the form yyyy:MM:dd hh:mm:ss.
 
Fields inherited from class magoffin.matt.meta.support.AbstractMetadataResource
log
 
Constructor Summary
EXIFJpegMetadataResource(java.io.InputStream in)
          Construct from an InputStream.
EXIFJpegMetadataResource(com.drew.metadata.Metadata exif)
          Construct from an existing EXIF Metadata instance.
 
Method Summary
protected  java.lang.String extractAperture()
          Extract the aperture (APEX value).
protected  java.lang.String extractCameraMake()
          Extract the camera make.
protected  java.lang.String extractCameraModel()
          Extract the cameral model.
protected  java.util.Date extractCreationDate()
          Extract a creation date from the EXIF.
protected  java.lang.String extractExposureBias()
          Extract the exposure bias, as an integer string.
protected  java.lang.String extractExposureTime()
          Extract the exposure time as a String value.
protected  java.lang.String extractFlash()
          Extract boolean FALSE if flash did not fire, TRUE otherwise.
protected  java.lang.String extractFocalLength()
          Extract the focal length.
protected  java.lang.String extractFocalLength35mmEquiv()
          Extract the focal length in terms of 35mm film.
protected  java.lang.String extractFstop()
          Extract the aperture as an F-Stop value.
protected  java.lang.String extractGpsLatitude()
          Extract the GPS latitude as a String value.
protected  java.lang.String extractGpsLongitude()
          Extract the GPS longitude as a String value.
protected  java.lang.String extractOrientation()
          Extract the orientation (as an integer string).
protected  java.lang.String extractShutterSpeed()
          Extract the shutter speed as a String value.
protected  int getExifInt(int tagType)
          Get an EXIF integer value.
protected  com.drew.lang.Rational getExifRational(int tagType)
          Get a EXIF Rational value.
protected  java.lang.String getExifString(int tagType)
          Get a EXIF String value.
protected  float getFocalLength35mmEquivFactor()
          Get a multiplication factor to convert the EXIF focal length into a 35mm equivalent length, for cameras that work this way.
protected  int getMetaInt(java.lang.Class<? extends com.drew.metadata.Directory> dirClass, int tagType)
          Get an EXIF integer value from an arbitrary EXIF directory.
protected  com.drew.lang.Rational getMetaRational(java.lang.Class<? extends com.drew.metadata.Directory> dirClass, int tagType)
          Get a EXIF Rational value from an arbitrary EXIF directory.
protected  java.lang.String getMetaString(java.lang.Class<? extends com.drew.metadata.Directory> dirClass, int tagType)
          Get a metadata String value from an arbitrary EXIF directory.
protected  void parseExif()
          Parse supported EXIF data from the Metadata instance associated with this object.
protected  java.lang.String roundDecimal(double decimal, int precision)
          Round a decimal to a number of places.
 
Methods inherited from class magoffin.matt.meta.support.AbstractEnumMetadataResource
addError, addValue, getValue, getValues, setValue, setValues
 
Methods inherited from class magoffin.matt.meta.support.AbstractMetadataResource
addError, addValue, clearValues, getParsedKeys, getParseErrors, getValue, getValueList, getValues, setValue, setValues
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface magoffin.matt.meta.MetadataResource
getParsedKeys, getParseErrors, getValue, getValues
 

Field Detail

EXIF_BASIC_DATE_FORMAT

public static final java.lang.String EXIF_BASIC_DATE_FORMAT
A date format in the form yyyy:MM:dd hh:mm:ss.

See Also:
Constant Field Values
Constructor Detail

EXIFJpegMetadataResource

public EXIFJpegMetadataResource(java.io.InputStream in)
Construct from an InputStream.

Parameters:
in - the JPEG input stream

EXIFJpegMetadataResource

public EXIFJpegMetadataResource(com.drew.metadata.Metadata exif)
Construct from an existing EXIF Metadata instance.

Parameters:
exif - the EXIF metadata
Method Detail

parseExif

protected void parseExif()
Parse supported EXIF data from the Metadata instance associated with this object.

Extending classes might want to override this behavior.


extractAperture

protected java.lang.String extractAperture()
Extract the aperture (APEX value).

Returns:
aperture

extractFstop

protected java.lang.String extractFstop()
Extract the aperture as an F-Stop value.

Returns:
f-stop

extractCameraMake

protected java.lang.String extractCameraMake()
Extract the camera make.

Returns:
camera make

extractCameraModel

protected java.lang.String extractCameraModel()
Extract the cameral model.

Returns:
camera model

extractExposureBias

protected java.lang.String extractExposureBias()
Extract the exposure bias, as an integer string.

Returns:
the exposure bias

extractFlash

protected java.lang.String extractFlash()
Extract boolean FALSE if flash did not fire, TRUE otherwise.

Returns:
boolean string

extractFocalLength

protected java.lang.String extractFocalLength()
Extract the focal length.

Returns:
focal length

extractFocalLength35mmEquiv

protected java.lang.String extractFocalLength35mmEquiv()
Extract the focal length in terms of 35mm film.

Returns:
focal length

extractOrientation

protected java.lang.String extractOrientation()
Extract the orientation (as an integer string).

Returns:
orientation

extractCreationDate

protected java.util.Date extractCreationDate()
Extract a creation date from the EXIF.

This method attempts to find the creation date for the image by taking the first value available from:

  1. ExifDirectory.TAG_DATETIME_ORIGINAL
  2. ExifDirectory.TAG_DATETIME_DIGITIZED
  3. ExifDirectory.TAG_DATETIME

If a date is found, it is parsed using the date format EXIF_BASIC_DATE_FORMAT. If a parse exception occurs, or no date is found, null is returned.

Returns:
a Date

extractExposureTime

protected java.lang.String extractExposureTime()
Extract the exposure time as a String value.

This method attempts to format the exposure Rational in a sensible way.

Returns:
the exposure string

extractShutterSpeed

protected java.lang.String extractShutterSpeed()
Extract the shutter speed as a String value.

This method attempts to format the shutter speed Rational in a sensible way.

Returns:
the shutter speed string

extractGpsLongitude

protected java.lang.String extractGpsLongitude()
Extract the GPS longitude as a String value.

This method combines the longitude reference with the longitude value.

Returns:
the GPS longitude string

extractGpsLatitude

protected java.lang.String extractGpsLatitude()
Extract the GPS latitude as a String value.

This method combines the latitude reference with the latitude value.

Returns:
the GPS latitude string

roundDecimal

protected java.lang.String roundDecimal(double decimal,
                                        int precision)
Round a decimal to a number of places.

Parameters:
decimal - the number to round
precision - the maximum number of fraction digits
Returns:
the rounded number, or decimal if an error occurs

getExifInt

protected int getExifInt(int tagType)
Get an EXIF integer value.

Parameters:
tagType - the EXIF tag to get an integer value for
Returns:
the integer value, or -1 if not found

getExifRational

protected com.drew.lang.Rational getExifRational(int tagType)
Get a EXIF Rational value.

Parameters:
tagType - the EXIF tag to get a Rational value for
Returns:
the Rational, or null if not found or an exception occurs

getExifString

protected java.lang.String getExifString(int tagType)
Get a EXIF String value.

Parameters:
tagType - the EXIF tag to get a String value for
Returns:
the String, or null if not found or an exception occurs

getMetaInt

protected int getMetaInt(java.lang.Class<? extends com.drew.metadata.Directory> dirClass,
                         int tagType)
Get an EXIF integer value from an arbitrary EXIF directory.

Parameters:
dirClass - the class of the directory to extract from
tagType - the EXIF tag to get an integer value for
Returns:
the integer value, or -1 if not found

getMetaRational

protected com.drew.lang.Rational getMetaRational(java.lang.Class<? extends com.drew.metadata.Directory> dirClass,
                                                 int tagType)
Get a EXIF Rational value from an arbitrary EXIF directory.

Parameters:
dirClass - the class of the directory to extract from
tagType - the EXIF tag to get a Rational value for
Returns:
the Rational, or null if not found or an exception occurs

getMetaString

protected java.lang.String getMetaString(java.lang.Class<? extends com.drew.metadata.Directory> dirClass,
                                         int tagType)
Get a metadata String value from an arbitrary EXIF directory.

Parameters:
dirClass - the class of the directory to extract from
tagType - the EXIF tag to get a String value for
Returns:
the String, or null if not found

getFocalLength35mmEquivFactor

protected float getFocalLength35mmEquivFactor()
Get a multiplication factor to convert the EXIF focal length into a 35mm equivalent length, for cameras that work this way.

This implementation returns 1, i.e. no multiplication factor. Extending classes can override this to provide a camera-specific value.

Returns:
the focalLength35mmEquivFactor