ncsa.hdf.view
Class Tools

java.lang.Object
  extended by ncsa.hdf.view.Tools

public final class Tools
extends java.lang.Object

The "Tools" class contains various of tools for HDF files such as jpeg to HDF converter.


Field Summary
static java.lang.String FILE_TYPE_JPEG
          Key for JPEG image file type.
static java.lang.String FILE_TYPE_PNG
          Key for PNG image file type.
static java.lang.String FILE_TYPE_TIFF
          Key for TIFF image file type.
static long MAX_INT16
           
static long MAX_INT32
           
static long MAX_INT64
           
static long MAX_INT8
           
static long MAX_UINT16
           
static long MAX_UINT32
           
static long MAX_UINT8
           
 
Constructor Summary
Tools()
           
 
Method Summary
static java.lang.Object autoContrastApply(java.lang.Object data_in, java.lang.Object data_out, double[] params, boolean isUnsigned)
          Apply autocontrast parameters in place (destructive)
static int autoContrastCompute(java.lang.Object data, double[] params, boolean isUnsigned)
          Computes autocontrast parameters (gain equates to contrast and bias equates to brightness) for integers.
static int autoContrastComputeMinMax(java.lang.Object data, java.lang.Object minmax)
          Computes autocontrast parameters by
static int autoContrastComputeSliderRange(double[] params, double[] gain, double[] bias)
          Auto-ranging of gain/bias sliders Given the results of autogaining an image, compute reasonable min and max values for gain/bias sliders.
static int autoContrastConvertImageBuffer(java.lang.Object src, byte[] dst, boolean isUnsigned)
          Converts image raw data to bytes.
static int computeStatistics(java.lang.Object data, double[] avgstd)
          Computes mean and standard deviation of a data array
static void convertImageToHDF(java.lang.String imgFileName, java.lang.String hFileName, java.lang.String fromType, java.lang.String toType)
          Converts an image file into HDF4/5 file.
static byte[][] createGrayPalette()
          Creates the gray palette of the indexed 256-color table.
static byte[][] createGrayWavePalette()
          Creates the gray wave palette of the indexed 256-color table.
static java.awt.Image createIndexedImage(byte[] imageData, byte[][] palette, int w, int h)
          Creates a RGB indexed image of 256 colors.
static byte[][] createNaturePalette()
          Creates the nature palette of the indexed 256-color table.
static byte[][] createRainbowPalette()
          Creates the rainbow palette of the indexed 256-color table.
static byte[][] createReverseGrayPalette()
          Creates the reverse gray palette of the indexed 256-color table.
static java.awt.Image createTrueColorImage(byte[] imageData, boolean planeInterlace, int w, int h)
          Creates a true color image.
static byte[][] createWavePalette()
          Creates the wave palette of the indexed 256-color table.
static int findMinMax(java.lang.Object data, double[] minmax)
          Finds the min and max values of the data array
static byte[] getBytes(java.lang.Object rawData, double[] minmax, byte[] byteData)
          Convert an array of raw data into array of a byte data.
static byte[] getBytes(java.lang.Object rawData, double[] minmax, int w, int h, boolean isTransposed, byte[] byteData)
           
static byte[] getBytes(java.lang.Object rawData, double[] minmax, int w, int h, boolean isTransposed, java.lang.Object fillValue, byte[] byteData)
          Convert an array of raw data into array of a byte data.
static byte[] getBytes(java.lang.Object rawData, double[] minmax, java.lang.Object fillValue, byte[] byteData)
           
static boolean hasAlpha(java.awt.Image image)
          This method returns true if the specified image has transparent pixels.
static java.lang.Object newInstance(java.lang.Class cls, java.lang.Object[] initargs)
          Create and initialize a new instance of the given class.
static void saveImageAs(java.awt.image.BufferedImage image, java.io.File file, java.lang.String type)
          Save a BufferedImage into an image file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_INT8

public static final long MAX_INT8
See Also:
Constant Field Values

MAX_UINT8

public static final long MAX_UINT8
See Also:
Constant Field Values

MAX_INT16

public static final long MAX_INT16
See Also:
Constant Field Values

MAX_UINT16

public static final long MAX_UINT16
See Also:
Constant Field Values

MAX_INT32

public static final long MAX_INT32
See Also:
Constant Field Values

MAX_UINT32

public static final long MAX_UINT32
See Also:
Constant Field Values

MAX_INT64

public static final long MAX_INT64
See Also:
Constant Field Values

FILE_TYPE_JPEG

public static final java.lang.String FILE_TYPE_JPEG
Key for JPEG image file type.

See Also:
Constant Field Values

FILE_TYPE_TIFF

public static final java.lang.String FILE_TYPE_TIFF
Key for TIFF image file type.

See Also:
Constant Field Values

FILE_TYPE_PNG

public static final java.lang.String FILE_TYPE_PNG
Key for PNG image file type.

See Also:
Constant Field Values
Constructor Detail

Tools

public Tools()
Method Detail

convertImageToHDF

public static void convertImageToHDF(java.lang.String imgFileName,
                                     java.lang.String hFileName,
                                     java.lang.String fromType,
                                     java.lang.String toType)
                              throws java.lang.Exception
Converts an image file into HDF4/5 file.

Parameters:
imgFileName - the input image file.
hFileName - the name of the HDF4/5 file.
fromType - the type of image.
toType - the type of file converted to.
Throws:
java.lang.Exception

saveImageAs

public static void saveImageAs(java.awt.image.BufferedImage image,
                               java.io.File file,
                               java.lang.String type)
                        throws java.lang.Exception
Save a BufferedImage into an image file.

Parameters:
image - the BufferedImage to save.
file - the image file.
type - the image type.
Throws:
java.lang.Exception

createGrayPalette

public static final byte[][] createGrayPalette()
Creates the gray palette of the indexed 256-color table.

The palette values are stored in a two-dimensional byte array and arrange by color components of red, green and blue. palette[][] = byte[3][256], where, palette[0][], palette[1][] and palette[2][] are the red, green and blue components respectively.

Returns:
the gray palette in the form of byte[3][256]

createReverseGrayPalette

public static final byte[][] createReverseGrayPalette()
Creates the reverse gray palette of the indexed 256-color table.

The palette values are stored in a two-dimensional byte array and arrange by color components of red, green and blue. palette[][] = byte[3][256], where, palette[0][], palette[1][] and palette[2][] are the red, green and blue components respectively.

Returns:
the gray palette in the form of byte[3][256]

createGrayWavePalette

public static final byte[][] createGrayWavePalette()
Creates the gray wave palette of the indexed 256-color table.

The palette values are stored in a two-dimensional byte array and arrange by color components of red, green and blue. palette[][] = byte[3][256], where, palette[0][], palette[1][] and palette[2][] are the red, green and blue components respectively.

Returns:
the gray palette in the form of byte[3][256]

createRainbowPalette

public static final byte[][] createRainbowPalette()
Creates the rainbow palette of the indexed 256-color table.

The palette values are stored in a two-dimensional byte array and arrange by color components of red, green and blue. palette[][] = byte[3][256], where, palette[0][], palette[1][] and palette[2][] are the red, green and blue components respectively.

Returns:
the rainbow palette in the form of byte[3][256]

createNaturePalette

public static final byte[][] createNaturePalette()
Creates the nature palette of the indexed 256-color table.

The palette values are stored in a two-dimensional byte array and arrange by color components of red, green and blue. palette[][] = byte[3][256], where, palette[0][], palette[1][] and palette[2][] are the red, green and blue components respectively.

Returns:
the nature palette in the form of byte[3][256]

createWavePalette

public static final byte[][] createWavePalette()
Creates the wave palette of the indexed 256-color table.

The palette values are stored in a two-dimensional byte array and arrange by color components of red, green and blue. palette[][] = byte[3][256], where, palette[0][], palette[1][] and palette[2][] are the red, green and blue components respectively.

Returns:
the wave palette in the form of byte[3][256]

hasAlpha

public static boolean hasAlpha(java.awt.Image image)
This method returns true if the specified image has transparent pixels.

Parameters:
image - the image to be check if has alpha.
Returns:
true if the image has alpha setting.

createIndexedImage

public static java.awt.Image createIndexedImage(byte[] imageData,
                                                byte[][] palette,
                                                int w,
                                                int h)
Creates a RGB indexed image of 256 colors.

Parameters:
imageData - the byte array of the image data.
palette - the color lookup table.
w - the width of the image.
h - the height of the image.
Returns:
the image.

createTrueColorImage

public static java.awt.Image createTrueColorImage(byte[] imageData,
                                                  boolean planeInterlace,
                                                  int w,
                                                  int h)
Creates a true color image.

DirectColorModel is used to construct the image from raw data. The DirectColorModel model is similar to an X11 TrueColor visual, which has the following parameters:

            Number of bits:        32
            Red mask:              0x00ff0000
            Green mask:            0x0000ff00
            Blue mask:             0x000000ff
            Alpha mask:            0xff000000
            Color space:           sRGB
            isAlphaPremultiplied:  False
            Transparency:          Transparency.TRANSLUCENT
            transferType:          DataBuffer.TYPE_INT
        

The data may be arranged in one of two ways: by pixel or by plane. In both cases, the dataset will have a dataspace with three dimensions, height, width, and components.

For HDF4, the interlace modes specify orders for the dimensions as:

           INTERLACE_PIXEL = [width][height][pixel components]
           INTERLACE_PLANE = [pixel components][width][height]
       

For HDF5, the interlace modes specify orders for the dimensions as:

           INTERLACE_PIXEL = [height][width][pixel components]
           INTERLACE_PLANE = [pixel components][height][width]
       

Parameters:
imageData - the byte array of the image data.
planeInterlace - flag if the image is plane intelace.
w - the width of the image.
h - the height of the image.
Returns:
the image.

getBytes

public static byte[] getBytes(java.lang.Object rawData,
                              double[] minmax,
                              byte[] byteData)
Convert an array of raw data into array of a byte data. Byte data ranged from -128 to 127.

Parameters:
rawData - The input raw data.
minmax - the range of the raw data.
Returns:
the byte array of pixel data.

getBytes

public static byte[] getBytes(java.lang.Object rawData,
                              double[] minmax,
                              int w,
                              int h,
                              boolean isTransposed,
                              byte[] byteData)

getBytes

public static byte[] getBytes(java.lang.Object rawData,
                              double[] minmax,
                              java.lang.Object fillValue,
                              byte[] byteData)

getBytes

public static byte[] getBytes(java.lang.Object rawData,
                              double[] minmax,
                              int w,
                              int h,
                              boolean isTransposed,
                              java.lang.Object fillValue,
                              byte[] byteData)
Convert an array of raw data into array of a byte data. Byte data ranged from -128 to 127.

Parameters:
rawData - The input raw data.
minmax - the range of the raw data.
isTransposed - if the data is transposeed
Returns:
the byte array of pixel data.

newInstance

public static java.lang.Object newInstance(java.lang.Class cls,
                                           java.lang.Object[] initargs)
                                    throws java.lang.Exception
Create and initialize a new instance of the given class.

Parameters:
initargs - - array of objects to be passed as arguments
Returns:
a new instance of the given class.
Throws:
java.lang.Exception

autoContrastCompute

public static int autoContrastCompute(java.lang.Object data,
                                      double[] params,
                                      boolean isUnsigned)
Computes autocontrast parameters (gain equates to contrast and bias equates to brightness) for integers.

The computation is based on the following scaling

      int_8       [0, 127]
      uint_8      [0, 255]
      int_16      [0, 32767]
      uint_16     [0, 65535]
      int_32      [0, 2147483647]
      uint_32     [0, 4294967295]
      int_64      [0, 9223372036854775807]
      uint_64     [0, 18446744073709551615] // Not supported.
 

Parameters:
data - the raw data array of signed/unsigned integers
params - the auto gain parameter. params[0]=gain, params[1]=bias
isUnsigned - the flag to indicate if the data array is unsiged integer
Returns:
non-negative if successful; otherwise, returns negative

autoContrastApply

public static java.lang.Object autoContrastApply(java.lang.Object data_in,
                                                 java.lang.Object data_out,
                                                 double[] params,
                                                 boolean isUnsigned)
Apply autocontrast parameters in place (destructive)

Parameters:
data_in - the original data array of signed/unsigned integers
data_out - the converted data array of signed/unsigned integers
params - the auto gain parameter. params[0]=gain, params[1]=bias
isUnsigned - the flag to indicate if the data array is unsiged integer
Returns:
the data array with the auto contrast conversion; otherwise, returns null

autoContrastComputeSliderRange

public static int autoContrastComputeSliderRange(double[] params,
                                                 double[] gain,
                                                 double[] bias)
Auto-ranging of gain/bias sliders Given the results of autogaining an image, compute reasonable min and max values for gain/bias sliders.

Parameters:
params - the auto gain parameter: params[0]=gain, params[1]=bias
gain - the range of the gain: gain[0]=min, gain[1]=mas
bias - the range of the bias: bias[0]=min, bias[1]=max
Returns:
non-negative if successful; otherwise, returns negative

autoContrastConvertImageBuffer

public static int autoContrastConvertImageBuffer(java.lang.Object src,
                                                 byte[] dst,
                                                 boolean isUnsigned)
Converts image raw data to bytes.

The integer data is converted to byte data based on the following rule

       
        uint_8       x
        int_8       (x & 0x7F) << 1
        uint_16     (x >> 8) & 0xFF
        int_16      (x >> 7) & 0xFF
        uint_32     (x >> 24) & 0xFF
        int_32      (x >> 23) & 0xFF
        uint_64     (x >> 56) & 0xFF
        int_64      (x >> 55) & 0xFF
 

Parameters:
src - the source data array of signed integers or unsigned shorts
dst - the destination data array of bytes
isUnsigned - the flag to indicate if the data array is unsiged integer
Returns:
non-negative if successful; otherwise, returns negative

autoContrastComputeMinMax

public static int autoContrastComputeMinMax(java.lang.Object data,
                                            java.lang.Object minmax)
Computes autocontrast parameters by
    min = mean - 3 * std.dev 
    max = mean + 3 * std.dev 
 

Parameters:
data - the raw data array
minmax - the min and max values.
Returns:
non-negative if successful; otherwise, returns negative

findMinMax

public static int findMinMax(java.lang.Object data,
                             double[] minmax)
Finds the min and max values of the data array

Parameters:
data - the raw data array
minmax - the mmin and max values of the array.
Returns:
non-negative if successful; otherwise, returns negative

computeStatistics

public static int computeStatistics(java.lang.Object data,
                                    double[] avgstd)
Computes mean and standard deviation of a data array

Parameters:
data - the raw data array
avgstd - the statistics: avgstd[0]=mean and avgstd[1]=stdev.
Returns:
non-negative if successful; otherwise, returns negative