manip_channel {farver}R Documentation

Modify colour space channels in hex-encoded colour strings

Description

This set of functions allows you to modify colours as given by strings, whithout first decoding them. For large vectors of colour values this should provide a considerable speedup.

Usage

set_channel(colour, channel, value, space = "rgb", white = "D65")

add_to_channel(colour, channel, value, space = "rgb", white = "D65")

multiply_channel(colour, channel, value, space = "rgb", white = "D65")

raise_channel(colour, channel, value, space = "rgb", white = "D65")

cap_channel(colour, channel, value, space = "rgb", white = "D65")

get_channel(colour, channel, space = "rgb", white = "D65")

Arguments

colour

A character string giving colours, either as hexadecimal strings or accepted colour names.

channel

The channel to modify or extract as a single letter, or 'alpha' for the alpha channel.

value

The value to modify with

space

The colour space the channel pertains to. Allowed values are: "cmy", "cmyk", "hsl", "hsb", "hsv", "lab" (CIE L*ab), "hunterlab" (Hunter Lab), "lch" (CIE Lch(ab) / polarLAB), "luv", "rgb" (sRGB), "xyz", "yxy" (CIE xyY), or "hcl" (CIE Lch(uv) / polarLuv)

white

The white reference of the channel colour space. Will only have an effect for relative colour spaces such as Lab and luv. Any value accepted by as_white_ref() allowed.

Value

A character vector of the same length as colour (or a numeric vector in the case of get_channel())

See Also

Other encoding and decoding functions: decode_colour, encode_colour

Examples

spectrum <- rainbow(10)

# set a specific channel
set_channel(spectrum, 'r', c(10, 50))
set_channel(spectrum, 'l', 50, space = 'lab')
set_channel(spectrum, 'alpha', c(0.5, 1))

# Add value to channel
add_to_channel(spectrum, 'r', c(10, 50))
add_to_channel(spectrum, 'l', 50, space = 'lab')

# Multiply a channel
multiply_channel(spectrum, 'r', c(10, 50))
multiply_channel(spectrum, 'l', 50, space = 'lab')

# set a lower bound on a channel
raise_channel(spectrum, 'r', c(10, 50))
raise_channel(spectrum, 'l', 20, space = 'lab')

# set an upper bound on a channel
cap_channel(spectrum, 'r', c(100, 50))
cap_channel(spectrum, 'l', 20, space = 'lab')


[Package farver version 2.0.1 Index]