Class Palette

java.lang.Object
org.deltava.util.tile.Palette

public class Palette extends Object
A class to store color palette data.
Since:
5.0
Version:
11.0
Author:
Luke
  • Constructor Details

    • Palette

      Palette(int maxColors)
      Generates a palette with a maximum number of colors.
      Parameters:
      maxColors - the maximum colors
    • Palette

      public Palette(BufferedImage img, int maxColors)
      Generates a palette from an existing Image.
      Parameters:
      img - the Image to process
      maxColors - the maximum size of the palette
      Throws:
      IllegalArgumentException - if the Image has over 256 colors
  • Method Details

    • size

      public int size()
      Returns the size of the palette.
      Returns:
      the number of colors
    • getMaxSize

      public int getMaxSize()
      Returns the maximum size of the pallette.
      Returns:
      the maximum number of colors
    • getTransparent

      public Color getTransparent()
      Returns the transparent color in this Palette.
      Returns:
      the transparent color
    • setTransparent

      public void setTransparent(Color c)
      Updates the transparent color.
      Parameters:
      c - the transparent color
    • translate

      public BufferedImage translate(BufferedImage in, boolean useClosest, boolean shrinkPalette)
      Downsamples an Image to use this Palette.
      Parameters:
      in - the Image to downsample
      useClosest - wether a nearest match algorithm should be used for unknown colors
      shrinkPalette - TRUE if the palette should use the minimum number of bits possible, otherwise FALSE
      Returns:
      a downsampled BufferedImage
    • add

      public void add(int r, int g, int b)
      Adds an RGB color to the Palette.
      Parameters:
      r - the Red component
      g - the Green component
      b - the Blue component
    • add

      public void add(Color c)
      Adds an RGB color to the Palette.
      Parameters:
      c - the Color
    • contains

      public boolean contains(Color c)
      Queries wether this Palette includes a particular RGB color.
      Parameters:
      c - the Color
      Returns:
      TRUE if the Palette contains this color, otherwise FALSE
    • getColors

      public Collection<Color> getColors()
      Returns the Colors in this Palette.
      Returns:
      a Collection of Colors
    • getColorModel

      public IndexColorModel getColorModel(boolean shrinkPalette)
      Returns an IndexColorModel using this Palette.
      Parameters:
      shrinkPalette - TRUE if the Palette should be no longer than required, otherwise FALSE
      Returns:
      an IndexColorModel