View source: R/render_gamma_linear.R
| render_gamma_linear | R Documentation |
Convert sRGB-encoded color data to linear light (and vice versa).
render_gamma_linear(color, srgb_to_linear = TRUE, as_hex = FALSE)
color |
A |
srgb_to_linear |
Default |
as_hex |
Default |
Same shape/type as input unless as_hex = TRUE on matrix/array with srgb_to_linear = FALSE,
in which case a character vector of hex codes is returned.
# Numeric RGB vector (sRGB -> linear -> back to sRGB)
srgb_vec = c(0.2, 0.4, 0.6)
linear_vec = render_gamma_linear(srgb_vec)
render_gamma_linear(linear_vec, srgb_to_linear = FALSE)
# Hex input (single color)
linear_from_hex = render_gamma_linear("#336699")
render_gamma_linear(linear_from_hex, srgb_to_linear = FALSE, as_hex = TRUE)
# Greyscale matrix (treated as image plane)
grey_image = matrix(c(0.1, 0.5, 0.9, 0.3), nrow = 2)
linear_grey = render_gamma_linear(grey_image)
render_gamma_linear(linear_grey, srgb_to_linear = FALSE, as_hex = TRUE)
# Array with a single greyscale channel
grey_pixels = array(c(0.2, 0.7), dim = c(1, 2, 1))
linear_grey_arr = render_gamma_linear(grey_pixels)
render_gamma_linear(linear_grey_arr, srgb_to_linear = FALSE, as_hex = TRUE)
# Array with greyscale + alpha
grey_alpha = array(c(0.3, 0.9, 0.6, 0.4), dim = c(1, 2, 2))
linear_grey_alpha = render_gamma_linear(grey_alpha)
render_gamma_linear(linear_grey_alpha, srgb_to_linear = FALSE, as_hex = TRUE)
# RGB array (3 channels)
rgb_pixels = array(
c(
0.2, 0.4, 0.6,
0.7, 0.1, 0.3
),
dim = c(1, 2, 3)
)
linear_rgb = render_gamma_linear(rgb_pixels)
render_gamma_linear(linear_rgb, srgb_to_linear = FALSE, as_hex = TRUE)
# RGBA array (alpha channel preserved)
rgba_pixels = array(
c(
0.2, 0.4, 0.6, 0.5,
0.7, 0.1, 0.3, 0.8
),
dim = c(1, 2, 4)
)
linear_rgba = render_gamma_linear(rgba_pixels)
render_gamma_linear(linear_rgba, srgb_to_linear = FALSE, as_hex = TRUE)
# rayimg input retains metadata and supports hex conversion
linear_img = render_gamma_linear(ray_read_image(rgba_pixels))
render_gamma_linear(linear_img, srgb_to_linear = FALSE, as_hex = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.