Class PaletteFactory

java.lang.Object
noaa.coastwatch.render.PaletteFactory

public class PaletteFactory extends Object

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 Details

    • PaletteFactory

      public PaletteFactory()
  • Method Details

    • getPredefined

      public static List<String> getPredefined()
      Gets the list of predefined palette names.
    • addPredefined

      public static void addPredefined(Palette palette)
      Adds the specified palette to the list of predefined palettes.
      Parameters:
      palette - the palette to add to the list.
    • addPredefined

      public static void addPredefined(File paletteDir) throws IOException
      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

      public static Palette create(File file) throws FileNotFoundException, IOException
      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

      public static Palette create(InputStream stream) throws IOException
      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

      public static Palette create(String name)
      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.