net.grelf.image
Class Metadata

java.lang.Object
  extended by net.grelf.image.Metadata

public class Metadata
extends java.lang.Object

This class manages metadata that GRIP puts into images. It is designed to be compatible with all the file formats used by GRIP: FITS for astronomical images and TIFF, PNG, JPEG (etc) via JAI Imageio. In the case of FITS the standard header fields are maintained and any other metadata loaded from a FITS file are kept in the order in which they appeared in the file so they can be resaved in the same order. In the case of TIFF, the standard TIFF plug-in in jai_imageio.jar is assumed, with package com.sun.media.imageio.plugins.tiff. The writer uses two metadata formats: its native format, called com_sun_media_imageio_plugins_tiff_image_1.0, and the standard format, javax_imageio_1.0. The package description at http://download.java.net/media/jai-imageio/javadoc/1.1/com/sun/media/imageio/plugins/tiff/package-summary.html explains that only certain elements written in the standard metadata format are added into the TIFF structure when using javax.imageio.metadata.IIOMetadata.mergeTree (). Because of that, GRIP writes and reads only the following.
the camera timestamp when the last photo was originally taken


The ImageKind content is a semicolon-separated sequence of values, of which this is an example:
GRIP combined image;32 images;First started at 2010:01:31 23:59:59;Last ended at 2010:02:01 00:10:59; Exposure 32 x 10s;ISO 3200;Aperture f/4.8;Focal length 1200mm That is separated out and displayed in image information, on GRIP's image menu.


Field Summary
static java.lang.String APERTURE_KEYWORD
           
static java.lang.String CAMERA_KEYWORD
           
static java.lang.String COPYRIGHT_KEYWORD
           
static java.lang.String EXPOSURE_KEYWORD
           
static java.lang.String FIRST_KEYWORD
           
static java.util.Map<java.lang.String,java.lang.String> FITS_KEYWORDS
           
static java.lang.String FOCAL_LENGTH_KEYWORD
           
static java.lang.String GRIP_COMBINED_IMAGE_ID
           
static java.lang.String IMAGE_KIND_KEYWORD
           
static java.lang.String ISO_KEYWORD
           
static java.lang.String LAST_KEYWORD
           
static java.lang.String METHOD_KEYWORD
           
static java.lang.String NIMAGES_KEYWORD
           
static java.lang.String OBSERVER_KEYWORD
           
 
Constructor Summary
Metadata()
          Construct an object holding no values, for the values to be added individually through addValue.
Metadata(java.util.List<FITS_KeywordRecord> list)
          Construct from a list of keywords as read from a FITS file.
Metadata(java.util.Map<java.lang.String,java.lang.String> values)
          Construct from a map using the keys defined as static _KEYWORD values in this class.
Metadata(java.lang.String value)
          Construct by parsing the value obtained from Im.getImageMetadataAsMap (), with key "ImageKind" - which may have been constructed by this class.
 
Method Summary
 void addValue(java.lang.String key, java.lang.String value)
          Only the keys defined as static _KEYWORD strings in this class are recognised by its methods.
 javax.imageio.metadata.IIOMetadataNode buildTree()
          Build a tree fragment in standard (javax_imageio_1.0) format suitable for merging into a javax.imageio.metadata.IIOMetadata object.
 void clear()
          Clear the metadata, for use when disposing an image.
 boolean contains(java.lang.String keyword)
           
 void convertImageKindString()
           
 java.lang.StringBuffer formatForDisplay()
          Assemble metadata from all known keys into lines separated by HTML <br> elements.
 float getAperture()
          Get aperture (f/) from the metadata if it is present, otherwise return 0.
 java.lang.String getCamera()
          Get camera details from the metadata if present, otherwise return empty String.
 java.lang.String getCopyright()
          Get copyright details from the metadata if present, otherwise return empty String.
 java.lang.String getDateTime()
          Get date and time taken (yyyy:mm:dd hh:mm:ss) from the metadata if it is present (with key "DateTimeOriginal"), otherwise return empty string.
 float getExposure()
          Get exposure (s) from the metadata if it is present, otherwise return 0.
 int getFocalLength()
          Get focal length (mm) from the metadata if it is present, otherwise return 0.
 int getISO()
          Get sensitivity (ISO) from the metadata if it is present, otherwise return 0.
 java.util.List<FITS_KeywordRecord> getList()
           
 java.util.Map<java.lang.String,java.lang.String> getMap()
           
 java.lang.String getPhotographer()
          Get photographer details from the metadata if present, otherwise return empty String.
 long getTimeInMillis()
          Get date and time taken, in ms since 1970.0, or 0 if "DateTimeOriginal" key was not present in the metadata or the value was invalid.
 java.lang.String getValue(java.lang.String... possibleKeys)
          For the first of the given keys found in the metadata, return the value.
 java.lang.String getValue(java.lang.String key)
          Get the value for the key, or null if the key is not found.
 void mergeIntoIIOI(javax.imageio.IIOImage iioi)
          Merge the metadata from the map into a JAI ImageIO image, if the image supports the standard format, javax_imageio_1.0.
 void remove(java.lang.String keyword)
           
 void removeTiffFields()
          It is not always appropriate to keep hold of TIFF fields which describe data layout in a file, eg when image is converted to different bit depth.
 void replaceValue(java.lang.String keyword, java.lang.String newValue)
           
 java.lang.String toFoldedString(java.lang.String lineEnd)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IMAGE_KIND_KEYWORD

public static final java.lang.String IMAGE_KIND_KEYWORD
See Also:
Constant Field Values

NIMAGES_KEYWORD

public static final java.lang.String NIMAGES_KEYWORD
See Also:
Constant Field Values

METHOD_KEYWORD

public static final java.lang.String METHOD_KEYWORD
See Also:
Constant Field Values

FIRST_KEYWORD

public static final java.lang.String FIRST_KEYWORD
See Also:
Constant Field Values

LAST_KEYWORD

public static final java.lang.String LAST_KEYWORD
See Also:
Constant Field Values

EXPOSURE_KEYWORD

public static final java.lang.String EXPOSURE_KEYWORD
See Also:
Constant Field Values

APERTURE_KEYWORD

public static final java.lang.String APERTURE_KEYWORD
See Also:
Constant Field Values

FOCAL_LENGTH_KEYWORD

public static final java.lang.String FOCAL_LENGTH_KEYWORD
See Also:
Constant Field Values

ISO_KEYWORD

public static final java.lang.String ISO_KEYWORD
See Also:
Constant Field Values

CAMERA_KEYWORD

public static final java.lang.String CAMERA_KEYWORD
See Also:
Constant Field Values

OBSERVER_KEYWORD

public static final java.lang.String OBSERVER_KEYWORD
See Also:
Constant Field Values

COPYRIGHT_KEYWORD

public static final java.lang.String COPYRIGHT_KEYWORD
See Also:
Constant Field Values

GRIP_COMBINED_IMAGE_ID

public static final java.lang.String GRIP_COMBINED_IMAGE_ID
See Also:
Constant Field Values

FITS_KEYWORDS

public static final java.util.Map<java.lang.String,java.lang.String> FITS_KEYWORDS
Constructor Detail

Metadata

public Metadata(java.util.Map<java.lang.String,java.lang.String> values)
Construct from a map using the keys defined as static _KEYWORD values in this class.


Metadata

public Metadata(java.util.List<FITS_KeywordRecord> list)
Construct from a list of keywords as read from a FITS file.


Metadata

public Metadata()
Construct an object holding no values, for the values to be added individually through addValue.


Metadata

public Metadata(java.lang.String value)
Construct by parsing the value obtained from Im.getImageMetadataAsMap (), with key "ImageKind" - which may have been constructed by this class. If that value was not constructed by this class an empty Metadata object will be constructed.

Method Detail

getMap

public java.util.Map<java.lang.String,java.lang.String> getMap()

getList

public java.util.List<FITS_KeywordRecord> getList()

convertImageKindString

public void convertImageKindString()

addValue

public void addValue(java.lang.String key,
                     java.lang.String value)
Only the keys defined as static _KEYWORD strings in this class are recognised by its methods.


contains

public boolean contains(java.lang.String keyword)

clear

public void clear()
Clear the metadata, for use when disposing an image.


getValue

public java.lang.String getValue(java.lang.String key)
Get the value for the key, or null if the key is not found.


getValue

public java.lang.String getValue(java.lang.String... possibleKeys)
For the first of the given keys found in the metadata, return the value. Otherwise return an empty String (rather than null).


getAperture

public float getAperture()
Get aperture (f/) from the metadata if it is present, otherwise return 0.


getCamera

public java.lang.String getCamera()
Get camera details from the metadata if present, otherwise return empty String.


getCopyright

public java.lang.String getCopyright()
Get copyright details from the metadata if present, otherwise return empty String.


getExposure

public float getExposure()
Get exposure (s) from the metadata if it is present, otherwise return 0.


getFocalLength

public int getFocalLength()
Get focal length (mm) from the metadata if it is present, otherwise return 0.


getISO

public int getISO()
Get sensitivity (ISO) from the metadata if it is present, otherwise return 0.


getPhotographer

public java.lang.String getPhotographer()
Get photographer details from the metadata if present, otherwise return empty String.


getDateTime

public java.lang.String getDateTime()
Get date and time taken (yyyy:mm:dd hh:mm:ss) from the metadata if it is present (with key "DateTimeOriginal"), otherwise return empty string.


getTimeInMillis

public long getTimeInMillis()
Get date and time taken, in ms since 1970.0, or 0 if "DateTimeOriginal" key was not present in the metadata or the value was invalid. Reasons for returning 0 are logged as warnings.


buildTree

public javax.imageio.metadata.IIOMetadataNode buildTree()
Build a tree fragment in standard (javax_imageio_1.0) format suitable for merging into a javax.imageio.metadata.IIOMetadata object.


formatForDisplay

public java.lang.StringBuffer formatForDisplay()
Assemble metadata from all known keys into lines separated by HTML <br> elements.


mergeIntoIIOI

public void mergeIntoIIOI(javax.imageio.IIOImage iioi)
Merge the metadata from the map into a JAI ImageIO image, if the image supports the standard format, javax_imageio_1.0. This is particularly useful at the end of the batch astro-process for putting combined metadata into the new accumulator image. The metadata then consist of camera/telescope settings and calculated creation and exposure times from the original sequence of images.


remove

public void remove(java.lang.String keyword)

removeTiffFields

public void removeTiffFields()
It is not always appropriate to keep hold of TIFF fields which describe data layout in a file, eg when image is converted to different bit depth.


replaceValue

public void replaceValue(java.lang.String keyword,
                         java.lang.String newValue)

toFoldedString

public java.lang.String toFoldedString(java.lang.String lineEnd)