1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// Color deprecated methods
use crate::Color;
use alloc::string::String;
#[cfg(not(feature = "std"))]
use num_traits::float::Float;
impl Color {
#[deprecated = "Use [new](#method.new) instead."]
/// Arguments:
///
/// * `r`: Red value [0..1]
/// * `g`: Green value [0..1]
/// * `b`: Blue value [0..1]
pub fn from_rgb(r: f32, g: f32, b: f32) -> Self {
Self { r, g, b, a: 1.0 }
}
#[deprecated = "Use [new](#method.new) instead."]
/// Arguments:
///
/// * `r`: Red value [0..1]
/// * `g`: Green value [0..1]
/// * `b`: Blue value [0..1]
/// * `a`: Alpha value [0..1]
pub fn from_rgba(r: f32, g: f32, b: f32, a: f32) -> Self {
Self { r, g, b, a }
}
#[deprecated = "Use [from_rgba8](#method.from_rgba8) instead."]
/// Arguments:
///
/// * `r`: Red value [0..255]
/// * `g`: Green value [0..255]
/// * `b`: Blue value [0..255]
pub fn from_rgb_u8(r: u8, g: u8, b: u8) -> Self {
Self {
r: r as f32 / 255.0,
g: g as f32 / 255.0,
b: b as f32 / 255.0,
a: 1.0,
}
}
#[deprecated = "Use [from_rgba8](#method.from_rgba8) instead."]
/// Arguments:
///
/// * `r`: Red value [0..255]
/// * `g`: Green value [0..255]
/// * `b`: Blue value [0..255]
/// * `a`: Alpha value [0..255]
pub fn from_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Self {
Self {
r: r as f32 / 255.0,
g: g as f32 / 255.0,
b: b as f32 / 255.0,
a: a as f32 / 255.0,
}
}
#[deprecated = "Use [from_linear_rgba](#method.from_linear_rgba) instead."]
/// Arguments:
///
/// * `r`: Red value [0..1]
/// * `g`: Green value [0..1]
/// * `b`: Blue value [0..1]
pub fn from_linear_rgb(r: f32, g: f32, b: f32) -> Self {
Self::from_linear_rgba(r, g, b, 1.0)
}
#[deprecated = "Use [from_linear_rgba8](#method.from_linear_rgba8) instead."]
/// Arguments:
///
/// * `r`: Red value [0..255]
/// * `g`: Green value [0..255]
/// * `b`: Blue value [0..255]
pub fn from_linear_rgb_u8(r: u8, g: u8, b: u8) -> Self {
Self::from_linear_rgba(r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0, 1.0)
}
#[deprecated = "Use [from_linear_rgba8](#method.from_linear_rgba8) instead."]
/// Arguments:
///
/// * `r`: Red value [0..255]
/// * `g`: Green value [0..255]
/// * `b`: Blue value [0..255]
/// * `a`: Alpha value [0..255]
pub fn from_linear_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Self {
Self::from_linear_rgba(
r as f32 / 255.0,
g as f32 / 255.0,
b as f32 / 255.0,
a as f32 / 255.0,
)
}
#[deprecated = "Use [from_hsva](#method.from_hsva) instead."]
/// Arguments:
///
/// * `h`: Hue angle [0..360]
/// * `s`: Saturation [0..1]
/// * `v`: Value [0..1]
pub fn from_hsv(h: f32, s: f32, v: f32) -> Self {
Self::from_hsva(h, s, v, 1.0)
}
#[deprecated = "Use [from_hsla](#method.from_hsla) instead."]
/// Arguments:
///
/// * `h`: Hue angle [0..360]
/// * `s`: Saturation [0..1]
/// * `l`: Lightness [0..1]
pub fn from_hsl(h: f32, s: f32, l: f32) -> Self {
Self::from_hsla(h, s, l, 1.0)
}
#[deprecated = "Use [from_hwba](#method.from_hwba) instead."]
/// Arguments:
///
/// * `h`: Hue angle [0..360]
/// * `w`: Whiteness [0..1]
/// * `b`: Blackness [0..1]
pub fn from_hwb(h: f32, w: f32, b: f32) -> Self {
Self::from_hwba(h, w, b, 1.0)
}
#[deprecated = "Use [from_oklaba](#method.from_oklaba) instead."]
/// Arguments:
///
/// * `l`: Perceived lightness
/// * `a`: How green/red the color is
/// * `b`: How blue/yellow the color is
pub fn from_oklab(l: f32, a: f32, b: f32) -> Self {
Self::from_oklaba(l, a, b, 1.0)
}
#[deprecated = "Use [from_laba](#method.from_laba) instead."]
/// Arguments:
///
/// * `l`: Lightness
/// * `a`: Distance along the `a` axis
/// * `b`: Distance along the `b` axis
/// * `alpha`: Alpha [0..1]
pub fn from_lab(l: f32, a: f32, b: f32, alpha: f32) -> Self {
Self::from_laba(l, a, b, alpha)
}
#[deprecated = "Use [to_laba](#method.to_laba) instead."]
/// Returns: `[l, a, b, alpha]`
pub fn to_lab(&self) -> [f32; 4] {
self.to_laba()
}
#[deprecated = "Use [from_lcha](#method.from_lcha) instead."]
/// Arguments:
///
/// * `l`: Lightness
/// * `c`: Chroma
/// * `h`: Hue angle in radians
/// * `alpha`: Alpha [0..1]
pub fn from_lch(l: f32, c: f32, h: f32, alpha: f32) -> Self {
Self::from_lcha(l, c, h, alpha)
}
#[deprecated = "Use [to_lcha](#method.to_lcha) instead."]
/// Returns: `[l, c, h, alpha]`
pub fn to_lch(&self) -> [f32; 4] {
self.to_lcha()
}
#[deprecated]
/// Returns: `(r, g, b, a)`
///
/// * Red, green, blue and alpha in the range [0..1]
pub fn rgba(&self) -> (f32, f32, f32, f32) {
(self.r, self.g, self.b, self.a)
}
#[deprecated = "Use [to_rgba8](#method.to_rgba8) instead."]
/// Returns: `(r, g, b, a)`
///
/// * Red, green, blue and alpha in the range [0..255]
pub fn rgba_u8(&self) -> (u8, u8, u8, u8) {
(
(self.r * 255.0).round() as u8,
(self.g * 255.0).round() as u8,
(self.b * 255.0).round() as u8,
(self.a * 255.0).round() as u8,
)
}
// --- Since version 0.7.2
#[deprecated = "Use [to_css_hex](#method.to_css_hex) instead."]
/// Get the RGB hexadecimal color string.
pub fn to_hex_string(&self) -> String {
self.to_css_hex()
}
#[deprecated = "Use [to_css_rgb](#method.to_css_rgb) instead."]
/// Get the CSS `rgb()` format string.
pub fn to_rgb_string(&self) -> String {
self.to_css_rgb()
}
}