Package net.sourceforge.jiu.data
Class Palette
- java.lang.Object
-
- net.sourceforge.jiu.data.Palette
-
- All Implemented Interfaces:
RGBIndex
public class Palette extends Object implements RGBIndex
This class represents a palette, a list of RGB colors. An RGB color here has three int values for its red, green and blue intensity. Each intensity value must be larger than or equal to zero and smaller than or equal to the maximum intensity value that can be given to the constructorPalette(int, int). This maximum value is typically 255. Note that the number of entries in a palette is restricted only by the element index typeintso that palettes with more than 256 entries are no problem. When accessing (reading or writing) samples of this palette, use the constantsRGBIndex.INDEX_RED,RGBIndex.INDEX_GREENandRGBIndex.INDEX_BLUEof this class to define a color channel.- Author:
- Marco Schmidt
- See Also:
PalettedImage
-
-
Field Summary
Fields Modifier and Type Field Description private int[][]dataprivate intmaxValueprivate intnumEntries-
Fields inherited from interface net.sourceforge.jiu.data.RGBIndex
INDEX_BLUE, INDEX_GREEN, INDEX_RED
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectclone()Creates a copy of this palette, allocating a new Palette object and copying each RGB triplet to the new palette.longgetAllocatedMemory()Returns the amount of memory in bytes allocated for this palette.intgetMaxValue()Returns the maximum value allowed for a sample.intgetNumEntries()Returns the number of entries in this palette.intgetSample(int channelIndex, int entryIndex)Returns one of the samples of this palette.int[]getSamples(int channelIndex)Returns all samples of one channel as an int array.booleanisBlackAndWhite()Checks if all entries of this palette are either black or white.booleanisGray()Checks if this palette is gray, i.e., checks if all entries are gray.voidput(int entryIndex, int red, int green, int blue)voidputSample(int channelIndex, int entryIndex, int newValue)Sets one sample of one color entry in the palette to a new value.
-
-
-
Constructor Detail
-
Palette
public Palette(int numEntries, int maxValue)Create a palette with the given number of entries and a maximum value for each sample.- Parameters:
numEntries- the number of entries to be accessible in this palettemaxValue- the maximum value to be allowed for each sample
-
Palette
public Palette(int numEntries)
Create a palette with the given number of entries and a maximum value of255.- Parameters:
numEntries- the number of entries to be accessible in this palette
-
-
Method Detail
-
clone
public Object clone()
Creates a copy of this palette, allocating a new Palette object and copying each RGB triplet to the new palette. Then returns the new palette. Thus, a "deep" copy of this Palette object is created, not a "shallow" one.
-
getAllocatedMemory
public long getAllocatedMemory()
Returns the amount of memory in bytes allocated for this palette.
-
getMaxValue
public int getMaxValue()
Returns the maximum value allowed for a sample.- Returns:
- the maximum sample value
-
getNumEntries
public int getNumEntries()
Returns the number of entries in this palette.- Returns:
- the number of entries in this palette
-
getSample
public int getSample(int channelIndex, int entryIndex)Returns one of the samples of this palette.- Parameters:
entryIndex- the index of the color to be addressed, must be from0togetNumEntries() - 1channelIndex- one of the three channels; must beRGBIndex.INDEX_RED,RGBIndex.INDEX_GREENorRGBIndex.INDEX_BLUE- Returns:
- the requested sample
-
getSamples
public int[] getSamples(int channelIndex)
Returns all samples of one channel as an int array.- Parameters:
channelIndex- index of the channel, one of theRGBIndexconstants- Returns:
- array with samples
-
isBlackAndWhite
public boolean isBlackAndWhite()
Checks if all entries of this palette are either black or white. An entry is black if all three intensitites (red, green and blue) are0, it is white if they are all equal togetMaxValue(). No particular order of entries (e.g. first color black, second white) is demanded and no specific number of entries (e.g. 2). This means that a palette is black and white if it contains ten entries that are all black.- Returns:
- if the palette contains only the colors black and white
-
isGray
public boolean isGray()
Checks if this palette is gray, i.e., checks if all entries are gray. This is the case if for all entries red, green and blue have the same intensity.- Returns:
- if the palette contains only shades of gray
-
put
public void put(int entryIndex, int red, int green, int blue)
-
putSample
public void putSample(int channelIndex, int entryIndex, int newValue)Sets one sample of one color entry in the palette to a new value.- Parameters:
channelIndex-
-
-