diff options
author | 2023-09-19 23:00:20 +0200 | |
---|---|---|
committer | 2023-09-19 23:00:20 +0200 | |
commit | be340a8cd822be1ea0fe4c1b1f3a62ca66d705b4 (patch) | |
tree | 38f6d1dc01bc3c32859b46b20e136daa0f90754e /tiny_skia | |
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 'tiny_skia')
-rw-r--r-- | tiny_skia/src/text.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/tiny_skia/src/text.rs b/tiny_skia/src/text.rs index d1b33293..70e95d01 100644 --- a/tiny_skia/src/text.rs +++ b/tiny_skia/src/text.rs @@ -1,6 +1,7 @@ use crate::core::alignment; use crate::core::text::{LineHeight, Shaping}; use crate::core::{Color, Font, Pixels, Point, Rectangle}; +use crate::graphics::color; use crate::graphics::text::cache::{self, Cache}; use crate::graphics::text::editor; use crate::graphics::text::font_system; @@ -216,7 +217,18 @@ fn draw( fn from_color(color: cosmic_text::Color) -> Color { let [r, g, b, a] = color.as_rgba(); - Color::from_rgba8(r, g, b, a as f32 / 255.0) + if color::GAMMA_CORRECTION { + // `cosmic_text::Color` is linear RGB in this case, so we + // need to convert back to sRGB + Color::from_linear_rgba( + r as f32 / 255.0, + g as f32 / 255.0, + b as f32 / 255.0, + a as f32 / 255.0, + ) + } else { + Color::from_rgba8(r, g, b, a as f32 / 255.0) + } } #[derive(Debug, Clone, Default)] |