Class Palette
java.lang.Object
org.deltava.util.tile.Palette
A class to store color palette data.
- Since:
- 5.0
- Version:
- 11.0
- Author:
- Luke
-
Constructor Summary
ConstructorsConstructorDescriptionPalette
(int maxColors) Generates a palette with a maximum number of colors.Palette
(BufferedImage img, int maxColors) Generates a palette from an existing Image. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int r, int g, int b) Adds an RGB color to the Palette.void
Adds an RGB color to the Palette.boolean
Queries wether this Palette includes a particular RGB color.getColorModel
(boolean shrinkPalette) Returns an IndexColorModel using this Palette.Returns the Colors in this Palette.int
Returns the maximum size of the pallette.Returns the transparent color in this Palette.void
Updates the transparent color.int
size()
Returns the size of the palette.translate
(BufferedImage in, boolean useClosest, boolean shrinkPalette) Downsamples an Image to use this Palette.
-
Constructor Details
-
Palette
Palette(int maxColors) Generates a palette with a maximum number of colors.- Parameters:
maxColors
- the maximum colors
-
Palette
Generates a palette from an existing Image.- Parameters:
img
- the Image to processmaxColors
- 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
Returns the transparent color in this Palette.- Returns:
- the transparent color
-
setTransparent
Updates the transparent color.- Parameters:
c
- the transparent color
-
translate
Downsamples an Image to use this Palette.- Parameters:
in
- the Image to downsampleuseClosest
- wether a nearest match algorithm should be used for unknown colorsshrinkPalette
- 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 componentg
- the Green componentb
- the Blue component
-
add
-
contains
Queries wether this Palette includes a particular RGB color.- Parameters:
c
- the Color- Returns:
- TRUE if the Palette contains this color, otherwise FALSE
-
getColors
Returns the Colors in this Palette.- Returns:
- a Collection of Colors
-
getColorModel
Returns an IndexColorModel using this Palette.- Parameters:
shrinkPalette
- TRUE if the Palette should be no longer than required, otherwise FALSE- Returns:
- an IndexColorModel
-