| 1 | //! The sRGB standard. |
| 2 | |
| 3 | use craterust-analyzer cargo palette 0.7.6 crate/::{ |
| 4 | bool_maskrust-analyzer cargo palette 0.7.6 bool_mask/::LazySelectrust-analyzer cargo palette 0.7.6 bool_mask/LazySelect#, |
| 5 | encodingrust-analyzer cargo palette 0.7.6 encoding/::{FromLinearrust-analyzer cargo palette 0.7.6 encoding/FromLinear#, IntoLinearrust-analyzer cargo palette 0.7.6 encoding/IntoLinear#}, |
| 6 | lumarust-analyzer cargo palette 0.7.6 luma/::LumaStandardrust-analyzer cargo palette 0.7.6 luma/LumaStandard#, |
| 7 | numrust-analyzer cargo palette 0.7.6 num/::{Arithmeticsrust-analyzer cargo palette 0.7.6 num/Arithmetics#, MulAddrust-analyzer cargo palette 0.7.6 num/MulAdd#, MulSubrust-analyzer cargo palette 0.7.6 num/MulSub#, PartialCmprust-analyzer cargo palette 0.7.6 num/PartialCmp#, Powfrust-analyzer cargo palette 0.7.6 num/Powf#, Realrust-analyzer cargo palette 0.7.6 num/Real#}, |
| 8 | rgbrust-analyzer cargo palette 0.7.6 rgb/::{Primariesrust-analyzer cargo palette 0.7.6 rgb/Primaries#, RgbSpacerust-analyzer cargo palette 0.7.6 rgb/RgbSpace#, RgbStandardrust-analyzer cargo palette 0.7.6 rgb/RgbStandard#}, |
| 9 | white_pointrust-analyzer cargo palette 0.7.6 white_point/::{Anyrust-analyzer cargo palette 0.7.6 white_point/Any#, D65rust-analyzer cargo palette 0.7.6 white_point/D65#}, |
| 10 | Mat3rust-analyzer cargo palette 0.7.6 matrix/Mat3#, Yxyrust-analyzer cargo palette 0.7.6 yxy/Yxy#, |
| 11 | }; |
| 12 | |
| 13 | use lookup_tablesrust-analyzer cargo palette 0.7.6 encoding/srgb/lookup_tables/::*; |
| 14 | |
| 15 | mod lookup_tablesrust-analyzer cargo palette 0.7.6 encoding/srgb/lookup_tables/; |
| 16 | |
| 17 | /// The sRGB standard, color space, and transfer function. |
| 18 | /// |
| 19 | /// # As transfer function |
| 20 | /// |
| 21 | /// `Srgb` will not use any kind of approximation when converting from `T` to |
| 22 | /// `T`. This involves calls to `powf`, which may make it too slow for certain |
| 23 | /// applications. |
| 24 | /// |
| 25 | /// There are some specialized cases where it has been optimized: |
| 26 | /// |
| 27 | /// * When converting from `u8` to `f32` or `f64`, while converting to linear |
| 28 | /// space. This uses lookup tables with precomputed values. `f32` will use the |
| 29 | /// table provided by [fast_srgb8::srgb8_to_f32]. |
| 30 | /// * When converting from `f32` or `f64` to `u8`, while converting from linear |
| 31 | /// space. This uses [fast_srgb8::f32_to_srgb8]. |
| 32 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 33 | pub struct Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb#; |
| 34 | |
| 35 | impl<T: Realrust-analyzer cargo palette 0.7.6 num/Real#> Primariesrust-analyzer cargo palette 0.7.6 rgb/Primaries#<T> for Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb# { |
| 36 | fn redrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][`Primaries<T>`]red().() -> Yxyrust-analyzer cargo palette 0.7.6 yxy/Yxy#<Anyrust-analyzer cargo palette 0.7.6 white_point/Any#, T> { |
| 37 | Yxyrust-analyzer cargo palette 0.7.6 yxy/Yxy#::newrust-analyzer cargo palette 0.7.6 yxy/impl#[`Yxy<Wp, T>`]new().( |
| 38 | T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.6400), |
| 39 | T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.3300), |
| 40 | T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.212656), |
| 41 | ) |
| 42 | } |
| 43 | fn greenrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][`Primaries<T>`]green().() -> Yxyrust-analyzer cargo palette 0.7.6 yxy/Yxy#<Anyrust-analyzer cargo palette 0.7.6 white_point/Any#, T> { |
| 44 | Yxyrust-analyzer cargo palette 0.7.6 yxy/Yxy#::newrust-analyzer cargo palette 0.7.6 yxy/impl#[`Yxy<Wp, T>`]new().( |
| 45 | T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.3000), |
| 46 | T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.6000), |
| 47 | T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.715158), |
| 48 | ) |
| 49 | } |
| 50 | fn bluerust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][`Primaries<T>`]blue().() -> Yxyrust-analyzer cargo palette 0.7.6 yxy/Yxy#<Anyrust-analyzer cargo palette 0.7.6 white_point/Any#, T> { |
| 51 | Yxyrust-analyzer cargo palette 0.7.6 yxy/Yxy#::newrust-analyzer cargo palette 0.7.6 yxy/impl#[`Yxy<Wp, T>`]new().( |
| 52 | T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.1500), |
| 53 | T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.0600), |
| 54 | T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.072186), |
| 55 | ) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | impl RgbSpacerust-analyzer cargo palette 0.7.6 rgb/RgbSpace# for Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb# { |
| 60 | type Primariesrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][RgbSpace]Primaries# = Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb#; |
| 61 | type WhitePointrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][RgbSpace]WhitePoint# = D65rust-analyzer cargo palette 0.7.6 white_point/D65#; |
| 62 | |
| 63 | #[rustfmt::skip] |
| 64 | #[inline(always)] |
| 65 | fn rgb_to_xyz_matrixrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][RgbSpace]rgb_to_xyz_matrix().() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Mat3rust-analyzer cargo palette 0.7.6 matrix/Mat3#<f64>> { |
| 66 | // Matrix from http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html |
| 67 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#([ |
| 68 | 0.4124564, 0.3575761, 0.1804375, |
| 69 | 0.2126729, 0.7151522, 0.0721750, |
| 70 | 0.0193339, 0.1191920, 0.9503041, |
| 71 | ]) |
| 72 | } |
| 73 | |
| 74 | #[rustfmt::skip] |
| 75 | #[inline(always)] |
| 76 | fn xyz_to_rgb_matrixrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][RgbSpace]xyz_to_rgb_matrix().() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Mat3rust-analyzer cargo palette 0.7.6 matrix/Mat3#<f64>> { |
| 77 | // Matrix from http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html |
| 78 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#([ |
| 79 | 3.2404542, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.5371385, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.4985314, |
| 80 | -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.9692660, 1.8760108, 0.0415560, |
| 81 | 0.0556434, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.2040259, 1.0572252, |
| 82 | ]) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | impl RgbStandardrust-analyzer cargo palette 0.7.6 rgb/RgbStandard# for Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb# { |
| 87 | type Spacerust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][RgbStandard]Space# = Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb#; |
| 88 | type TransferFnrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][RgbStandard]TransferFn# = Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb#; |
| 89 | } |
| 90 | |
| 91 | impl LumaStandardrust-analyzer cargo palette 0.7.6 luma/LumaStandard# for Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb# { |
| 92 | type WhitePointrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][LumaStandard]WhitePoint# = D65rust-analyzer cargo palette 0.7.6 white_point/D65#; |
| 93 | type TransferFnrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][LumaStandard]TransferFn# = Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb#; |
| 94 | } |
| 95 | |
| 96 | impl<T> IntoLinearrust-analyzer cargo palette 0.7.6 encoding/IntoLinear#<T, T> for Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb# |
| 97 | where |
| 98 | T: Realrust-analyzer cargo palette 0.7.6 num/Real# + Powfrust-analyzer cargo palette 0.7.6 num/Powf# + MulAddrust-analyzer cargo palette 0.7.6 num/MulAdd# + Arithmeticsrust-analyzer cargo palette 0.7.6 num/Arithmetics# + PartialCmprust-analyzer cargo palette 0.7.6 num/PartialCmp# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 99 | T::Maskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#Mask#: LazySelectrust-analyzer cargo palette 0.7.6 bool_mask/LazySelect#<T>, |
| 100 | { |
| 101 | #[inline] |
| 102 | fn into_linearrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][`IntoLinear<T, T>`]into_linear().(x: T) -> T { |
| 103 | // Dividing the constants directly shows performance benefits in benchmarks for this function |
| 104 | lazy_selectrust-analyzer cargo palette 0.7.6 macros/lazy_select/lazy_select!! { |
| 105 | if x.lt_eqrust-analyzer cargo palette 0.7.6 num/PartialCmp#lt_eq().(&T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.04045)) => T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(1.0 /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). 12.92) *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). &x, |
| 106 | else => x.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().().mul_addrust-analyzer cargo palette 0.7.6 num/MulAdd#mul_add().(T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(1.0 /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). 1.055), T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.055 /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). 1.055)).powfrust-analyzer cargo palette 0.7.6 num/Powf#powf().(T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(2.4)), |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | impl<T> FromLinearrust-analyzer cargo palette 0.7.6 encoding/FromLinear#<T, T> for Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb# |
| 112 | where |
| 113 | T: Realrust-analyzer cargo palette 0.7.6 num/Real# + Powfrust-analyzer cargo palette 0.7.6 num/Powf# + MulSubrust-analyzer cargo palette 0.7.6 num/MulSub# + Arithmeticsrust-analyzer cargo palette 0.7.6 num/Arithmetics# + PartialCmprust-analyzer cargo palette 0.7.6 num/PartialCmp# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 114 | T::Maskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#Mask#: LazySelectrust-analyzer cargo palette 0.7.6 bool_mask/LazySelect#<T>, |
| 115 | { |
| 116 | #[inline] |
| 117 | fn from_linearrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][`FromLinear<T, T>`]from_linear().(x: T) -> T { |
| 118 | lazy_selectrust-analyzer cargo palette 0.7.6 macros/lazy_select/lazy_select!! { |
| 119 | if x.lt_eqrust-analyzer cargo palette 0.7.6 num/PartialCmp#lt_eq().(&T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.0031308)) => T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(12.92) *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). &x, |
| 120 | else => x.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().().powfrust-analyzer cargo palette 0.7.6 num/Powf#powf().(T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(1.0 /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). 2.4)).mul_subrust-analyzer cargo palette 0.7.6 num/MulSub#mul_sub().(T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(1.055), T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.055)), |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | impl IntoLinearrust-analyzer cargo palette 0.7.6 encoding/IntoLinear#<f32, u8> for Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb# { |
| 126 | #[inline] |
| 127 | fn into_linearrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][`IntoLinear<f32, u8>`]into_linear().(encoded: u8) -> f32 { |
| 128 | fast_srgb8rust-analyzer cargo fast-srgb8 1.0.0 crate/::srgb8_to_f32rust-analyzer cargo fast-srgb8 1.0.0 srgb8_to_f32().(encoded) |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | impl FromLinearrust-analyzer cargo palette 0.7.6 encoding/FromLinear#<f32, u8> for Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb# { |
| 133 | #[inline] |
| 134 | fn from_linearrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][`FromLinear<f32, u8>`]from_linear().(linear: f32) -> u8 { |
| 135 | fast_srgb8rust-analyzer cargo fast-srgb8 1.0.0 crate/::f32_to_srgb8rust-analyzer cargo fast-srgb8 1.0.0 f32_to_srgb8().(linear) |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | impl IntoLinearrust-analyzer cargo palette 0.7.6 encoding/IntoLinear#<f64, u8> for Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb# { |
| 140 | #[inline] |
| 141 | fn into_linearrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][`IntoLinear<f64, u8>`]into_linear().(encoded: u8) -> f64 { |
| 142 | SRGB_U8_TO_F64rust-analyzer cargo palette 0.7.6 encoding/srgb/lookup_tables/SRGB_U8_TO_F64.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().encoded as usize]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | impl FromLinearrust-analyzer cargo palette 0.7.6 encoding/FromLinear#<f64, u8> for Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb# { |
| 147 | #[inline] |
| 148 | fn from_linearrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][`FromLinear<f64, u8>`]from_linear().(linear: f64) -> u8 { |
| 149 | Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb#::from_linearrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][`FromLinear<f32, u8>`]from_linear().(linear as f32) |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | #[cfg(test)] |
| 154 | mod testrust-analyzer cargo palette 0.7.6 encoding/srgb/test/ { |
| 155 | use craterust-analyzer cargo palette 0.7.6 crate/::encodingrust-analyzer cargo palette 0.7.6 encoding/::{FromLinearrust-analyzer cargo palette 0.7.6 encoding/FromLinear#, IntoLinearrust-analyzer cargo palette 0.7.6 encoding/IntoLinear#, Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb#}; |
| 156 | |
| 157 | #[cfg(feature = "approx")] |
| 158 | mod conversionrust-analyzer cargo palette 0.7.6 encoding/srgb/test/conversion/ { |
| 159 | use craterust-analyzer cargo palette 0.7.6 crate/::{ |
| 160 | encodingrust-analyzer cargo palette 0.7.6 encoding/::Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb#, |
| 161 | matrixrust-analyzer cargo palette 0.7.6 matrix/::{matrix_inverserust-analyzer cargo palette 0.7.6 matrix/matrix_inverse()., rgb_to_xyz_matrixrust-analyzer cargo palette 0.7.6 matrix/rgb_to_xyz_matrix().}, |
| 162 | rgbrust-analyzer cargo palette 0.7.6 rgb/::RgbSpacerust-analyzer cargo palette 0.7.6 rgb/RgbSpace#, |
| 163 | }; |
| 164 | |
| 165 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 166 | fn rgb_to_xyzrust-analyzer cargo palette 0.7.6 encoding/srgb/test/conversion/rgb_to_xyz().() { |
| 167 | let dynamic = rgb_to_xyz_matrixrust-analyzer cargo palette 0.7.6 matrix/rgb_to_xyz_matrix().::<Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb#, f64>(); |
| 168 | let constant = Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb#::rgb_to_xyz_matrixrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][RgbSpace]rgb_to_xyz_matrix().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 169 | assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_eq!!(dynamic[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., constant[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., epsilonrust-analyzer cargo approx 0.5.1 impl#[`Relative<A, B>`]epsilon(). = 0.0000001); |
| 170 | } |
| 171 | |
| 172 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 173 | fn xyz_to_rgbrust-analyzer cargo palette 0.7.6 encoding/srgb/test/conversion/xyz_to_rgb().() { |
| 174 | let dynamic = matrix_inverserust-analyzer cargo palette 0.7.6 matrix/matrix_inverse().(rgb_to_xyz_matrixrust-analyzer cargo palette 0.7.6 matrix/rgb_to_xyz_matrix().::<Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb#, f64>()); |
| 175 | let constant = Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb#::xyz_to_rgb_matrixrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][RgbSpace]xyz_to_rgb_matrix().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 176 | assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_eq!!(dynamic[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., constant[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., epsilonrust-analyzer cargo approx 0.5.1 impl#[`Relative<A, B>`]epsilon(). = 0.0000001); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 181 | fn u8_to_f32_to_u8rust-analyzer cargo palette 0.7.6 encoding/srgb/test/u8_to_f32_to_u8().() { |
| 182 | for expected in 0u8..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#255u8 { |
| 183 | let linear: f32 = Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb#::into_linearrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][`IntoLinear<f32, u8>`]into_linear().(expected); |
| 184 | let result: u8 = Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb#::from_linearrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][`FromLinear<f32, u8>`]from_linear().(linear); |
| 185 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, expected); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 190 | fn u8_to_f64_to_u8rust-analyzer cargo palette 0.7.6 encoding/srgb/test/u8_to_f64_to_u8().() { |
| 191 | for expected in 0u8..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#255u8 { |
| 192 | let linear: f64 = Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb#::into_linearrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][`IntoLinear<f64, u8>`]into_linear().(expected); |
| 193 | let result: u8 = Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb#::from_linearrust-analyzer cargo palette 0.7.6 encoding/srgb/impl#[Srgb][`FromLinear<f64, u8>`]from_linear().(linear); |
| 194 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, expected); |
| 195 | } |
| 196 | } |
| 197 | } |