ncsa.hdf.view
Class Tools

java.lang.Object
  extended byncsa.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.


Constructor Summary
Tools()
           
 
Method Summary
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 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 byte[] getBytes(java.lang.Object rawData, double[] minmax)
          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)
          Convert an array of raw data into array of a byte data.
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
 

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]

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)
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)
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