X-Git-Url: https://git.libre-soc.org/?p=mesa.git;a=blobdiff_plain;f=src%2Futil%2Fformat_srgb.h;h=596af56f4cd84af182010a774a96e54c1d8acd8e;hp=8e92c38f4611b0c51aae27749e39a41f3c2279c1;hb=a4c708dd24e5ba8ac381973c14db8d23f4ac97bf;hpb=992e1ea8e4290cf14d59f89415bfd13e0920aad7 diff --git a/src/util/format_srgb.h b/src/util/format_srgb.h index 8e92c38f461..596af56f4cd 100644 --- a/src/util/format_srgb.h +++ b/src/util/format_srgb.h @@ -38,6 +38,8 @@ #define U_FORMAT_SRGB_H_ #include +#include +#include "c99_compat.h" extern const float util_format_srgb_8unorm_to_linear_float_table[256]; @@ -52,6 +54,34 @@ 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) +{ + if (cl <= 0.0f) + return 0.0f; + else if (cl < 0.0031308f) + return 12.92f * cl; + else if (cl < 1.0f) + return 1.055f * powf(cl, 0.41666f) - 0.055f; + else + return 1.0f; +} + + /** * Convert a unclamped linear float to srgb value in the [0,255]. */