Skip to contents

convert R color to HCL color matrix

Usage

col2hcl(
  x,
  maxColorValue = 255,
  model = getOption("jam.model", c("hcl", "polarLUV", "polarLAB")),
  ...
)

Arguments

x

character R compatible color, either a color name, hex value, or a mixture of the two. Any value compatible with grDevices::col2rgb().

maxColorValue

numeric maximum value to return, useful when the downstream alpha range should be 255. By default maxValue=1 is returned.

model

character color model to use

  • "hcl" to use farver HCL

  • "polarLUV" for the standard R conventional HCL,

  • "polarLAB" which uses the LAB-based HCL values.

...

additional arguments are ignored.

Value

numeric matrix with H, C, L values.

Details

This function takes an R color and converts to an HCL matrix, using the colorspace package, and colorspace::RGB() and colorspace::polarLUV() functions. It is also used to maintain alpha transparency, to enable interconversion via other color manipulation functions as well.

When model="hcl" this function uses farver::decode_colour() and bypasses colorspace. In future the colorspace dependency will likely be removed in favor of using farver. In any event, model="hcl" is equivalent to using model="polarLUV" and fixup=TRUE, except that it should be much faster.

Examples

col2hcl("#FF000044")
#>              [,1]
#> H      12.1743993
#> C     179.0489832
#> L      53.2407941
#> alpha   0.2666667