uk.co.silentsoftware.core.helpers
Class ColourHelper

java.lang.Object
  extended by uk.co.silentsoftware.core.helpers.ColourHelper

public final class ColourHelper
extends java.lang.Object

Utility class to provide common colour functionality


Constructor Summary
ColourHelper()
           
 
Method Summary
static java.awt.image.BufferedImage changeBrightness(java.awt.image.BufferedImage img, float amount)
          Changes brightness by increasing all pixel values by a given amount
static java.awt.image.BufferedImage changeContrast(java.awt.image.BufferedImage img, float amount)
          Changes the contrast of an image
private static int changePixelBrightness(int pixel, float amount)
          Changes brightness by increasing the pixel value by a given amount
private static int changePixelContrast(int pixel, float c)
          Changes the contrast of an individual pixel by a given amount.
private static int changePixelSaturation(int pixel, float amount)
          Changes the saturation of an individual pixel by the given amount (0-1 range)
static java.awt.image.BufferedImage changeSaturation(java.awt.image.BufferedImage img, float amount)
          Changes image saturation by a given amount (0-1 range)
static java.awt.image.BufferedImage colourAttributes(java.awt.image.BufferedImage output, java.awt.image.BufferedImage original, ColourChoiceStrategy colourChoiceStrategy)
          Colours an entire image using the given colourstrategy based on the original and output images
private static java.awt.image.BufferedImage colourAttributes(int xMax, int yMax, java.awt.image.BufferedImage output, java.awt.image.BufferedImage original, ColourChoiceStrategy colourChoiceStrategy)
          Colours the Spectrum attribute blocks by selecting xMax by yMax parts of the output image (i.e.
(package private) static float correctRange(float value, int low, int high)
          Ensures a value is within a given range.
private static int correctRange(int channel)
          Corrects and individual colour channel value's range to 0>channel<255
static int getClosestBrightGigascreenColour(int rgb)
          Retrieves the half bright Gigascreen colour most like the provided rgb colour
static int getClosestBrightSpectrumColour(int rgb)
          Retrieves the spectrum bright colour most like the provided rgb colour
static int getClosestBrightSpectrumColour(int rgb, int excludedRgb)
          Retrieves the spectrum bright colour most like the provided rgb colour which is NOT the excluded rgb
private static int getClosestColour(int rgb, int[] colourSet)
           
private static int getClosestColour(int red, int green, int blue, int[] colourSet)
          Retrieves the from the colourSet most like the provided rgb colour
private static int getClosestColourWithExclusion(int rgb, int excludedRgb, int[] colourSet)
          Retrieves the colour from the colourSet most like the provided rgb colour
static int getClosestGigascreenColour(int rgb)
          Retrieves the Gigascreen colour most like the provided rgb colour
static int getClosestGigascreenColour(int red, int green, int blue)
          Retrieves the Gigascreen colour most like the provided rgb colour
static int getClosestHalfBrightGigascreenColour(int rgb)
          Retrieves the half bright Gigascreen colour most like the provided rgb colour
static int getClosestHalfBrightSpectrumColour(int rgb)
          Retrieves the spectrum half bright colour most like the provided rgb colour
static int getClosestHalfBrightSpectrumColour(int rgb, int excludedRgb)
          Retrieves the spectrum half bright colour most like the provided rgb colour which is NOT the excluded rgb
static int getClosestReducedHalfBrightSpectrumColour(int rgb)
          Retrieves the reduced set spectrum half bright colour most like the provided rgb colour
static int getClosestReducedHalfBrightSpectrumColour(int rgb, int excludedRgb)
          Retrieves the reduced set spectrum half bright colour most like the provided rgb colour which is NOT the excluded rgb
static int getClosestSpectrumColour(int rgb)
          Retrieves the spectrum colour most like the provided rgb colour
static int getClosestSpectrumColour(int red, int green, int blue)
          Retrieves the spectrum colour most like the provided rgb colour
static int getMonochromeColour(int rgb, int ink, int paper)
          Based on the darkness of the pixel colour determines whether a pixel is ink or paper and returns that colour.
static int getMonochromeColour(int red, int green, int blue, int ink, int paper)
          Based on the darkness of the pixel colour determines whether a pixel is ink or paper and returns that colour.
static int intToAlphaRgb(int[] rgb)
          Convert individual RGB components into a 32 bit ARGB value
static int intToAlphaRgb(int red, int green, int blue)
          Convert individual RGB components into a 32 bit ARGB value
static int[] intToRgbComponents(int rgb)
           
static boolean isBlack(int red, int green, int blue)
          Determines whether a pixel is closer to black (than white)
static boolean isBrightSet(int argb)
          Determines whether the colour is from the Spectrum's bright or half bright colour set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ColourHelper

public ColourHelper()
Method Detail

getClosestSpectrumColour

public static int getClosestSpectrumColour(int rgb)
Retrieves the spectrum colour most like the provided rgb colour

Parameters:
rgb -
Returns:

getClosestSpectrumColour

public static int getClosestSpectrumColour(int red,
                                           int green,
                                           int blue)
Retrieves the spectrum colour most like the provided rgb colour

Parameters:
red -
green -
blue -
Returns:

getClosestBrightSpectrumColour

public static int getClosestBrightSpectrumColour(int rgb,
                                                 int excludedRgb)
Retrieves the spectrum bright colour most like the provided rgb colour which is NOT the excluded rgb

Parameters:
rgb -
Returns:

getClosestBrightSpectrumColour

public static int getClosestBrightSpectrumColour(int rgb)
Retrieves the spectrum bright colour most like the provided rgb colour

Parameters:
rgb -
Returns:

getClosestHalfBrightSpectrumColour

public static int getClosestHalfBrightSpectrumColour(int rgb,
                                                     int excludedRgb)
Retrieves the spectrum half bright colour most like the provided rgb colour which is NOT the excluded rgb

Parameters:
rgb -
Returns:

getClosestHalfBrightSpectrumColour

public static int getClosestHalfBrightSpectrumColour(int rgb)
Retrieves the spectrum half bright colour most like the provided rgb colour

Parameters:
rgb -
Returns:

getClosestReducedHalfBrightSpectrumColour

public static int getClosestReducedHalfBrightSpectrumColour(int rgb,
                                                            int excludedRgb)
Retrieves the reduced set spectrum half bright colour most like the provided rgb colour which is NOT the excluded rgb

Parameters:
rgb -
Returns:

getClosestReducedHalfBrightSpectrumColour

public static int getClosestReducedHalfBrightSpectrumColour(int rgb)
Retrieves the reduced set spectrum half bright colour most like the provided rgb colour

Parameters:
rgb -
Returns:

getClosestGigascreenColour

public static int getClosestGigascreenColour(int red,
                                             int green,
                                             int blue)
Retrieves the Gigascreen colour most like the provided rgb colour

Parameters:
red -
green -
blue -
Returns:

getClosestHalfBrightGigascreenColour

public static int getClosestHalfBrightGigascreenColour(int rgb)
Retrieves the half bright Gigascreen colour most like the provided rgb colour

Parameters:
rgb -
Returns:

getClosestBrightGigascreenColour

public static int getClosestBrightGigascreenColour(int rgb)
Retrieves the half bright Gigascreen colour most like the provided rgb colour

Parameters:
rgb -
Returns:

getClosestGigascreenColour

public static int getClosestGigascreenColour(int rgb)
Retrieves the Gigascreen colour most like the provided rgb colour

Parameters:
rgb -
Returns:

getClosestColour

private static int getClosestColour(int red,
                                    int green,
                                    int blue,
                                    int[] colourSet)
Retrieves the from the colourSet most like the provided rgb colour

Parameters:
red -
green -
blue -
colourSet -
Returns:

getClosestColour

private static int getClosestColour(int rgb,
                                    int[] colourSet)

getClosestColourWithExclusion

private static int getClosestColourWithExclusion(int rgb,
                                                 int excludedRgb,
                                                 int[] colourSet)
Retrieves the colour from the colourSet most like the provided rgb colour

Parameters:
rgb -
colourSet -
Returns:

colourAttributes

public static java.awt.image.BufferedImage colourAttributes(java.awt.image.BufferedImage output,
                                                            java.awt.image.BufferedImage original,
                                                            ColourChoiceStrategy colourChoiceStrategy)
Colours an entire image using the given colourstrategy based on the original and output images

Parameters:
output -
original -
colourChoiceStrategy -
Returns:

colourAttributes

private static java.awt.image.BufferedImage colourAttributes(int xMax,
                                                             int yMax,
                                                             java.awt.image.BufferedImage output,
                                                             java.awt.image.BufferedImage original,
                                                             ColourChoiceStrategy colourChoiceStrategy)
Colours the Spectrum attribute blocks by selecting xMax by yMax parts of the output image (i.e. usually 8x8 pixels), chooses the most popular two colours. The colour choice strategy then decides how to colour individual pixels based on these two colours. Note it is expected that this method will be called AFTER the pixels have been changed to Spectrum colours.

Parameters:
xMax -
yMax -
output -
colourChoiceStrategy -
Returns:

isBrightSet

public static boolean isBrightSet(int argb)
Determines whether the colour is from the Spectrum's bright or half bright colour set.

Parameters:
argb -
Returns:

changeContrast

public static java.awt.image.BufferedImage changeContrast(java.awt.image.BufferedImage img,
                                                          float amount)
Changes the contrast of an image

Parameters:
img -
amount -
Returns:

changePixelContrast

private static int changePixelContrast(int pixel,
                                       float c)
Changes the contrast of an individual pixel by a given amount.

Parameters:
pixel -
c -
Returns:

changeBrightness

public static java.awt.image.BufferedImage changeBrightness(java.awt.image.BufferedImage img,
                                                            float amount)
Changes brightness by increasing all pixel values by a given amount

Parameters:
img -
amount -
Returns:

changePixelBrightness

private static int changePixelBrightness(int pixel,
                                         float amount)
Changes brightness by increasing the pixel value by a given amount

Parameters:
pixel -
amount -
Returns:

changeSaturation

public static java.awt.image.BufferedImage changeSaturation(java.awt.image.BufferedImage img,
                                                            float amount)
Changes image saturation by a given amount (0-1 range)

Parameters:
img -
amount -
Returns:

changePixelSaturation

private static int changePixelSaturation(int pixel,
                                         float amount)
Changes the saturation of an individual pixel by the given amount (0-1 range)

Parameters:
pixel -
amount -
Returns:

correctRange

static float correctRange(float value,
                          int low,
                          int high)
Ensures a value is within a given range. If it exceeds or is below it is set to the high value or low value respectively

Parameters:
value -
low -
high -
Returns:

intToRgbComponents

public static int[] intToRgbComponents(int rgb)

intToAlphaRgb

public static int intToAlphaRgb(int[] rgb)
Convert individual RGB components into a 32 bit ARGB value

Parameters:
rgb -
Returns:

intToAlphaRgb

public static int intToAlphaRgb(int red,
                                int green,
                                int blue)
Convert individual RGB components into a 32 bit ARGB value

Parameters:
red -
green -
blue -
Returns:

correctRange

private static int correctRange(int channel)
Corrects and individual colour channel value's range to 0>channel<255

Parameters:
channel -
Returns:

isBlack

public static boolean isBlack(int red,
                              int green,
                              int blue)
Determines whether a pixel is closer to black (than white)

Parameters:
red -
green -
blue -
Returns:

getMonochromeColour

public static int getMonochromeColour(int rgb,
                                      int ink,
                                      int paper)
Based on the darkness of the pixel colour determines whether a pixel is ink or paper and returns that colour. Used for converting colour to monochrome based on whether a pixel can be considered black using the isBlack threshold.

Parameters:
rgb -
ink -
paper -
Returns:

getMonochromeColour

public static int getMonochromeColour(int red,
                                      int green,
                                      int blue,
                                      int ink,
                                      int paper)
Based on the darkness of the pixel colour determines whether a pixel is ink or paper and returns that colour. Used for converting colour to monochrome based on whether a pixel can be considered black using the isBlack threshold.

Parameters:
red -
green -
blue -
ink -
paper -
Returns: