org.geotools.image.io
Class SampleConverter

java.lang.Object
  extended by org.geotools.image.io.SampleConverter

public abstract class SampleConverter
extends java.lang.Object

Converts samples from the values stored in the image file to the values stored in the raster. Some typical conversions are:

Note that pad values are replaced by 0 in the integer case, not by an arbitrary number, because 0 is the result of (int) NaN cast. While not mandatory, this property make some mathematics faster during conversions between geophysics and display views in the coverage module.

There is no scaling because this class is not for samples to geophysics values conversions (except the replacement of pad values by NaN). This class is about the minimal changes needed in order to comply to the contraints of a target color model, e.g. for working around negative numbers. Sample converters work on int, float or double primitive types, which match the primitive types expected by the Raster API.

Since:
2.4
Version:
$Id: SampleConverter.java 30679 2008-06-13 10:19:41Z acuster $
Author:
Martin Desruisseaux

Field Summary
static SampleConverter IDENTITY
          A sample converter that do not performs any conversion.
 
Constructor Summary
protected SampleConverter()
          Constructs a sample converter.
 
Method Summary
abstract  double convert(double value)
          Converts a double-precision value before to store it in the raster.
abstract  float convert(float value)
          Converts a float-precision value before to store it in the raster.
abstract  int convert(int value)
          Converts a float-precision value before to store it in the raster.
static SampleConverter createOffset(double offset, double padValue)
          Creates a sample converter that replaces a pad value by NaN or 0, and applies an offset on all other values.
static SampleConverter createOffset(double offset, double[] padValues)
          Creates a sample converter that replaces an arbitrary amount of pad values by NaN or 0, and applies an offset on all other values.
static SampleConverter createPadValueMask(double padValue)
          Creates a sample converter that replaces a single pad value by NaN for floating point numbers, or 0 for integers.
static SampleConverter createPadValuesMask(double[] padValues)
          Creates a sample converter that replaces an arbitrary amount of pad values by NaN for floating point numbers, or 0 for integers.
 double getOffset()
          If this converter applies an offset, returns the offset.
 java.lang.String toString()
          Returns a string representation of this sample converter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

IDENTITY

public static final SampleConverter IDENTITY
A sample converter that do not performs any conversion.

Constructor Detail

SampleConverter

protected SampleConverter()
Constructs a sample converter.

Method Detail

createPadValueMask

public static SampleConverter createPadValueMask(double padValue)
Creates a sample converter that replaces a single pad value by NaN for floating point numbers, or 0 for integers.

Parameters:
padValue - The pad values to replace by NaN or 0.

createPadValuesMask

public static SampleConverter createPadValuesMask(double[] padValues)
Creates a sample converter that replaces an arbitrary amount of pad values by NaN for floating point numbers, or 0 for integers.

Parameters:
padValue - The pad values to replace by NaN or 0, or null if none.

createOffset

public static SampleConverter createOffset(double offset,
                                           double padValue)
Creates a sample converter that replaces a pad value by NaN or 0, and applies an offset on all other values. This is typically used in order to shift a range of arbitrary (including negative) integer values to a range of strictly positive values. The later is more manageable by index color model.

Parameters:
An - offset to add to the values to be read, before to store them in the raster. This is used primarily for transforming signed short into unsigned short.
padValue - The pad value to replace. This the value before the offset is applied.

createOffset

public static SampleConverter createOffset(double offset,
                                           double[] padValues)
Creates a sample converter that replaces an arbitrary amount of pad values by NaN or 0, and applies an offset on all other values.

Parameters:
An - offset to add to the values to be read, before to store them in the raster.
padValue - The pad values to replace. They the values before the offset is applied.

convert

public abstract double convert(double value)
Converts a double-precision value before to store it in the raster. Subclasses should override this method if some fixed values need to be converted into Double.NaN value.

Parameters:
value - The value read from the image file.
Returns:
The value to store in the raster.

convert

public abstract float convert(float value)
Converts a float-precision value before to store it in the raster. Subclasses should override this method if some fixed values need to be converted into Float.NaN value.

Parameters:
value - The value read from the image file.
Returns:
The value to store in the raster.

convert

public abstract int convert(int value)
Converts a float-precision value before to store it in the raster.

Parameters:
value - The value read from the image file.
Returns:
The value to store in the raster.

getOffset

public double getOffset()
If this converter applies an offset, returns the offset. Otherwise returns 0.


toString

public java.lang.String toString()
Returns a string representation of this sample converter. This is mostly for debugging purpose and may change in any future version.

Overrides:
toString in class java.lang.Object


Copyright © 1996-2010 Geotools. All Rights Reserved.