Package colorblind.generators
Class ColorTransformGenerator
java.lang.Object
colorblind.generators.Generator
colorblind.generators.ColorTransformGenerator
- Direct Known Subclasses:
ColorDeficiencySimulator
,DaltonizeGenerator
Base class for all of the color transform generators.
This class provides some default matrix values and implementations of some
useful functions for color blindness simulations and daltonization.
-
Field Summary
Modifier and TypeFieldDescriptionprotected float
protected float
protected int[]
protected int[]
protected Deficiency
protected boolean
protected final int
protected float[]
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract int[]
precalcDichromaticColorMap
(Matrix sim, float amount) protected abstract int[]
precalcMonochromaticColorMap
(Vector sim, float amount) protected int[]
preComputeApplyGammaCorrectionLUT
(int maxEncodedValue) protected float[]
setAmount
(float amount) Set % of colorblindness.Indicate to the generator that the amount may change.int
transformColor
(int color) Transform an individual color using the colorMap.processing.core.PImage
transformPImage
(processing.core.PImage img) Copy an arbitrary PImage object and transform it using the colorMap.void
transformPixels
(int[] pixels) Called by ColorBlindness routine to transform every pixel in the pixel array.
-
Field Details
-
deficiency
-
colorMap
protected int[] colorMap -
amount
protected float amount -
amountComplement
protected float amountComplement -
dynamicAmount
protected boolean dynamicAmount -
MAX_ENCODED_VALUE
protected final int MAX_ENCODED_VALUE -
removeGammaCorrectionLUT
protected float[] removeGammaCorrectionLUT -
applyGammaCorrectionLUT
protected int[] applyGammaCorrectionLUT
-
-
Constructor Details
-
ColorTransformGenerator
Constructor. Compute gamma lookup tables. This is fast and the memory is small.- Parameters:
colorBlindness
-
-
-
Method Details
-
precalcMonochromaticColorMap
-
precalcDichromaticColorMap
-
setAmount
Set % of colorblindness. This defaults to 100%. Better to call setDynamicAmount() before calling this.- Parameters:
amount
- : in range [0, 1]- Returns:
-
setDynamicAmount
Indicate to the generator that the amount may change. This enables it to improve performance considerably.- Returns:
-
transformColor
public int transformColor(int color) Transform an individual color using the colorMap. Preserves the input color's transparency or alpha channel. Note it is not so efficient to call this for thousands of colors per frame.- Parameters:
color
-- Returns:
- transformed color using colorMap.
-
transformPixels
public void transformPixels(int[] pixels) Called by ColorBlindness routine to transform every pixel in the pixel array. Alters pixels in place. This does not support transparency. The transformed colors will have 0xFF as the alpha channel, regardless of what the value was in the original color.- Specified by:
transformPixels
in classGenerator
- Parameters:
pixels
- Processing pixel array.
-
transformPImage
public processing.core.PImage transformPImage(processing.core.PImage img) Copy an arbitrary PImage object and transform it using the colorMap. Original image is unaltered. Unlike transformPixels, this supports transparency. The transformed colors will have the same alpha channel as the original image. Maintaining the alpha channel makes this noticeably slower, but that's OK because this should be called only once for an image, not once per frame. If you want faster performance and don't care about the alpha channel, use transformPixels(img.pixels) instead.- Parameters:
img
- Processing PImage to be altered.- Returns:
-
preComputeApplyGammaCorrectionLUT
protected int[] preComputeApplyGammaCorrectionLUT(int maxEncodedValue) -
preComputeRemoveGammaCorrectionLUT
protected float[] preComputeRemoveGammaCorrectionLUT()
-