Automate

Automate

Make your phone or tablet smarter with automation

Get it on Google Play

colorRecode

value colorRecode(color, transform, alpha)

Returns color transcoded according transform, optionally with alpha.

Used for converting between color models, decoding (unpack) a single color value into an array of color components, encoding (pack) an array of components into a single color value, or any combination thereof.

Conversion between every color model is currently not supported and may fail, e.g. RGB and CMYK since that can’t be done accurately without device dependent color profiles, etc..

Transform “stages”, names are case-insensitive:

  • cmykCMYK color model, where 4 components represent Cyan [0,1], Magenta [0,1], Yellow [0,1] and Black [0,1]. Used as first “stage” to specify the initial color components as this model, otherwise for converting to this model.
  • grayscaleGrayscale color model, where a single component represent lightness [0,1]. Used as first “stage” to specify the initial color components as this model, otherwise for converting to this model.
  • rgbRGB color model, where 3 components represent Red [0,1], Green [0,1] and Blue [0,1]. Used as first “stage” to specify or decode the initial color into components as/of this model, otherwise for converting to this model. Can be followed by pack or hex for encoding into a single color value.
  • hsvHSV color model, where 3 components represent Hue [0,1], Saturation [0,1] and (lightness) Value [0,1]. Used as first “stage” to specify the initial color components as this model, otherwise for converting to this model.
  • ycbcrYCbCr color space, where 3 components represent luminance (Y) [0,1], blue-difference chroma (CB) [-0.5,+0.5] and red-difference chroma (CR) [-0.5,+0.5]. Used as first “stage” to specify the initial color components as this model, otherwise for converting to this model.
  • ycck — YCCK color model, used to encode CMYK in YCbCr, where 4 components represent luminance (Y) [0,1], blue-difference chroma (CB) [-0.5,+0.5], red-difference chroma (CR) [-0.5,+0.5] and Black [0,1] Used as first “stage” to specify the initial color components as this model, otherwise for converting to this model.
  • pack — Encode components into a single number. Currently only allowed after a RGB color model, for encoding it into a 32-bit ARGB color number.
  • hex — Encode components into a single hexadecimal text. Currently only allowed after a RGB color model, for encoding it into a hexadecimal text, i.e. hexEncode, of its 32-bit ARGB color number.

Examples

  • Convert YCbCr to RGB components:
    colorRecode([0.299,-0.1688,0.5], "ycbcr rgb") returns [1,0,0]
  • Decode a 32-bit ARGB color number into its components:
    colorRecode(0xFFFF0000, "rgb") returns [1,0,0]
  • Decode and convert a 32-bit ARGB color number into separate HSV components:
    colorRecode(0xFFFF0000, "rgb hsv") returns [0,1,1]
  • Convert and encode HSV components into a 32-bit ARGB color number:
    colorRecode([0,1,1], "hsv rgb pack") returns 0xFFFFFF00
  • Encode RGB components, with 50% alpha, into a ARGB hexadecimal text:
    colorRecode([1,0,0], "rgb hex", 0.5) returns "80ff0000"

Parameters

  1. colorarray of color components, or encoded color number or text.
  2. transformtext with space-separated list of one or more transformation “stages”, interpreted from left to right.
  3. alpha — optional alpha (transparency) factor override [0,1].

Returns

Note! This documentation is also accessible within the app from Help & feedback menu.