package org.jboss.media.format.image.iio;
import javax.imageio.metadata.IIOMetadata;
import org.w3c.dom.Node;
public class StandardMediaHeader extends IIOMediaHeader
{
private static final long serialVersionUID = 0L;
private static final String STANDARD_METADATA_FORMAT_NAME =
"javax_imageio_1.0";
private static final String[] FIELD_NAMES =
{
"colorSpaceType",
"numChannels",
"gamma",
"blackIsZero",
"compressionTypeName",
"lossless",
"numProgressiveScans",
"bitRate",
"planarConfiguration",
"sampleFormat",
"bitsPerSample",
"significantBitsPerSample",
"sampleMSB",
"pixelAspectRatio",
"imageOrientation",
"horizontalPixelSize",
"verticalPixelSize",
"horizontalPhysicalPixelSpacing",
"verticalPhysicalPixelSpacing",
"horizontalPosition",
"verticalPosition",
"horizontalPixelOffset",
"verticalPixelOffset",
"horizontalScreenSize",
"verticalScreenSize",
"formatVersion",
"subimageInterpretation",
"imageCreationYear" };
public StandardMediaHeader(IIOMetadata imageMetadata)
{
super(imageMetadata, STANDARD_METADATA_FORMAT_NAME);
}
public String[] getFieldNames()
{
return FIELD_NAMES;
}
public Object getField(String fieldname)
{
Object field = null;
if (fieldname.equals("colorSpaceType"))
{
field = getColorSpaceType();
}
if (fieldname.equals("numChannels"))
{
field = getNumChannels();
}
if (fieldname.equals("gamma"))
{
field = new Float(getGamma());
}
if (fieldname.equals("blackIsZero"))
{
field = getBlackIsZero();
}
if (fieldname.equals("compressionTypeName"))
{
field = getCompressionTypeName();
}
if (fieldname.equals("lossless"))
{
field = getLossless();
}
if (fieldname.equals("numProgressiveScans"))
{
field = new Integer(getNumProgressiveScans());
}
if (fieldname.equals("bitRate"))
{
field = new Float(getBitRate());
}
if (fieldname.equals("planarConfiguration"))
{
field = getPlanarConfiguration();
}
if (fieldname.equals("sampleFormat"))
{
field = getSampleFormat();
}
if (fieldname.equals("bitsPerSample"))
{
field = getBitsPerSample();
}
if (fieldname.equals("significantBitsPerSample"))
{
field = getSignificantBitsPerSample();
}
if (fieldname.equals("sampleMSB"))
{
field = getSampleMSB();
}
if (fieldname.equals("pixelAspectRatio"))
{
field = new Float(getPixelAspectRatio());
}
if (fieldname.equals("imageOrientation"))
{
field = getImageOrientation();
}
if (fieldname.equals("horizontalPixelSize"))
{
field = new Float(getHorizontalPixelSize());
}
if (fieldname.equals("verticalPixelSize"))
{
field = new Float(getVerticalPixelSize());
}
if (fieldname.equals("horizontalPhysicalPixelSpacing"))
{
field = new Float(getHorizontalPhysicalPixelSpacing());
}
if (fieldname.equals("verticalPhysicalPixelSpacing"))
{
field = new Float(getVerticalPhysicalPixelSpacing());
}
if (fieldname.equals("horizontalPosition"))
{
field = new Float(getHorizontalPosition());
}
if (fieldname.equals("verticalPosition"))
{
field = new Float(getVerticalPosition());
}
if (fieldname.equals("horizontalPixelOffset"))
{
field = new Integer(getHorizontalPixelOffset());
}
if (fieldname.equals("verticalPixelOffset"))
{
field = new Integer(getVerticalPixelOffset());
}
if (fieldname.equals("horizontalScreenSize"))
{
field = new Integer(getHorizontalScreenSize());
}
if (fieldname.equals("verticalScreenSize"))
{
field = new Integer(getVerticalScreenSize());
}
if (fieldname.equals("formatVersion"))
{
field = getFormatVersion();
}
if (fieldname.equals("subimageInterpretation"))
{
field = getSubimageInterpretation();
}
if (fieldname.equals("imageCreationYear"))
{
field = new Integer(getImageCreationYear());
}
return field;
}
public String getColorSpaceType()
{
Node chroma = getChromaNode();
Node colorSpaceType = getNode(chroma, "ColorSpaceType");
return getAttribute(colorSpaceType, "name");
}
public String getNumChannels()
{
Node chroma = getChromaNode();
Node numChannels = getNode(chroma, "NumChannels");
return getAttribute(numChannels, "value");
}
public float getGamma()
{
Node chroma = getChromaNode();
Node gamma = getNode(chroma, "Gamma");
String value = getAttribute(gamma, "value");
return Float.parseFloat(value);
}
public String getBlackIsZero()
{
Node chroma = getChromaNode();
Node blackIsZero = getNode(chroma, "BlackIsZero");
return getAttribute(blackIsZero, "value");
}
public String getCompressionTypeName()
{
Node compression = getCompressionNode();
Node compressionTypeName = getNode(compression, "CompressionTypeName");
return getAttribute(compressionTypeName, "value");
}
public String getLossless()
{
Node compression = getCompressionNode();
Node lossless = getNode(compression, "Lossless");
return getAttribute(lossless, "value");
}
public int getNumProgressiveScans()
{
Node compression = getCompressionNode();
Node numProgressiveScans = getNode(compression, "NumProgressiveScans");
String value = getAttribute(numProgressiveScans, "value");
return Integer.parseInt(value);
}
public float getBitRate()
{
Node compression = getCompressionNode();
Node bitRate = getNode(compression, "BitRate");
String value = getAttribute(bitRate, "value");
return value == null ? 0 : Float.parseFloat(value);
}
public String getPlanarConfiguration()
{
Node data = getDataNode();
Node planarConfiguration = getNode(data, "PlanarConfiguration");
return getAttribute(planarConfiguration, "value");
}
public String getSampleFormat()
{
Node data = getDataNode();
Node sampleFormat = getNode(data, "SampleFormat");
return getAttribute(sampleFormat, "value");
}
public String getBitsPerSample()
{
Node data = getDataNode();
Node bitsPerSample = getNode(data, "BitsPerSample");
return getAttribute(bitsPerSample, "value");
}
public String getSignificantBitsPerSample()
{
Node data = getDataNode();
Node significantBitsPerSample = getNode(data, "SignificantBitsPerSample");
return getAttribute(significantBitsPerSample, "value");
}
public String getSampleMSB()
{
Node data = getDataNode();
Node sampleMSB = getNode(data, "SampleMSB");
return getAttribute(sampleMSB, "value");
}
public float getPixelAspectRatio()
{
Node dimension = getDimensionNode();
Node pixelAspectRatio = getNode(dimension, "PixelAspectRatio");
String value = getAttribute(pixelAspectRatio, "value");
return Float.parseFloat(value);
}
public String getImageOrientation()
{
Node dimension = getDimensionNode();
Node imageOrientation = getNode(dimension, "ImageOrientation");
return getAttribute(imageOrientation, "value");
}
public float getHorizontalPixelSize()
{
Node dimension = getDimensionNode();
Node horizontalPixelSize = getNode(dimension, "HorizontalPixelSize");
String value = getAttribute(horizontalPixelSize, "value");
return Float.parseFloat(value);
}
public float getVerticalPixelSize()
{
Node dimension = getDimensionNode();
Node verticalPixelSize = getNode(dimension, "VerticalPixelSize");
String value = getAttribute(verticalPixelSize, "value");
return Float.parseFloat(value);
}
public float getHorizontalPhysicalPixelSpacing()
{
Node dimension = getDimensionNode();
Node horizontalPhysicalPixelSpacing =
getNode(dimension, "HorizontalPhysicalPixelSpacing");
String value = getAttribute(horizontalPhysicalPixelSpacing, "value");
return value == null ? 0 : Float.parseFloat(value);
}
public float getVerticalPhysicalPixelSpacing()
{
Node dimension = getDimensionNode();
Node verticalPhysicalPixelSpacing =
getNode(dimension, "VerticalPhysicalPixelSpacing");
String value = getAttribute(verticalPhysicalPixelSpacing, "value");
return value == null ? 0 : Float.parseFloat(value);
}
public float getHorizontalPosition()
{
Node dimension = getDimensionNode();
Node horizontalPosition = getNode(dimension, "HorizontalPosition");
String value = getAttribute(horizontalPosition, "value");
return value == null ? 0 : Float.parseFloat(value);
}
public float getVerticalPosition()
{
Node dimension = getDimensionNode();
Node verticalPosition = getNode(dimension, "VerticalPosition");
String value = getAttribute(verticalPosition, "value");
return value == null ? 0 : Float.parseFloat(value);
}
public int getHorizontalPixelOffset()
{
Node dimension = getDimensionNode();
Node horizontalPixelOffset = getNode(dimension, "HorizontalPixelOffset");
String value = getAttribute(horizontalPixelOffset, "value");
return value == null ? 0 : Integer.parseInt(value);
}
public int getVerticalPixelOffset()
{
Node dimension = getDimensionNode();
Node verticalPixelOffset = getNode(dimension, "VerticalPixelOffset");
String value = getAttribute(verticalPixelOffset, "value");
return value == null ? 0 : Integer.parseInt(value);
}
public int getHorizontalScreenSize()
{
Node dimension = getDimensionNode();
Node horizontalScreenSize = getNode(dimension, "HorizontalScreenSize");
String value = getAttribute(horizontalScreenSize, "value");
return value == null ? 0 : Integer.parseInt(value);
}
public int getVerticalScreenSize()
{
Node dimension = getDimensionNode();
Node verticalScreenSize = getNode(dimension, "VerticalScreenSize");
String value = getAttribute(verticalScreenSize, "value");
return value == null ? 0 : Integer.parseInt(value);
}
public String getFormatVersion()
{
Node document = getDocumentNode();
Node formatVersion = getNode(document, "FormatVersion");
return getAttribute(formatVersion, "value");
}
public String getSubimageInterpretation()
{
Node document = getDocumentNode();
Node subimageInterpretation = getNode(document, "SubimageInterpretation");
return getAttribute(subimageInterpretation, "value");
}
public int getImageCreationYear()
{
Node document = getDocumentNode();
Node formatVersion = getNode(document, "ImageCreationTime");
String value = getAttribute(formatVersion, "year");
return value == null ? 0 : Integer.parseInt(value);
}
private Node getChromaNode()
{
return getNode("Chroma");
}
private Node getCompressionNode()
{
return getNode("Compression");
}
private Node getDataNode()
{
return getNode("Data");
}
private Node getDimensionNode()
{
return getNode("Dimension");
}
private Node getDocumentNode()
{
return getNode("Document");
}
}