[Mesa-dev] [PATCH 04/14] util/srgb: Add a float sRGB -> linear helper

Nanley Chery nanleychery at gmail.com
Fri Mar 30 18:12:17 UTC 2018


From: Jason Ekstrand <jason.ekstrand at intel.com>

Reviewed-by: Nanley Chery <nanley.g.chery at intel.com>
---
 src/util/format_srgb.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/util/format_srgb.h b/src/util/format_srgb.h
index 34b50afe3d1..596af56f4cd 100644
--- a/src/util/format_srgb.h
+++ b/src/util/format_srgb.h
@@ -54,6 +54,20 @@ extern const unsigned
 util_format_linear_to_srgb_helper_table[104];
 
 
+static inline float
+util_format_srgb_to_linear_float(float cs)
+{
+   if (cs <= 0.0f)
+      return 0.0f;
+   else if (cs <= 0.04045f)
+      return cs / 12.92f;
+   else if (cs < 1.0f)
+      return powf((cs + 0.055) / 1.055f, 2.4f);
+   else
+      return 1.0f;
+}
+
+
 static inline float
 util_format_linear_to_srgb_float(float cl)
 {
-- 
2.16.2



More information about the mesa-dev mailing list