org.geotools.resources.image
Class ImageUtilities

java.lang.Object
  extended by org.geotools.resources.image.ImageUtilities

public final class ImageUtilities
extends java.lang.Object

A set of static methods working on images. Some of those methods are useful, but not really rigorous. This is why they do not appear in any "official" package, but instead in this private one. Do not rely on this API! It may change in incompatible way in any future version.

Since:
2.0
Version:
$Id: ImageUtilities.java 34823 2010-01-19 18:47:51Z danieleromagnoli $
Author:
Martin Desruisseaux (IRD), Simone Giannecchini

Field Summary
static java.awt.RenderingHints DONT_REPLACE_INDEX_COLOR_MODEL
          RenderingHints used to prevent JAI operations from expanding IndexColorModels.
static java.awt.RenderingHints EXTEND_BORDER_BY_COPYING
          Cached instance of a RenderingHints for controlling border extension on JAI operations.
static java.awt.RenderingHints EXTEND_BORDER_BY_REFLECT
          Cached instance of a RenderingHints for controlling border extension on JAI operations.
static java.awt.RenderingHints NN_INTERPOLATION_HINT
          RenderingHints for requesting Nearest Neighbor intepolation.
static java.awt.RenderingHints NOCACHE_HINT
          RenderingHints for avoiding caching of JAI RenderedOps.
static java.awt.RenderingHints REPLACE_INDEX_COLOR_MODEL
          RenderingHints used to force JAI operations to expand IndexColorModels.
 
Method Summary
static
<T extends javax.imageio.spi.ImageReaderWriterSpi>
void
allowNativeCodec(java.lang.String format, java.lang.Class<T> category, boolean allowed)
          Allows or disallows native acceleration for the specified image format.
static javax.media.jai.ImageLayout createIntersection(javax.media.jai.ImageLayout layout, java.util.List<java.awt.image.RenderedImage> sources)
          Computes a new ImageLayout which is the intersection of the specified ImageLayout and all RenderedImages in the supplied list.
static void fill(java.awt.image.WritableRenderedImage image, java.lang.Number value)
          Sets every samples in the given image to the given value.
static javax.media.jai.ImageLayout getImageLayout(java.awt.image.RenderedImage image)
          Suggests an ImageLayout for the specified image.
static java.lang.String getInterpolationName(javax.media.jai.Interpolation interp)
          Returns the interpolation name for the specified interpolation object.
static java.awt.RenderingHints getRenderingHints(java.awt.image.RenderedImage image)
          Suggests a set of RenderingHints for the specified image.
static boolean isCLibAvailable()
          Tells me whether or not the native libraries for JAI/ImageIO are active or not.
static boolean isMediaLibAvailable()
          Tells me whether or not the native libraries for JAI are active or not.
static javax.media.jai.RenderedOp tileImage(javax.media.jai.RenderedOp image)
          Tiles the specified image.
static javax.media.jai.Interpolation toInterpolation(java.lang.Object type)
          Casts the specified object to an object.
static java.awt.Dimension toTileSize(java.awt.Dimension size)
          Suggests a tile size for the specified image size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DONT_REPLACE_INDEX_COLOR_MODEL

public static final java.awt.RenderingHints DONT_REPLACE_INDEX_COLOR_MODEL
RenderingHints used to prevent JAI operations from expanding IndexColorModels.


REPLACE_INDEX_COLOR_MODEL

public static final java.awt.RenderingHints REPLACE_INDEX_COLOR_MODEL
RenderingHints used to force JAI operations to expand IndexColorModels.


NN_INTERPOLATION_HINT

public static final java.awt.RenderingHints NN_INTERPOLATION_HINT
RenderingHints for requesting Nearest Neighbor intepolation.


NOCACHE_HINT

public static final java.awt.RenderingHints NOCACHE_HINT
RenderingHints for avoiding caching of JAI RenderedOps.


EXTEND_BORDER_BY_COPYING

public static final java.awt.RenderingHints EXTEND_BORDER_BY_COPYING
Cached instance of a RenderingHints for controlling border extension on JAI operations. It contains an instance of a BorderExtenderCopy.


EXTEND_BORDER_BY_REFLECT

public static final java.awt.RenderingHints EXTEND_BORDER_BY_REFLECT
Cached instance of a RenderingHints for controlling border extension on JAI operations. It contains an instance of a BorderExtenderReflect.

Method Detail

getImageLayout

public static javax.media.jai.ImageLayout getImageLayout(java.awt.image.RenderedImage image)
Suggests an ImageLayout for the specified image. All parameters are initially set equal to those of the given RenderedImage, and then the tile size is updated according the image size. This method never returns null.


getRenderingHints

public static java.awt.RenderingHints getRenderingHints(java.awt.image.RenderedImage image)
Suggests a set of RenderingHints for the specified image. The rendering hints may include the following parameters: This method may returns null if no rendering hints is proposed.


toTileSize

public static java.awt.Dimension toTileSize(java.awt.Dimension size)
Suggests a tile size for the specified image size. On input, size is the image's size. On output, it is the tile size. This method write the result directly in the supplied object and returns size for convenience.

This method it aimed to computing a tile size such that the tile grid would have overlapped the image bound in order to avoid having tiles crossing the image bounds and being therefore partially empty. This method will never returns a tile size smaller than . If this method can't suggest a size, then it left the corresponding size field (width or height) unchanged.

The width and height fields are processed independently in the same way. The following discussion use the width field as an example.

This method inspects different tile sizes close to the default tile size. Lets width be the default tile width. Values are tried in the following order: width, width+1, width-1, width+2, width-2, width+3, width-3, etc. until one of the following happen:


createIntersection

public static javax.media.jai.ImageLayout createIntersection(javax.media.jai.ImageLayout layout,
                                                             java.util.List<java.awt.image.RenderedImage> sources)
Computes a new ImageLayout which is the intersection of the specified ImageLayout and all RenderedImages in the supplied list. If the minX, minY, width and height properties are not defined in the layout, then they will be inherited from the first source for consistency with OpImage constructor.

Parameters:
layout - The original layout. This object will not be modified.
sources - The list of sources RenderedImage.
Returns:
A new ImageLayout, or the original layout if no change was needed.

toInterpolation

public static javax.media.jai.Interpolation toInterpolation(java.lang.Object type)
                                                     throws java.lang.IllegalArgumentException
Casts the specified object to an object.

Parameters:
type - The interpolation type as an Interpolation or a CharSequence object.
Returns:
The interpolation object for the specified type.
Throws:
java.lang.IllegalArgumentException - if the specified interpolation type is not a know one.

getInterpolationName

public static java.lang.String getInterpolationName(javax.media.jai.Interpolation interp)
Returns the interpolation name for the specified interpolation object. This method tries to infer the name from the object's class name.

Parameters:
Interpolation - The interpolation object, or null for "nearest" (which is an other way to say "no interpolation").

allowNativeCodec

public static <T extends javax.imageio.spi.ImageReaderWriterSpi> void allowNativeCodec(java.lang.String format,
                                                                                       java.lang.Class<T> category,
                                                                                       boolean allowed)
Allows or disallows native acceleration for the specified image format. By default, the image I/O extension for JAI provides native acceleration for PNG and JPEG. Unfortunatly, those native codec has bug in their 1.0 version. Invoking this method will force the use of standard codec provided in J2SE 1.4.

Implementation note: the current implementation assume that JAI codec class name start with "CLib". It work for Sun's 1.0 implementation, but may change in future versions. If this method doesn't recognize the class name, it does nothing.

Parameters:
format - The format name (e.g. "png").
category - ImageReaderSpi.class to set the reader, or ImageWriterSpi.class to set the writer.
allowed - false to disallow native acceleration.

tileImage

public static javax.media.jai.RenderedOp tileImage(javax.media.jai.RenderedOp image)
                                            throws java.io.IOException
Tiles the specified image.

Throws:
java.io.IOException - If an I/O operation were required (in order to check if the image were tiled on disk) and failed.
Since:
2.3

fill

public static void fill(java.awt.image.WritableRenderedImage image,
                        java.lang.Number value)
Sets every samples in the given image to the given value. This method is typically used for clearing an image content.

Parameters:
image - The image to fill.
value - The value to to given to every samples.

isMediaLibAvailable

public static boolean isMediaLibAvailable()
Tells me whether or not the native libraries for JAI are active or not.

Returns:
false in case the JAI native libs are not in the path, true otherwise.

isCLibAvailable

public static boolean isCLibAvailable()
Tells me whether or not the native libraries for JAI/ImageIO are active or not.

Returns:
false in case the JAI/ImageIO native libs are not in the path, true otherwise.


Copyright © 1996-2010 Geotools. All Rights Reserved.