Metadata

Corresponding to an image is a set of non-pixel data that represents properties of that image. Some examples are width, height, color table, color space, and so on. Although there are ImageReader methods for obtaining the image width and height(such as getWidth and getHeight), it is not possible to provide a separate method for each piece of metadata that could be contained in an image format. Instead, the ImageReader class provides the metadata information collectively using the following two methods:

IIOMetadata getImageMetadata(int imageIndex)

and

IIOMetadata getStreamMetadata()

The first method provides the metadata for the image specified by the index imageIndex, while the second method provides the metadata that is descriptive of all images contained in a single stream. For example, a single file could hold any number of images that all share a common color table. In this situation, the color table could be described by the stream metadata. Another example is the ch5 format that we are using in this chapter. The number of images is part of the stream metadata and the width and height measures are part of each image's metadata.

XML and XML APIs

Extensible Markup Language (XML) is a language for creating and using markup languages for data storage and organization. The different data elements are delimited through the use of tags. The exact tags are not predefined in XML, but are instead defined by the implementer using XML. For example, the following XML code describes an example of the image metadata for the ch5 format that we've been using in this chapter. This code block shows two elements, ch5.imageio.ch5image_1.00 and imageDimensions with the imageDimensions element containing attributes of imageWidth and imageHeight.

<ch5.imageio.ch5image_1.00>
    <imageDimensions imageWidth=256 imageHeight=256>
    </imageDimensions>
</ch5.imageio.chstream_1.00>

Within a single XML document, there is one main element in which all other elements are contained. Thus, this main element can be considered a parent element to all other elements within the document. Similarly, each of the elements within an XML file might be considered a parent to any elements they contain as well as to any of their attributes. Using this line of reasoning, it can be useful to consider the XML document as a tree with the main element being the root node of the tree.

There are two main ways for working with XML documents in Java. The first way is through a Simple Parser for XML (SAXP) that treats the XML document like a serial stream of data. This parser generates events whenever anything interesting occurs while a data stream is being parsed. When working with a SAXP parser, you must implement methods to handle the events as they arise. The advantages of using SAXP parsers is that they're fast and they don't require much memory, because they do not store the parsed elements. The second method for working with XML documents is with a Document Object Model (DOM) that stores the entire XML document in a tree format. Instead of generating events, it simply gives an application access to this DOM tree. It's important to note that the DOM tree nodes do not simply contain the elements and attributes, but objects representing elements and attributes. Thus, each of the DOM nodes contain functionality for manipulating this tree. Besides element and attribute node types, there are also node types for document, document type, processing instruction, entity, and so on.

IIOMetadata

javax.imageio.metadata.IIOMetadata classes are used to represent metadata while also providing the capability to access this information as a tree of javax.imageio.metadata.IIOMetadataNode objects. The IIOMetadataNode class implements the Java DOM Element interface (which extends the DOM Node interface) so that one can treat stream and image metadata using the XML DOM API. For example, to convert a IIOMetadata object into a DOM tree, simply use the following method:

public org.w3c.dom.Node getAsTree(String formatName)

where formatName is the desired metadata format.

When designing IIOMetadata classes, designers can create stream and image metadata classes any way they like, although generally the closer a metadata format follows a particular image format, the less able it is to describe any other image formats. Often, there are tradeoffs when designing a metadata format between the number of image formats that it can be used for, and how much information each of these applicable image formats will lose when using this format.

Tip

There is one plug-in–neutral metadata format already defined, and it is called com.sun.imageio_1.0. All image formats can be expressed using this format, but many will contain some information that this format cannot express and will be lost. This format has child nodes for chroma, compression, dimension, document, text, tile, and transparency.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset