pslib
Class PSColour

java.lang.Object
  extended by pslib.PSColour

public class PSColour
extends java.lang.Object

PSColour Class

The PSColour object allows the storage of RGBA component colour values. Stored values may be modified as required whilst preserving the object reference.

This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library. If not, see http://www.gnu.org/licenses/.


Constructor Summary
PSColour()
          Create a new object instance with default values
PSColour(float g)
          Create a new object instance with the specified value (0f-1f)
PSColour(float g, float a)
          Create a new object instance with the specified values (0f-1f)
PSColour(float r, float g, float b)
          Create a new object instance with the specified values (0f-1f)
PSColour(int g)
          Create a new object instance with the specified value (0-255)
PSColour(int g, int a)
          Create a new object instance with the specified values (0-255)
PSColour(int r, int g, int b)
          Create a new object instance with the specified values (0-255)
PSColour(int r, int g, int b, int a)
          Create a new object instance with the specified values (0-255)
 
Method Summary
static int colourToInteger(PSColour c)
          Return a 32bit ARGB integer representing the component colour values of the specified PSColour object
 PSColour copy()
          Return a copy of this object
 int getAlpha()
          Return the component alpha value (0-255)
 int getARGB()
          Return a hexadecimal ARGB integer containing the component colour values of this object
 int getBlue()
          Return the component blue value (0-255)
 int getBrightness()
          Return the brightness value of this object (0-255)
 java.awt.Color getColor()
          Return a java.awt.Color object containing the component colour values of this object
 int[] getComponents()
          Return an integer array containing the component colour values of this object (0-255)
 float[] getComponents(float[] c)
          Fill the specified float array with the component colour values of this object (0f-1f) and return the result
 int[] getComponents(int[] c)
          Fill the specified integer array with the component colour values of this object (0-255) and return the result
 int getGreen()
          Return the component green value (0-255)
 int getRed()
          Return the component red value (0-255)
static PSColour integerToColour(int h)
          Return a PSColour object with component values derived from the specified 32bit ARGB integer
 void set(java.awt.Color c)
          Set the component values of this object to those of the specified java.awt.Color object
 void set(float r, float g, float b)
          Set the component values of this object (0f-1f)
 void set(float r, float g, float b, float a)
          Set the component values of this object (0f-1f)
 void set(int h)
          Set the component values of this object to those specified by the 32 bit ARGB value
 void set(int r, int g, int b)
          Set the component values of this object (0-255)
 void set(int r, int g, int b, int a)
          Set the component values of this object (0-255)
 void set(PSColour c)
          Set the component values of this object to those of the specified PSColour object
 void setAlpha(float a)
          Set the alpha component value (0f-1f)
 void setAlpha(int a)
          Set the alpha component value (0-255)
 void setBlue(float b)
          Set the blue component value (0f-1f)
 void setBlue(int b)
          Set the blue component value (0-255)
 void setGreen(float g)
          Set the green component value (0f-1f)
 void setGreen(int g)
          Set the green component value (0-255)
 void setRed(float r)
          Set the red component value (0f-1f)
 void setRed(int r)
          Set the red component value (0-255)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PSColour

public PSColour()
Create a new object instance with default values


PSColour

public PSColour(int g)
Create a new object instance with the specified value (0-255)

Parameters:
g - greyscale

PSColour

public PSColour(int g,
                int a)
Create a new object instance with the specified values (0-255)

Parameters:
g - greyscale
a - alpha

PSColour

public PSColour(int r,
                int g,
                int b)
Create a new object instance with the specified values (0-255)

Parameters:
r - red
g - green
b - blue

PSColour

public PSColour(int r,
                int g,
                int b,
                int a)
Create a new object instance with the specified values (0-255)

Parameters:
r - red
g - green
b - blue
a - alpha

PSColour

public PSColour(float g)
Create a new object instance with the specified value (0f-1f)

Parameters:
g - greyscale

PSColour

public PSColour(float g,
                float a)
Create a new object instance with the specified values (0f-1f)

Parameters:
g - greyscale
a - alpha

PSColour

public PSColour(float r,
                float g,
                float b)
Create a new object instance with the specified values (0f-1f)

Parameters:
r - red
g - green
b - blue
Method Detail

setRed

public final void setRed(int r)
Set the red component value (0-255)

Parameters:
r - red

setRed

public final void setRed(float r)
Set the red component value (0f-1f)

Parameters:
r - red

setGreen

public final void setGreen(int g)
Set the green component value (0-255)

Parameters:
g - green

setGreen

public final void setGreen(float g)
Set the green component value (0f-1f)

Parameters:
g - green

setBlue

public final void setBlue(int b)
Set the blue component value (0-255)

Parameters:
b - blue

setBlue

public final void setBlue(float b)
Set the blue component value (0f-1f)

Parameters:
b - blue

setAlpha

public final void setAlpha(int a)
Set the alpha component value (0-255)

Parameters:
a - alpha

setAlpha

public final void setAlpha(float a)
Set the alpha component value (0f-1f)

Parameters:
a - alpha

set

public final void set(java.awt.Color c)
Set the component values of this object to those of the specified java.awt.Color object

Parameters:
c - Color object

set

public final void set(PSColour c)
Set the component values of this object to those of the specified PSColour object

Parameters:
c - PSColour object

set

public final void set(int h)
Set the component values of this object to those specified by the 32 bit ARGB value

Parameters:
h - ARGB value

set

public final void set(int r,
                      int g,
                      int b)
Set the component values of this object (0-255)

Parameters:
r - red
g - green
b - blue

set

public final void set(int r,
                      int g,
                      int b,
                      int a)
Set the component values of this object (0-255)

Parameters:
r - red
g - green
b - blue
a - alpha

set

public final void set(float r,
                      float g,
                      float b)
Set the component values of this object (0f-1f)

Parameters:
r - red
g - green
b - blue

set

public final void set(float r,
                      float g,
                      float b,
                      float a)
Set the component values of this object (0f-1f)

Parameters:
r - red
g - green
b - blue
a - alpha

getRed

public final int getRed()
Return the component red value (0-255)

Returns:
the component red value

getGreen

public final int getGreen()
Return the component green value (0-255)

Returns:
the component green value

getBlue

public final int getBlue()
Return the component blue value (0-255)

Returns:
the component blue value

getAlpha

public final int getAlpha()
Return the component alpha value (0-255)

Returns:
the component alpha value

getBrightness

public final int getBrightness()
Return the brightness value of this object (0-255)

The brightness value is calculated as the average of the component colour values.

Returns:
the brightness value of this object

copy

public final PSColour copy()
Return a copy of this object

Returns:
a copy of this object

getComponents

public final int[] getComponents()
Return an integer array containing the component colour values of this object (0-255)

Returns:
an integer array containing the component colour values of this object

getComponents

public final int[] getComponents(int[] c)
Fill the specified integer array with the component colour values of this object (0-255) and return the result

Parameters:
c - integer array
Returns:
the specified array containing the component colour values of this object

getComponents

public final float[] getComponents(float[] c)
Fill the specified float array with the component colour values of this object (0f-1f) and return the result

Parameters:
c - float array
Returns:
the specified array containing the component colour values of this object

getColor

public final java.awt.Color getColor()
Return a java.awt.Color object containing the component colour values of this object

Returns:
a Color object containing the component colour values of this object

getARGB

public final int getARGB()
Return a hexadecimal ARGB integer containing the component colour values of this object

Returns:
an integer containing the component colour values of this object

colourToInteger

public static int colourToInteger(PSColour c)
Return a 32bit ARGB integer representing the component colour values of the specified PSColour object

Parameters:
c - colour
Returns:
an integer containing the component colour values of the specified PSColour object

integerToColour

public static PSColour integerToColour(int h)
Return a PSColour object with component values derived from the specified 32bit ARGB integer

Parameters:
h - ARGB integer
Returns:
a PSColour object with component values derived from the specified integer