Class ColorTransformGenerator

Direct Known Subclasses:
ColorDeficiencySimulator, DaltonizeGenerator

public abstract class ColorTransformGenerator extends Generator
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 Details

    • deficiency

      protected Deficiency deficiency
    • colorMap

      protected int[] colorMap
    • amount

      protected float amount
    • amountComplement

      protected float amountComplement
    • dynamicAmount

      protected boolean dynamicAmount

      protected final int MAX_ENCODED_VALUE
    • removeGammaCorrectionLUT

      protected float[] removeGammaCorrectionLUT
    • applyGammaCorrectionLUT

      protected int[] applyGammaCorrectionLUT
  • Constructor Details

    • ColorTransformGenerator

      public ColorTransformGenerator(Deficiency colorBlindness)
      Constructor. Compute gamma lookup tables. This is fast and the memory is small.
      colorBlindness -
  • Method Details

    • precalcMonochromaticColorMap

      protected abstract int[] precalcMonochromaticColorMap(Vector sim, float amount)
    • precalcDichromaticColorMap

      protected abstract int[] precalcDichromaticColorMap(Matrix sim, float amount)
    • setAmount

      public ColorTransformGenerator setAmount(float amount)
      Set % of colorblindness. This defaults to 100%. Better to call setDynamicAmount() before calling this.
      amount - : in range [0, 1]
    • setDynamicAmount

      public ColorTransformGenerator setDynamicAmount()
      Indicate to the generator that the amount may change. This enables it to improve performance considerably.
    • 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.
      color -
      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 class Generator
      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.
      img - Processing PImage to be altered.
    • preComputeApplyGammaCorrectionLUT

      protected int[] preComputeApplyGammaCorrectionLUT(int maxEncodedValue)
    • preComputeRemoveGammaCorrectionLUT

      protected float[] preComputeRemoveGammaCorrectionLUT()