diff options
author | 2023-06-06 17:06:40 -0700 | |
---|---|---|
committer | 2023-06-06 17:24:26 -0700 | |
commit | 9554c78f3adc9846b76e9d3b96af06e98fb69aa0 (patch) | |
tree | cb51e072386014989aa42d259b9e17a70ae2d821 /graphics/src/gradient.rs | |
parent | 226ce3d6c96e1ee091980c3d1ba869c01920b316 (diff) | |
download | iced-9554c78f3adc9846b76e9d3b96af06e98fb69aa0.tar.gz iced-9554c78f3adc9846b76e9d3b96af06e98fb69aa0.tar.bz2 iced-9554c78f3adc9846b76e9d3b96af06e98fb69aa0.zip |
Updated color packing into u32 to consider incorrect web-colors.
Diffstat (limited to 'graphics/src/gradient.rs')
-rw-r--r-- | graphics/src/gradient.rs | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/graphics/src/gradient.rs b/graphics/src/gradient.rs index 57cc007f..97b0a6d7 100644 --- a/graphics/src/gradient.rs +++ b/graphics/src/gradient.rs @@ -103,11 +103,17 @@ impl Linear { let mut offsets = [0.0f32; 8]; for (index, stop) in self.stops.iter().enumerate() { - let (color, offset) = stop - .map_or((Color::default().into_u32(), 2.0), |s| { - (s.color.into_u32(), s.offset) - }); - colors[index] = color; + let (color, offset) = + stop.map_or((Color::default(), 2.0), |s| (s.color, s.offset)); + + if color::GAMMA_CORRECTION { + //correct colors, convert to linear before uploading to GPU + colors[index] = color.into_linear_u32(); + } else { + //web colors, don't convert to linear before uploading to GPU + colors[index] = color.into_u32(); + } + offsets[index] = offset; } @@ -139,16 +145,17 @@ pub fn pack(gradient: &core::Gradient, bounds: Rectangle) -> Packed { let mut offsets = [0.0f32; 8]; for (index, stop) in linear.stops.iter().enumerate() { - // let [r, g, b, a] = - // color::pack(stop.map_or(Color::default(), |s| s.color)) - // .components(); - let (color, offset) = stop - .map_or((Color::default().into_u32(), 2.0), |s| { - (s.color.into_u32(), s.offset) - }); + .map_or((Color::default(), 2.0), |s| (s.color, s.offset)); + + if color::GAMMA_CORRECTION { + //correct colors, convert to linear before uploading to GPU + colors[index] = color.into_linear_u32(); + } else { + //web colors, don't convert to linear before uploading to GPU + colors[index] = color.into_u32(); + } - colors[index] = color; offsets[index] = offset; } |