Package noaa.coastwatch.render
Class PaletteFactory
java.lang.Object
noaa.coastwatch.render.PaletteFactory
The PaletteFactory
class handles written tables of
predefined index color models. Each model has a number of color entries
and is associated with a descriptive name. The number of entries can vary
from 1 up to 65536, although in practice the palette will be remapped to
256 colors for use with 8-bit images. The palette file
has an XML format, as follows:
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE palette SYSTEM "http://coastwatch.noaa.gov/xml/palette.dtd"> <palette name="BW-Linear" length="256"> <color r="0" g="0" b="0" /> <color r="1" g="1" b="1" /> <color r="2" g="2" b="2" /> ... </palette>
Users may generate files of this form and use them as input to the
palette constructor. Alternately, palettes may be created by
specifying the name and index color model data. A number of predefined
palettes are also available using the names returned by the getPredefined()
method.
- Since:
- 3.1.7
- Author:
- Peter Hollemans
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addPredefined
(File paletteDir) Adds the palettes in the specified directory to the list of predefined palettes.static void
addPredefined
(Palette palette) Adds the specified palette to the list of predefined palettes.static Palette
Creates a new palette from the specified file.static Palette
create
(InputStream stream) Constructs a new palette from an input stream.static Palette
Constructs a new palette from a predefined palette name.Gets the list of predefined palette names.
-
Constructor Details
-
PaletteFactory
public PaletteFactory()
-
-
Method Details
-
getPredefined
Gets the list of predefined palette names. -
addPredefined
Adds the specified palette to the list of predefined palettes.- Parameters:
palette
- the palette to add to the list.
-
addPredefined
Adds the palettes in the specified directory to the list of predefined palettes. Palettes are identified as any file ending in '.xml'. Thus, palettes should be kept in a directory by themselves to use this method.- Parameters:
paletteDir
- the palette directory to list.- Throws:
IOException
- if an error occurred reading the directory or parsing palette file contents.
-
create
Creates a new palette from the specified file.- Parameters:
file
- the file to read.- Returns:
- the new palette.
- Throws:
FileNotFoundException
- if the file is not valid.IOException
- if the file had input format errors.
-
create
Constructs a new palette from an input stream.- Parameters:
stream
- the input stream to read palette data from.- Returns:
- the new palette.
- Throws:
IOException
- if the file had input format errors.
-
create
Constructs a new palette from a predefined palette name. This method returns the same instance of the predefined palette when called multiple times with the same name. A hash map is kept of predefined palettes, and reading of palette data only occurs when required.- Parameters:
name
- the predefined palette name.- Returns:
- the new palette.
- Throws:
RuntimeException
- if the predefined palette had input format errors or the predefined palette is invalid.
-