diff options
author | 2023-09-19 23:00:20 +0200 | |
---|---|---|
committer | 2023-09-19 23:00:20 +0200 | |
commit | be340a8cd822be1ea0fe4c1b1f3a62ca66d705b4 (patch) | |
tree | 38f6d1dc01bc3c32859b46b20e136daa0f90754e /core/src | |
parent | 9af0a27e675b71164f32f8d82eb4cde9cdd459f3 (diff) | |
download | iced-be340a8cd822be1ea0fe4c1b1f3a62ca66d705b4.tar.gz iced-be340a8cd822be1ea0fe4c1b1f3a62ca66d705b4.tar.bz2 iced-be340a8cd822be1ea0fe4c1b1f3a62ca66d705b4.zip |
Fix gamma correction for colored glyphs in `iced_wgpu`
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/color.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/core/src/color.rs b/core/src/color.rs index 1392f28b..cce8b340 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -89,6 +89,26 @@ impl Color { } } + /// Creates a [`Color`] from its linear RGBA components. + pub fn from_linear_rgba(r: f32, g: f32, b: f32, a: f32) -> Self { + // As described in: + // https://en.wikipedia.org/wiki/SRGB + fn gamma_component(u: f32) -> f32 { + if u < 0.0031308 { + 12.92 * u + } else { + 1.055 * u.powf(1.0 / 2.4) - 0.055 + } + } + + Self { + r: gamma_component(r), + g: gamma_component(g), + b: gamma_component(b), + a, + } + } + /// Converts the [`Color`] into its RGBA8 equivalent. #[must_use] pub fn into_rgba8(self) -> [u8; 4] { |