net.paulhertz.aifile
Class Palette

java.lang.Object
  extended by net.paulhertz.aifile.Palette

public class Palette
extends Object

Maintains a set of Processing-style colors: alpha, red, green and blue stored as 4 bytes in an 32-bit int. Does not permit duplicate color entries. Provides methods for adding colors in other formats, and some utility functions.


Constructor Summary
Palette()
          Creates a Palette with no colors
Palette(Palette palette)
          Creates a Palette instance from another Palette's colorSet.
 
Method Summary
 void addBlackWhiteGray()
          Adds black, white and gray to the palette.
 void addColor(CMYKColor cmyk)
          Transforms a CMYKColor to a 32-bit int and adds it to the colorSet of this Palette.
 void addColor(int argb)
          Adds a Processing color to the colorSet of this Palette.
 void addColor(RGBColor rgb)
          Transforms an RGBColor to a 32-bit int and adds it to the colorSet of this Palette.
 void addColors(ArrayList<Integer> argbColors)
          Adds colors in argbColors to the colorSet of this Palette.
 void addColors(int[] argbColors)
          Adds colors in argbColors to the colorSet of this Palette.
static int[] argbComponents(int argb)
          Breaks a Processing color into A, R, G and B values in an array.
static int cmyk2int(CMYKColor cmyk)
          Converts a CMYKColor to a Processing color.
static int[] colorPermutation(int argb)
          Returns all unique permutations of the color channels of a supplied color.
static int complement(int argb)
          Returns the complement of a color.
static int composeColor(int gray)
          Creates a Processing ARGB color from a grayscale value.
static int composeColor(int r, int g, int b, int a)
          Creates a Processing ARGB color from r, g, b, and alpha channel values.
 int getColor(int index)
           
 int[] getColors()
          Returns the colors in the colorSet of this Palette as an array of integers.
 LinkedHashSet<Integer> getColorSet()
          Returns the internal storage for colors.
static RGBColor int2rgb(int argb)
          Converts a Processing color to an RGBColor.
static int randColor()
          Returns a random Processing color.
static int randColor(int[] c)
          Creates a random color from randomly selected values in an array.
static int rgb2int(RGBColor rgb)
          Converts an RGBColor to a Processing color.
static int[] rgbComponents(int argb)
          Breaks a Processing color into R, G and B values in an array.
 String toString()
           
 void write(PrintWriter pw)
          Writes this Palette in Adobe Illustrator file format.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Palette

public Palette()
Creates a Palette with no colors


Palette

public Palette(Palette palette)
Creates a Palette instance from another Palette's colorSet.

Parameters:
palette - a Palette, source for the colors used in this Palette
Method Detail

write

public void write(PrintWriter pw)
Writes this Palette in Adobe Illustrator file format. If you call this yourself, call it right after outputting the header (perhaps with a call to writeHeader()).

Parameters:
pw - PrintWriter for output to file

addBlackWhiteGray

public void addBlackWhiteGray()
Adds black, white and gray to the palette.


addColor

public void addColor(RGBColor rgb)
Transforms an RGBColor to a 32-bit int and adds it to the colorSet of this Palette.

Parameters:
rgb - an RGBColor

addColor

public void addColor(CMYKColor cmyk)
Transforms a CMYKColor to a 32-bit int and adds it to the colorSet of this Palette.

Parameters:
cmyk - a CMYKColor

addColor

public void addColor(int argb)
Adds a Processing color to the colorSet of this Palette.

Parameters:
argb - a Processing-format color, alpha, red, green and blue stored as 4 bytes in an 32-bit int

addColors

public void addColors(ArrayList<Integer> argbColors)
Adds colors in argbColors to the colorSet of this Palette. Skips colors that are already in the palette.

Parameters:
argbColors - an ArrayList of Processing-format colors (32 bit integers)

addColors

public void addColors(int[] argbColors)
Adds colors in argbColors to the colorSet of this Palette. Skips colors that are already in the palette.

Parameters:
argbColors - an array of Processing-format colors (32 bit integers)

getColorSet

public LinkedHashSet<Integer> getColorSet()
Returns the internal storage for colors.

Returns:
the internal storage for colors, a LinkedHashSet

getColors

public int[] getColors()
Returns the colors in the colorSet of this Palette as an array of integers. These can be treated as Processing-format colors, with ARGB channels.

Returns:
colors in palette as an array of ints

getColor

public int getColor(int index)

argbComponents

public static int[] argbComponents(int argb)
Breaks a Processing color into A, R, G and B values in an array.

Parameters:
argb - a Processing color as a 32-bit integer
Returns:
an array of integers in the range 0..255 for each color component: {A, R, G, B}

rgbComponents

public static int[] rgbComponents(int argb)
Breaks a Processing color into R, G and B values in an array.

Parameters:
argb - a Processing color as a 32-bit integer
Returns:
an array of integers in the range 0..255 for 3 primary color components: {R, G, B}

composeColor

public static int composeColor(int r,
                               int g,
                               int b,
                               int a)
Creates a Processing ARGB color from r, g, b, and alpha channel values. Note the order of arguments, the same as the Processing color(value1, value2, value3, alpha) method.

Parameters:
r - red component 0..255
g - green component 0..255
b - blue component 0..255
a - alpha component 0..255
Returns:
a 32-bit integer with bytes in Processing format ARGB.

composeColor

public static int composeColor(int gray)
Creates a Processing ARGB color from a grayscale value. Alpha will be set to 255.

Parameters:
gray - a grayscale value 0..255
Returns:
an int compatible with a Processing color

randColor

public static int randColor(int[] c)
Creates a random color from randomly selected values in an array.

Parameters:
c - an array of integer values
Returns:
a color with a = 255 and r, g and b randomly selected from the array values

randColor

public static int randColor()
Returns a random Processing color.

Returns:
a color with a = 255 and r, g and b set to random values in 0..255

colorPermutation

public static int[] colorPermutation(int argb)
Returns all unique permutations of the color channels of a supplied color.

Parameters:
argb - a Processing-format color, a, r, g and b as bytes in a 32-bit integer
Returns:
an array of Processing-format colors with all unique permutations of r, g and b, where a = 255

complement

public static int complement(int argb)
Returns the complement of a color.

Parameters:
argb - a Processing-format color, 32-bit integer a, r, g and b channels.
Returns:
the rgb complement of the supplied color, same alpha

int2rgb

public static RGBColor int2rgb(int argb)
Converts a Processing color to an RGBColor.

Parameters:
argb - a Processing color
Returns:
an RGBColor

rgb2int

public static int rgb2int(RGBColor rgb)
Converts an RGBColor to a Processing color.

Parameters:
rgb -
Returns:
a Processing color

cmyk2int

public static int cmyk2int(CMYKColor cmyk)
Converts a CMYKColor to a Processing color.

Parameters:
cmyk -
Returns:
a Processing color

toString

public String toString()
Overrides:
toString in class Object


Processing library IgnoCodeLib by Paul Hertz. (C) 2013