org.geotoolkit.image.io
Class Palette

Object
  extended by Palette

@Immutable
public abstract class Palette
extends 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.


Sharing IndexColorModel instances
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:
3.11
Author:
Martin Desruisseaux (IRD), Antoine Hnawia (IRD)
Module:
coverage/geotk-coverage (download)    View source code for this class

Field Summary
protected  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, String name, int numBands, int visibleBand)
          Creates a palette with the specified name.
 
Method Summary
protected abstract  ImageTypeSpecifier createImageTypeSpecifier()
          Creates a new image type specifier for this palette.
 boolean equals(Object object)
          Compares this palette with the specified object for equality.
 ColorModel getColorModel()
          Returns the color model for this palette.
 RenderedImage getImage(Dimension size)
          Returns the color palette as an image of the specified size.
 ImageTypeSpecifier getImageTypeSpecifier()
          Returns the image type specifier for this palette.
 int hashCode()
          Returns a hash value for this palette.
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected final 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,
                  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 ColorModel getColorModel()
                         throws FileNotFoundException,
                                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.

Returns:
The color model for this palette.
Throws:
FileNotFoundException - If the RGB values need to be read from a file and this file (typically inferred from name) is not found.
IOException - If an other kind of I/O error occurred.

getImageTypeSpecifier

public ImageTypeSpecifier getImageTypeSpecifier()
                                         throws FileNotFoundException,
                                                IOException
Returns the image type specifier for this palette. The default implementation first check if the specified still in the cache. If not, then the createImageTypeSpecifier() method is invoked and its result is stored in the cache for future reuse.

Returns:
The image type specified for this palette.
Throws:
FileNotFoundException - If the RGB values need to be read from a file and this file (typically inferred from name) is not found.
IOException - If an other kind of I/O error occurred.

createImageTypeSpecifier

protected abstract ImageTypeSpecifier createImageTypeSpecifier()
                                                        throws FileNotFoundException,
                                                               IOException
Creates a new image type specifier for this palette. This method is invoked by getImageTypeSpecifier() when the specifier is not present in the cache.

Returns:
The image type specified for this palette.
Throws:
FileNotFoundException - If the RGB values need to be read from a file and this file (typically inferred from name) is not found.
IOException - If an other kind of I/O error occurred.
Since:
3.11

getImage

public RenderedImage getImage(Dimension size)
                       throws 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
Returns:
The color palette as an image of the given size.
Throws:
IOException - if the color values can't be read.

hashCode

public int hashCode()
Returns a hash value for this palette. See equals(Object) for information about which attributes can be used in the computation.

Overrides:
hashCode in class Object

equals

public boolean equals(Object object)
Compares this palette with the specified object for equality. This method shall compare only the values given to the constructor. It shall not trig the ColorModel construction, because this equals method is used by PaletteFactory.palettes in order to check if an existing Palette instance can be reused.

Overrides:
equals in class Object
Parameters:
object - The object to compare with this palette for equality.
Returns:
true if the given object is equal to this palette.


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.