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