From c9510db551893775d3233340dd114d971e24323a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 7 Oct 2019 03:56:16 +0200 Subject: Render colored quads --- core/src/color.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'core') diff --git a/core/src/color.rs b/core/src/color.rs index 5cc3a084..2b64c78d 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -16,4 +16,23 @@ impl Color { b: 0.0, a: 1.0, }; + + pub fn into_linear(self) -> [f32; 4] { + // As described in: + // https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation + fn linear_component(u: f32) -> f32 { + if u < 0.04045 { + u / 12.92 + } else { + ((u + 0.055) / 1.055).powf(2.4) + } + } + + [ + linear_component(self.r), + linear_component(self.g), + linear_component(self.b), + self.a, + ] + } } -- cgit