|
1 | 1 | // devela::color::fns
|
2 | 2 | //
|
3 | 3 |
|
4 |
| -#[cfg(all(feature = "no_std", feature = "dep"))] |
5 |
| -use crate::_dep::libm::Libm; |
| 4 | +#[cfg(feature = "libm")] |
| 5 | +use crate::ops::FloatExt; |
6 | 6 |
|
7 | 7 | /// Applies the `gamma` to an `f32` channel.
|
8 | 8 | #[inline]
|
9 |
| -#[cfg(any(feature = "std", all(feature = "no_std", feature = "dep")))] |
10 |
| -#[cfg_attr( |
11 |
| - feature = "nightly", |
12 |
| - doc(cfg(any(feature = "std", all(feature = "no_std", feature = "dep")))) |
13 |
| -)] |
| 9 | +#[cfg(any(feature = "std", feature = "libm"))] |
| 10 | +#[cfg_attr(feature = "nightly", doc(cfg(any(feature = "std", feature = "libm"))))] |
14 | 11 | pub fn linearize32(nonlinear: f32, gamma: f32) -> f32 {
|
15 | 12 | if nonlinear >= 0.04045 {
|
16 |
| - #[cfg(feature = "std")] |
17 | 13 | return ((nonlinear + 0.055) / (1. + 0.055)).powf(gamma);
|
18 |
| - |
19 |
| - #[cfg(not(feature = "std"))] |
20 |
| - return Libm::<f32>::pow((nonlinear + 0.055) / (1. + 0.055), gamma); |
21 | 14 | } else {
|
22 | 15 | nonlinear / 12.92
|
23 | 16 | }
|
24 | 17 | }
|
25 | 18 |
|
26 | 19 | /// Removes the `gamma` from an `f32` channel.
|
27 | 20 | #[inline]
|
28 |
| -#[cfg(any(feature = "std", all(feature = "no_std", feature = "dep")))] |
29 |
| -#[cfg_attr( |
30 |
| - feature = "nightly", |
31 |
| - doc(cfg(any(feature = "std", all(feature = "no_std", feature = "dep")))) |
32 |
| -)] |
| 21 | +#[cfg(any(feature = "std", feature = "libm"))] |
| 22 | +#[cfg_attr(feature = "nightly", doc(cfg(any(feature = "std", feature = "libm"))))] |
33 | 23 | pub fn nonlinearize32(linear: f32, gamma: f32) -> f32 {
|
34 | 24 | if linear >= 0.0031308 {
|
35 |
| - #[cfg(feature = "std")] |
36 | 25 | return (1.055) * linear.powf(1.0 / gamma) - 0.055;
|
37 |
| - |
38 |
| - #[cfg(not(feature = "std"))] |
39 |
| - return (1.055) * Libm::<f32>::pow(linear, 1.0 / gamma) - 0.055; |
40 | 26 | } else {
|
41 | 27 | 12.92 * linear
|
42 | 28 | }
|
|
0 commit comments