it.geosolutions.imageio.utilities
Class ImageIOUtilities

Object
  extended by ImageIOUtilities

public class ImageIOUtilities
extends Object

Simple class containing commonly used utility methods.


Method Summary
static String adjustAttributeName(String attributeName)
           
static void checkNotNull(Object checkMe, String message)
           
static ColorModel createColorModel(SampleModel sampleModel)
          Creates a ColorModel that may be used with the specified SampleModel.
static void displayImageIOMetadata(Node root)
          Given a root node, print the values/attributes tree using the System Out
static boolean equals(Object object1, Object object2)
          Convenience method for testing two objects for equality.
static List<ImageReaderWriterSpi> getJDKImageReaderWriterSPI(ServiceRegistry registry, String formatName, boolean isReader)
           
static String getShortClassName(Object object)
          Returns a short class name for the specified object.
static String getShortName(Class<?> classe)
          Returns a short class name for the specified class.
static int getSubSamplingFactor2(int xSubsamplingFactor, int ySubsamplingFactor)
          Given a pair of xSubsamplingFactor (xSSF) and ySubsamplingFactor (ySFF), look for a subsampling factor (SSF) in case xSSF !
static boolean replaceProvider(Class<? extends ImageReaderWriterSpi> providerClass, String customProviderName, String originalProviderName, String format)
          Replace the original provider with name originalProviderName with the provider with name customProviderName for the class providerClass and for the provided format .
static boolean sameInterfaces(Class<?> object1, Class<?> object2, Class<?> base)
          Returns true if the two specified objects implements exactly the same set of interfaces.
static void setNativeAccelerationAllowed(String operation, boolean allowed)
          Allows or disallow native acceleration for the specified operation on the default JAI instance.
static void setNativeAccelerationAllowed(String operation, boolean allowed, JAI jai)
          Allows or disallow native acceleration for the specified operation on the given JAI instance.
static String spaces(int length)
          Returns a string of the specified length filled with white spaces.
static File urlToFile(URL url)
          Takes a URL and converts it to a File.
static void visualize(RenderedImage ri)
          base method used to simply visualize RenderedImage without further information
static void visualize(RenderedImage ri, String title)
          base method used to simply visualize RenderedImage
static void visualize(RenderedImage ri, String title, boolean rescale)
          base method used to visualize RenderedImage by specifying the frame title as well as the request for rescaling.
static void visualize(RenderedImage ri, String title, boolean rescale, int roiThreshold)
          base method used to visualize RenderedImage by specifying the frame title as well as the request for rescaling.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createColorModel

public static final ColorModel createColorModel(SampleModel sampleModel)
Creates a ColorModel that may be used with the specified SampleModel. If a suitable ColorModel cannot be found, this method returns null.

Suitable ColorModels are guaranteed to exist for all instances of ComponentSampleModel. For 1- and 3- banded SampleModels, the returned ColorModel will be opaque. For 2- and 4-banded SampleModels, the output will use alpha transparency which is not premultiplied. 1- and 2-banded data will use a grayscale ColorSpace, and 3- and 4-banded data a sRGB ColorSpace. Data with 5 or more bands will have a BogusColorSpace.

An instance of DirectColorModel will be created for instances of SinglePixelPackedSampleModel with no more than 4 bands.

An instance of IndexColorModel will be created for instances of MultiPixelPackedSampleModel. The colormap will be a grayscale ramp with 1 << numberOfBits entries ranging from zero to at most 255.

Returns:
An instance of ColorModel that is suitable for the supplied SampleModel, or null.
Throws:
IllegalArgumentException - If sampleModel is null.

displayImageIOMetadata

public static void displayImageIOMetadata(Node root)
Given a root node, print the values/attributes tree using the System Out

Parameters:
root - the root node to be printed.
TODO:
change it using Logger

visualize

public static void visualize(RenderedImage ri)
base method used to simply visualize RenderedImage without further information

Parameters:
ri - RenderedImage to visualize

visualize

public static void visualize(RenderedImage ri,
                             String title)
base method used to simply visualize RenderedImage

Parameters:
ri - RenderedImage to visualize
title - title for the frame (usually the image filename)

visualize

public static void visualize(RenderedImage ri,
                             String title,
                             boolean rescale)
base method used to visualize RenderedImage by specifying the frame title as well as the request for rescaling.

Parameters:
ri - RenderedImage to visualize
title - title for the frame (usually the image filename)
rescale - if true the RenderedImage will be rescaled using a default value for the ROI.

visualize

public static void visualize(RenderedImage ri,
                             String title,
                             boolean rescale,
                             int roiThreshold)
base method used to visualize RenderedImage by specifying the frame title as well as the request for rescaling.

Parameters:
ri - RenderedImage to visualize
title - title for the frame (usually the image filename)
rescale - if true the RenderedImage will be rescaled using a default value for the ROI.
roiThreshold - the threshold for the inner ROI. It represent the minimum value of the pixels representing the region of interest.

getJDKImageReaderWriterSPI

public static List<ImageReaderWriterSpi> getJDKImageReaderWriterSPI(ServiceRegistry registry,
                                                                    String formatName,
                                                                    boolean isReader)

replaceProvider

public static boolean replaceProvider(Class<? extends ImageReaderWriterSpi> providerClass,
                                      String customProviderName,
                                      String originalProviderName,
                                      String format)
Replace the original provider with name originalProviderName with the provider with name customProviderName for the class providerClass and for the provided format .

Parameters:
providerClass - the Class for the providers.
customProviderName - the name of the provider we want to use as new preferred provider.
originalProviderName - the name of the provider we want to deregister.
format - the format for this provi
Returns:
true if we find both of the providers and the replacement succeed, false otherwise.

equals

public static boolean equals(Object object1,
                             Object object2)
Convenience method for testing two objects for equality. One or both objects may be null.


sameInterfaces

public static boolean sameInterfaces(Class<?> object1,
                                     Class<?> object2,
                                     Class<?> base)
Returns true if the two specified objects implements exactly the same set of interfaces. Only interfaces assignable to base are compared. Declaration order doesn't matter. For example in ISO 19111, different interfaces exist for different coordinate system geometries (CartesianCS, PolarCS, etc.).


spaces

public static String spaces(int length)
Returns a string of the specified length filled with white spaces. This method tries to return a pre-allocated string if possible.

Parameters:
length - The string length. Negative values are clamped to 0.
Returns:
A string of length length filled with white spaces.

getShortName

public static String getShortName(Class<?> classe)
Returns a short class name for the specified class. This method will omit the package name. For example, it will return "String" instead of "java.lang.String" for a String object. It will also name array according Java language usage, for example "double[]" instead of "[D".

Parameters:
classe - The object class (may be null).
Returns:
A short class name for the specified object.

urlToFile

public static File urlToFile(URL url)
Takes a URL and converts it to a File. The attempts to deal with Windows UNC format specific problems, specifically files located on network shares and different drives. If the URL.getAuthority() returns null or is empty, then only the url's path property is used to construct the file. Otherwise, the authority is prefixed before the path. It is assumed that url.getProtocol returns "file". Authority is the drive or network share the file is located on. Such as "C:", "E:", "\\fooServer"

Parameters:
url - a URL object that uses protocol "file"
Returns:
a File that corresponds to the URL's location

getSubSamplingFactor2

public static int getSubSamplingFactor2(int xSubsamplingFactor,
                                        int ySubsamplingFactor)
Given a pair of xSubsamplingFactor (xSSF) and ySubsamplingFactor (ySFF), look for a subsampling factor (SSF) in case xSSF != ySSF or they are not powers of 2. In case xSSF == ySSF == 2^N, the method return 0 (No optimal subsampling factor found).

Parameters:
xSubsamplingFactor -
ySubsamplingFactor -
Returns:

getShortClassName

public static String getShortClassName(Object object)
Returns a short class name for the specified object. This method will omit the package name. For example, it will return "String" instead of "java.lang.String" for a String object.

Parameters:
object - The object (may be null).
Returns:
A short class name for the specified object.

adjustAttributeName

public static String adjustAttributeName(String attributeName)

setNativeAccelerationAllowed

public static void setNativeAccelerationAllowed(String operation,
                                                boolean allowed,
                                                JAI jai)
Allows or disallow native acceleration for the specified operation on the given JAI instance. By default, JAI uses hardware accelerated methods when available. For example, it make use of MMX instructions on Intel processors. Unluckily, some native method crash the Java Virtual Machine under some circumstances. For example on JAI 1.1.2, the "Affine" operation on an image with float data type, bilinear interpolation and an ImageLayout rendering hint cause an exception in medialib native code. Disabling the native acceleration (i.e using the pure Java version) is a convenient workaround until Sun fix the bug.

Implementation note: the current implementation assumes that factories for native implementations are declared in the com.sun.media.jai.mlib package, while factories for pure java implementations are declared in the com.sun.media.jai.opimage package. It work for Sun's 1.1.2 implementation, but may change in future versions. If this method doesn't recognize the package, it does nothing.

Parameters:
operation - The operation name (e.g. "Affine").
allowed - false to disallow native acceleration.
jai - The instance of JAI we are going to work on. This argument can be omitted for the default JAI instance.
See Also:
JAI bug report 4906854

setNativeAccelerationAllowed

public static void setNativeAccelerationAllowed(String operation,
                                                boolean allowed)
Allows or disallow native acceleration for the specified operation on the default JAI instance. This method is a shortcut for setNativeAccelerationAllowed(operation, allowed, JAI.getDefaultInstance()).

See Also:
setNativeAccelerationAllowed(String, boolean, JAI)

checkNotNull

public static final void checkNotNull(Object checkMe,
                                      String message)


Copyright © 2006-2010 GeoSolutions. All Rights Reserved.