Class Shaders

java.lang.Object
uk.ac.starlink.ttools.plot.Shaders

public class Shaders extends Object
Provides some implementations of the Shader interface.

Many other lookup tables are available. See for instance http://www.ncl.ucar.edu/Document/Graphics/color_table_gallery.shtml. The utility class LutSteal is available to help turn these into lut files that can be used here.

Since:
5 Jun 2007
Author:
Mark Taylor
  • Field Details

    • LUTFILES_PROPERTY

      public static final String LUTFILES_PROPERTY
      Property containing a File.pathSeparator-separated list of text files containing custom lookup tables. Each line should contain three space-separated floating point values between zero and one giving the Red, Green and Blue components of a colour.
      See Also:
    • FIX_RED

      public static final Shader FIX_RED
      Fixes red level at parameter value.
    • FIX_GREEN

      public static final Shader FIX_GREEN
      Fixes green level at parameter value.
    • FIX_BLUE

      public static final Shader FIX_BLUE
      Fixes blue level at parameter value.
    • SCALE_RED

      public static final Shader SCALE_RED
      Scales red level by parameter value.
    • SCALE_GREEN

      public static final Shader SCALE_GREEN
      Scales green level by parameter value.
    • SCALE_BLUE

      public static final Shader SCALE_BLUE
      Scales blue level by parameter value.
    • FIX_Y

      public static final Shader FIX_Y
      Fixes Y in YUV colour space.
    • FIX_U

      public static final Shader FIX_U
      Fixes U in YUV colour space.
    • FIX_V

      public static final Shader FIX_V
      Fixes V in YUV colour space.
    • SCALE_Y

      public static final Shader SCALE_Y
      Scales Y in YUV colour space.
    • HSV_H

      public static final Shader HSV_H
      Fixes H in HSV colour space.
    • HSV_S

      public static final Shader HSV_S
      Fixes S in HSV colour space.
    • HSV_V

      public static final Shader HSV_V
      Fixes V in HSV colour space.
    • SCALE_H

      public static final Shader SCALE_H
      Scales H in HSV colour space.
    • SCALE_S

      public static final Shader SCALE_S
      Scales S in HSV colour space.
    • SCALE_V

      public static final Shader SCALE_V
      Scales V in HSV colour space.
    • RED_BLUE

      public static final Shader RED_BLUE
      Interpolates between red (0) and blue (1).
    • CYAN_MAGENTA

      public static final Shader CYAN_MAGENTA
      Interpolates between cyan (0) and magenta (1).
    • WHITE_BLACK

      public static final Shader WHITE_BLACK
      Interpolates between white (0) and black (1).
    • BLACK_WHITE

      public static final Shader BLACK_WHITE
      Interpolates between black (0) and white (1).
    • SRON_RAINBOW

      public static final Shader SRON_RAINBOW
      Rainbow shader copied from SRON technical note SRON/EPS/TN/09-002.
    • CUBEHELIX

      public static final Shader CUBEHELIX
      Standard cubehelix shader.
    • CUBEHELIX2

      public static final Shader CUBEHELIX2
      Enhanced hue cubehelix shader.
    • CUBEHELIX3

      public static final Shader CUBEHELIX3
      Lurid cubehelix shader.
    • LUT_AIPS0

      public static final Shader LUT_AIPS0
      Shader based on lookup table Aips0.
    • LUT_BACKGR

      public static final Shader LUT_BACKGR
      Shader based on lookup table Backgr.
    • LUT_COLOR

      public static final Shader LUT_COLOR
      Shader based on lookup table Color.
    • LUT_HEAT

      public static final Shader LUT_HEAT
      Shader based on lookup table Heat.
    • LUT_IDL2

      public static final Shader LUT_IDL2
      Shader based on lookup table IDL2.
    • LUT_IDL4

      public static final Shader LUT_IDL4
      Shader based on lookup table IDL4.
    • LUT_ISOPHOT

      public static final Shader LUT_ISOPHOT
      Shader based on lookup table Isophot.
    • LUT_LIGHT

      public static final Shader LUT_LIGHT
      Shader based on lookup table Light.
    • LUT_MANYCOL

      public static final Shader LUT_MANYCOL
      Shader based on lookup table Manycol.
    • LUT_PASTEL

      public static final Shader LUT_PASTEL
      Shader based on lookup table Pastel.
    • LUT_RAINBOW

      public static final Shader LUT_RAINBOW
      Shader based on lookup table Rainbow.
    • LUT_RAMP

      public static final Shader LUT_RAMP
      Shader based on lookup table Ramp.
    • LUT_RANDOM

      public static final Shader LUT_RANDOM
      Shader based on lookup table Random.
    • LUT_REAL

      public static final Shader LUT_REAL
      Shader based on lookup table Real.
    • LUT_SMOOTH

      public static final Shader LUT_SMOOTH
      Shader based on lookup table Smooth.
    • LUT_STAIRCASE

      public static final Shader LUT_STAIRCASE
      Shader based on lookup table Staircase.
    • LUT_STANDARD

      public static final Shader LUT_STANDARD
      Shader based on lookup table Standard.
    • LUT_ACCENT

      public static final Shader LUT_ACCENT
      Shader based on lookup table Accent.
    • LUT_COLD

      public static final Shader LUT_COLD
      Shader based on lookup table Cold.
    • LUT_GLNEMO2

      public static final Shader LUT_GLNEMO2
      Shader copied from glNemo2 application.
    • LUT_GNUPLOT

      public static final Shader LUT_GNUPLOT
      Shader copied from Matplotlib Gnuplot lookup table.
    • LUT_GNUPLOT2

      public static final Shader LUT_GNUPLOT2
      Shader copied from Matplotlib Gnuplot2 lookup table.
    • LUT_SPECXB2Y

      public static final Shader LUT_SPECXB2Y
      Shader copied from SPECX blue2yellow lookup table.
    • LUT_BRG

      public static final Shader LUT_BRG
      Shader copied from Matplotlib BRG lookup table.
    • LUT_PAIRED

      public static final Shader LUT_PAIRED
      Shader copied from Matplotlib Paired lookup table.
    • LUT_RAINBOW3

      public static final Shader LUT_RAINBOW3
      Shader copied from Matplotlib gist_rainbow lookup table.
    • LUT_SET1

      public static final Shader LUT_SET1
      Shader copied from Matplotlib Set1 lookup table.
    • LUT_MPL2MAGMA

      public static final Shader LUT_MPL2MAGMA
      Shader copied from Matplotlib 2.0 Magma lookup table.
    • LUT_MPL2INFERNO

      public static final Shader LUT_MPL2INFERNO
      Shader copied from Matplotlib 2.0 Inferno lookup table.
    • LUT_MPL2PLASMA

      public static final Shader LUT_MPL2PLASMA
      Shader copied from Matplotlib 2.0 Plasma lookup table.
    • LUT_MPL2VIRIDIS

      public static final Shader LUT_MPL2VIRIDIS
      Shader copied from Matplotlib 2.0 Viridis lookup table.
    • LUT_HOTCOLD

      public static final Shader LUT_HOTCOLD
      Diverging hot-cold shader provided by Daniel Michalik.
    • LUT_CIVIDIS

      public static final Shader LUT_CIVIDIS
      Cividis shader derived from DOI:10.1371/journal.pone.0199239.
    • LUT_PAINBOW

      public static final Shader LUT_PAINBOW
      Painbow shader scraped from https://xkcd.com/2537/. Thanks Randall.
    • LUT_GUPPY

      public static final Shader LUT_GUPPY
      Guppy diverging shader from CMasher.
    • LUT_ICEBURN

      public static final Shader LUT_ICEBURN
      Iceburn diverging shader from CMasher.
    • LUT_REDSHIFT

      public static final Shader LUT_REDSHIFT
      Redshift diverging shader from CMasher.
    • LUT_PRIDE

      public static final Shader LUT_PRIDE
      Pride diverging shader from CMasher.
    • LUT_INFINITY

      public static final Shader LUT_INFINITY
      Infinity cyclic shader from CMasher.
    • LUT_COSMIC

      public static final Shader LUT_COSMIC
      Cosmic sequential shader from CMasher.
    • LUT_EMBER

      public static final Shader LUT_EMBER
      Ember sequential shader from CMasher.
    • LUT_GOTHIC

      public static final Shader LUT_GOTHIC
      Gothic sequential shader from CMasher.
    • LUT_RAINFOREST

      public static final Shader LUT_RAINFOREST
      Rainforest sequential shader from CMasher.
    • LUT_VOLTAGE

      public static final Shader LUT_VOLTAGE
      Voltage sequential shader from CMasher.
    • LUT_BUBBLEGUM

      public static final Shader LUT_BUBBLEGUM
      Bubblegum sequential shader from CMasher.
    • LUT_GEM

      public static final Shader LUT_GEM
      Gem sequential shader from CMasher.
    • LUT_CHROMA

      public static final Shader LUT_CHROMA
      Chroma sequential shader from CMasher.
    • LUT_NEON

      public static final Shader LUT_NEON
      Neon sequential shader from CMasher.
    • LUT_TROPICAL

      public static final Shader LUT_TROPICAL
      Tropical sequential shader from CMasher.
    • LUT_SHADERS

      public static final Shader[] LUT_SHADERS
      Selection of lookup table-based shaders.
    • BREWER_BUGN

      public static final Shader BREWER_BUGN
      ColorBrewer sequential blue-green shader.
    • BREWER_BUPU

      public static final Shader BREWER_BUPU
      ColorBrewer sequential blue-purple shader.
    • BREWER_ORRD

      public static final Shader BREWER_ORRD
      ColorBrewer sequential orange-red shader.
    • BREWER_PUBU

      public static final Shader BREWER_PUBU
      ColorBrewer sequential purple-blue shader.
    • BREWER_PURD

      public static final Shader BREWER_PURD
      ColorBrewer sequential purple-red shader.
    • BREWER_RDBU

      public static final Shader BREWER_RDBU
      ColorBrewer diverging red-blue shader.
    • BREWER_PIYG

      public static final Shader BREWER_PIYG
      ColorBrewer diverging pink-green shader.
    • BREWER_BRBG

      public static final Shader BREWER_BRBG
      ColorBrewer diverging brown-blue-green shader.
    • HCL_POLAR

      public static final Shader HCL_POLAR
      Hue-chroma-luminance cyclic shader. Got from hclwizard.org with parameters: qualitative, H1=0 H2=351, N=40, C1=90, L1=60
    • DFLT_GRID_SHADER

      public static final Shader DFLT_GRID_SHADER
      Shader used by default for the transverse axis of non-absolute ramps.
    • NULL

      public static final Shader NULL
      Shader which does nothing.
    • TRANSPARENCY

      public static final Shader TRANSPARENCY
      Scales alpha channel by parameter value.
    • FIX_INTENSITY

      public static final Shader FIX_INTENSITY
      Shader which sets intensity.
    • SCALE_INTENSITY

      public static final Shader SCALE_INTENSITY
      Shader which scales intensity.
    • FADE_BLACK

      public static final Shader FADE_BLACK
      Shader which interpolates between the base colour and black.
    • FADE_WHITE

      public static final Shader FADE_WHITE
      Shader which interpolates between the base colour and white.
    • FIX_HUE

      public static final Shader FIX_HUE
      Shader which fixes hue.
  • Constructor Details

    • Shaders

      public Shaders()
  • Method Details

    • createInterpolationShader

      public static Shader createInterpolationShader(String name, Color color0, Color color1)
      Constructs a shader which interpolates smoothly between two colours.
      Parameters:
      name - name
      color0 - colour corresponding to parameter value 0
      color1 - colour corresponding to parameter value 1
      Returns:
      shader
    • createInterpolationShader

      public static Shader createInterpolationShader(String name, Color[] colors)
      Constructs a shader which interpolates between a sequence of colours. The shading is defined by a sequence of linear segments.
      Parameters:
      name - name
      colors - sequence of colours; value 0 corresponds to the first colour and value 1 corresponds to the last
      Returns:
      shader
    • createFixedShader

      public static Shader createFixedShader(String name, Color color)
      Creates a shader which always returns a fixed colour regardless of the supplied parameter.
      Parameters:
      name - shader name
      color - fixed output colour
      Returns:
      fixed colour shader
    • createMaskShader

      public static Shader createMaskShader(String name, float minMask, float maxMask, boolean sense)
      Creates a shader which for each value either does nothing to a colour or turns it completely transparent. The pass range is specified by a minimum and maximum value and a sense.
      Parameters:
      name - shader name
      minMask - minimum value (exclusive) for range
      maxMask - maximum value (exclusive) for range
      sense - if true, values outside the range are transparent, if false, values within the range are transparent
    • getCustomShaders

      public static Shader[] getCustomShaders()
      Returns an array of any custom shaders specified by the LUTFILES_PROPERTY property.
      Returns:
      array of zero or more custom shaders
    • invert

      public static Shader invert(Shader shader)
      Returns a shader which runs in the opposite direction to a given one.
      Parameters:
      shader - base shader
      Returns:
      inverted version
    • fade

      public static Shader fade(Shader shader, float scaleAlpha)
      Returns a shader which scales the alpha value of all its colours by a given constant.
      Parameters:
      shader - input shader
      scaleAlpha - alpha scaling factor, in range 0..1
      Returns:
      fading shader; same as input if scaleAlpha==1
    • rename

      public static Shader rename(Shader shader, String name)
      Returns a shader which delegates all behaviour to a supplied base instance, except it has a given name.
      Parameters:
      shader - base shader
      name - new name
      Returns:
      new shader
    • stretch

      public static Shader stretch(Shader shader, float frac0, float frac1)
      Returns a shader which corresponds to a sub-range of a given shader.
      Parameters:
      shader - base shader
      frac0 - parameter value in base shader corresponding to value 0 in this one (must be in range 0-1)
      frac1 - parameter value in base shader corresponding to value 1 in this one (must be in range 0-1)
      Returns:
      new shader
    • quantise

      public static Shader quantise(Shader shader, double nlevel)
      Returns a shader which splits the colour map into a set of discrete levels.
      Parameters:
      shader - base shader
      nlevel - number of discrete colour levels required
      Returns:
      new shader
    • applyShader

      public static Shader applyShader(Shader shader, Color baseColor, int nsample)
      Creates a shader by applying an existing shader to a given base colour. This only does useful work if the existing shader is non-absolute.
      Parameters:
      shader - shader to apply (presumably non-absolute)
      baseColor - colour to which the shader will be applied
      nsample - number of samples in the lookup table
      Returns:
      new absolute shader
    • create2dIcon

      public static Icon create2dIcon(Shader xShader, Shader yShader, boolean xFirst, Color baseColor, int width, int height, int xpad, int ypad)
      Constructs an icon which represents two shaders in two dimensions.
      Parameters:
      xShader - shader for X direction
      yShader - shader for Y direction
      xFirst - true if X shader is to be applied first
      baseColor - base colour for the shaders to work on
      width - total width of the icon
      height - total height of the icon
      xpad - internal padding in the X direction
      ypad - internal padding in the Y direction
      Returns:
      icon
    • createShaderIcon

      public static Icon createShaderIcon(Shader shader, Shader gridShader, boolean horizontal, int width, int height, int xpad, int ypad)
      Returns an icon which displays a shader in action, using an explicitly provided grid shader.
      Parameters:
      shader - shader to illustrate
      gridShader - defines the pixels along the transverse direction of the shader; ignored (may be null) for absolute shaders
      horizontal - true for shading running horizontally, false for vertically
      width - total icon width in pixels
      height - total icon height in pixels
      xpad - internal padding in the X direction
      ypad - internal padding in the Y direction
      Returns:
      icon
    • createShaderIcon

      public static Icon createShaderIcon(Shader shader, boolean horizontal, int width, int height, int xpad, int ypad)
      Returns an icon which displays a shader in action, using a default grid shader if required.
      Parameters:
      shader - shader to illustrate
      horizontal - true for shading running horizontally, false for vertically
      width - total icon width in pixels
      height - total icon height in pixels
      xpad - internal padding in the X direction
      ypad - internal padding in the Y direction
      Returns:
      icon
    • isTransparent

      public static boolean isTransparent(Shader shader)
      Indicates whether the given shader object is capable of introducing transparency into a colour (modifying rgba[3] from 1 to a lower value).
      Parameters:
      shader - shader to test
      Returns:
      true if shader adjusts transparency or is null