util/srgb: Add a float sRGB -> linear helper
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 23 Jun 2017 03:00:47 +0000 (20:00 -0700)
committerNanley Chery <nanley.g.chery@intel.com>
Tue, 24 Apr 2018 20:41:14 +0000 (13:41 -0700)
Reviewed-by: Nanley Chery <nanley.g.chery@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/util/format_srgb.h

index 34b50afe3d1d3287be42fdea2b5fef92ffb54429..596af56f4cd84af182010a774a96e54c1d8acd8e 100644 (file)
@@ -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)
 {