1- # ' Conversion between RGB and HLS color spaces
2- # '
3- # ' @param x An integer matrix with 3 rows.
4- # ' @returns An integer matrix of the same size as `x`
5- # ' @rdname rgb-hls
6- # ' @name rgb-hls
7- NULL
8-
9- # ' @rdname rgb-hls
10- # ' @export
11- rgb2hls <- function (x ) azny_rgb_to_hls(floor(x ))
12-
13- # ' @rdname rgb-hls
14- # ' @export
15- hls2rgb <- function (x ) azny_hls_to_rgb(floor(x ))
16-
17- # ' Create a native raster filled with a color
18- # '
19- # ' @param color Color name or hex code.
20- # ' @param width,height A positive integer scalar.
21- # ' @returns A `nativeRaster` object.
22- # ' @export
23- fill_with <- function (color , width , height ) {
24- packed_int <- colorfast :: col_to_int(color [1 ])
25- out <- matrix (packed_int , nrow = height , ncol = width )
26- as_nr(out )
27- }
28-
291# ' Color manipulation
302# '
313# ' @param nr A `nativeRaster` object.
4+ # ' @param lut A 256x3 double matrix in range `[0, 255]`.
325# ' @param intensity A numeric scalar.
336# ' @param depth,shades A positive integer scalar.
347# ' @param gamma A numeric scalar. The gamma exponent.
@@ -42,16 +15,25 @@ fill_with <- function(color, width, height) {
4215# ' @name color-manip
4316NULL
4417
18+ # ' @rdname color-manip
19+ # ' @export
20+ apply_lut1d <- function (nr , lut ) {
21+ if (! all(is.finite(lut )) || ! all(lut > = 0 ) || ! all(lut < = 255 )) {
22+ cli :: cli_abort(" `lut` must be a double matrix in range [0, 255]." )
23+ }
24+ as_nr(azny_lut1d(cast_nr(nr ), nrow(nr ), ncol(nr ), lut ))
25+ }
26+
4527# ' @rdname color-manip
4628# ' @export
4729brighten <- function (nr , intensity ) {
48- as_nr(azny_brighten(nr , nrow(nr ), ncol(nr ), intensity ))
30+ as_nr(azny_brighten(cast_nr( nr ) , nrow(nr ), ncol(nr ), intensity ))
4931}
5032
5133# ' @rdname color-manip
5234# ' @export
5335contrast <- function (nr , intensity ) {
54- as_nr(azny_contrast(nr , nrow(nr ), ncol(nr ), intensity ))
36+ as_nr(azny_contrast(cast_nr( nr ) , nrow(nr ), ncol(nr ), intensity ))
5537}
5638
5739# ' @rdname color-manip
@@ -61,7 +43,7 @@ duotone <- function(nr, color_a = "yellow", color_b = "navy", gamma = 2.2) {
6143 color_b <- colorfast :: col_to_rgb(color_b [1 ])
6244 as_nr(
6345 azny_duotone(
64- nr ,
46+ cast_nr( nr ) ,
6547 nrow(nr ),
6648 ncol(nr ),
6749 as.integer(color_a [, 1 ]),
@@ -74,19 +56,19 @@ duotone <- function(nr, color_a = "yellow", color_b = "navy", gamma = 2.2) {
7456# ' @rdname color-manip
7557# ' @export
7658grayscale <- function (nr ) {
77- as_nr(azny_grayscale(nr , nrow(nr ), ncol(nr )))
59+ as_nr(azny_grayscale(cast_nr( nr ) , nrow(nr ), ncol(nr )))
7860}
7961
8062# ' @rdname color-manip
8163# ' @export
8264hue_rotate <- function (nr , rad ) {
83- as_nr(azny_hue_rotate(nr , nrow(nr ), ncol(nr ), rad ))
65+ as_nr(azny_hue_rotate(cast_nr( nr ) , nrow(nr ), ncol(nr ), rad ))
8466}
8567
8668# ' @rdname color-manip
8769# ' @export
8870invert <- function (nr ) {
89- as_nr(azny_invert(nr , nrow(nr ), ncol(nr )))
71+ as_nr(azny_invert(cast_nr( nr ) , nrow(nr ), ncol(nr )))
9072}
9173
9274# ' @rdname color-manip
@@ -96,7 +78,7 @@ linocut <- function(nr, ink = "navy", paper = "snow", threshold = 0.4) {
9678 paper <- colorfast :: col_to_rgb(paper [1 ])
9779 as_nr(
9880 azny_linocut(
99- nr ,
81+ cast_nr( nr ) ,
10082 nrow(nr ),
10183 ncol(nr ),
10284 as.integer(ink [, 1 ]),
@@ -109,25 +91,25 @@ linocut <- function(nr, ink = "navy", paper = "snow", threshold = 0.4) {
10991# ' @rdname color-manip
11092# ' @export
11193posterize <- function (nr , shades = 4 ) {
112- as_nr(azny_posterize(nr , nrow(nr ), ncol(nr ), shades ))
94+ as_nr(azny_posterize(cast_nr( nr ) , nrow(nr ), ncol(nr ), shades ))
11395}
11496
11597# ' @rdname color-manip
11698# ' @export
11799reset_alpha <- function (nr , alpha = 1 ) {
118- as_nr(azny_reset_alpha(nr , nrow(nr ), ncol(nr ), alpha ))
100+ as_nr(azny_reset_alpha(cast_nr( nr ) , nrow(nr ), ncol(nr ), alpha ))
119101}
120102
121103# ' @rdname color-manip
122104# ' @export
123105saturate <- function (nr , intensity ) {
124- as_nr(azny_saturate(nr , nrow(nr ), ncol(nr ), intensity ))
106+ as_nr(azny_saturate(cast_nr( nr ) , nrow(nr ), ncol(nr ), intensity ))
125107}
126108
127109# ' @rdname color-manip
128110# ' @export
129111sepia <- function (nr , intensity , depth = 20 ) {
130- as_nr(azny_sepia(nr , nrow(nr ), ncol(nr ), intensity , depth ))
112+ as_nr(azny_sepia(cast_nr( nr ) , nrow(nr ), ncol(nr ), intensity , depth ))
131113}
132114
133115# ' @rdname color-manip
@@ -136,7 +118,7 @@ set_matte <- function(nr, color = "green") {
136118 rgb_int <- colorfast :: col_to_rgb(color [1 ])
137119 as_nr(
138120 azny_set_matte(
139- nr ,
121+ cast_nr( nr ) ,
140122 nrow(nr ),
141123 ncol(nr ),
142124 as.integer(rgb_int [, 1 ])
@@ -147,11 +129,11 @@ set_matte <- function(nr, color = "green") {
147129# ' @rdname color-manip
148130# ' @export
149131solarize <- function (nr , threshold = 0.5 ) {
150- as_nr(azny_solarize(nr , nrow(nr ), ncol(nr ), threshold ))
132+ as_nr(azny_solarize(cast_nr( nr ) , nrow(nr ), ncol(nr ), threshold ))
151133}
152134
153135# ' @rdname color-manip
154136# ' @export
155137unpremul <- function (nr , max = 255L ) {
156- as_nr(azny_unpremul(nr , nrow(nr ), ncol(nr ), max ))
138+ as_nr(azny_unpremul(cast_nr( nr ) , nrow(nr ), ncol(nr ), max ))
157139}
0 commit comments