From 14ce44a7bca30999601969563d97167751cdd326 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 28 Jun 2017 15:13:58 -0700 Subject: [PATCH] main/formats: Add a get_linear_format_srgb helper Reviewed-by: Chad Versace --- src/mesa/main/format_fallback.py | 22 ++++++++++++++++++++++ src/mesa/main/formats.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/src/mesa/main/format_fallback.py b/src/mesa/main/format_fallback.py index a833eab..2f02d0d 100644 --- a/src/mesa/main/format_fallback.py +++ b/src/mesa/main/format_fallback.py @@ -106,6 +106,28 @@ _mesa_get_srgb_format_linear(mesa_format format) } /** + * For a linear format, return the corresponding sRGB color space format. + * For an sRGB format, return the format as-is. + * Assert-fails if the format is not sRGB and does not have an sRGB equivalent. + */ +mesa_format +_mesa_get_linear_format_srgb(mesa_format format) +{ + switch (format) { +%for unorm, srgb in unorm_to_srgb_map: + case ${unorm}: + return ${srgb}; +%endfor +%for unorm, srgb in unorm_to_srgb_map: + case ${srgb}: +%endfor + return format; + default: + unreachable("Given format does not have an sRGB equivalent"); + } +} + +/** * If the format has an alpha channel, and there exists a non-alpha * variant of the format with an identical bit layout, then return * the non-alpha format. Otherwise return the original format. diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h index 62b5e0c..fbcbe36 100644 --- a/src/mesa/main/formats.h +++ b/src/mesa/main/formats.h @@ -749,6 +749,9 @@ extern mesa_format _mesa_get_srgb_format_linear(mesa_format format); extern mesa_format +_mesa_get_linear_format_srgb(mesa_format format); + +extern mesa_format _mesa_get_uncompressed_format(mesa_format format); extern GLuint -- 2.7.4