org.geotools.image.io
Class Palette

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

public abstract class Palette
extends java.lang.Object

A set of RGB colors created by a palette factory from a name. A palette can creates a color model (often indexed) or an image type specifier from the RGB colors. The color model is retained by the palette as a weak reference (not as a soft reference) because it may consume up to 256 kilobytes. The purpose of the weak reference is to share existing instances in order to reduce memory usage; the purpose is not to provide caching.

Since:
2.4
Version:
$Id: Palette.java 30679 2008-06-13 10:19:41Z acuster $
Author:
Antoine Hnawia, Martin Desruisseaux (IRD)

Field Summary
protected  java.lang.String name
          The name of this palette.
protected  int numBands
          The number of bands in the color model.
protected  int visibleBand
          The band to display, in the range 0 inclusive to numBands exclusive.
 
Constructor Summary
protected Palette(PaletteFactory factory, java.lang.String name, int numBands, int visibleBand)
          Creates a palette with the specified name.
 
Method Summary
 boolean equals(java.lang.Object object)
          Compares this palette with the specified object for equality.
 java.awt.image.ColorModel getColorModel()
          Returns the color model for this palette.
 java.awt.image.RenderedImage getImage(java.awt.Dimension size)
          Returns the color palette as an image of the specified size.
abstract  javax.imageio.ImageTypeSpecifier getImageTypeSpecifier()
          Returns the image type specifier for this palette.
 int hashCode()
          Returns a hash value for this palette.
 void show()
          Shows the palette in a windows.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected final java.lang.String name
The name of this palette.


numBands

protected final int numBands
The number of bands in the color model. The value is 1 in the vast majority of cases.


visibleBand

protected final int visibleBand
The band to display, in the range 0 inclusive to numBands exclusive. This is used when an image contains more than one band but only one band can be used for computing the colors to display. For example IndexColorModel works on only one band.

Constructor Detail

Palette

protected Palette(PaletteFactory factory,
                  java.lang.String name,
                  int numBands,
                  int visibleBand)
Creates a palette with the specified name.

Parameters:
factory - The originating factory.
name - The palette name.
numBands - The number of bands (usually 1) to assign to numBands.
visibleBand - The visible band (usually 0) to assign to visibleBand.
Method Detail

getColorModel

public java.awt.image.ColorModel getColorModel()
                                        throws java.io.IOException
Returns the color model for this palette. This method tries to reuse existing color model if possible, since it may consume a significant amount of memory.

Throws:
java.io.FileNotFoundException - If the RGB values need to be read from a file and this file (typically inferred from name) is not found.
java.io.IOException - If an other find of I/O error occured.
javax.imageio.IIOException - If an other kind of error prevent this method to complete.

getImageTypeSpecifier

public abstract javax.imageio.ImageTypeSpecifier getImageTypeSpecifier()
                                                                throws java.io.IOException
Returns the image type specifier for this palette.

Throws:
java.io.FileNotFoundException - If the RGB values need to be read from a file and this file (typically inferred from name) is not found.
java.io.IOException - If an other find of I/O error occured.
javax.imageio.IIOException - If an other kind of error prevent this method to complete.

getImage

public java.awt.image.RenderedImage getImage(java.awt.Dimension size)
                                      throws java.io.IOException
Returns the color palette as an image of the specified size. This is useful for looking visually at a color palette.

Parameters:
size - The image size. The palette will be vertical if size.height > size.width
Throws:
java.io.IOException - if the color values can't be read.

show

public void show()
          throws java.io.IOException
Shows the palette in a windows. This is mostly for debugging purpose.

Throws:
java.io.IOException - if the color values can't be read.

hashCode

public int hashCode()
Returns a hash value for this palette.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object object)
Compares this palette with the specified object for equality.

Overrides:
equals in class java.lang.Object


Copyright © 1996-2010 Geotools. All Rights Reserved.