main/formats: Add a get_linear_format_srgb helper

Reviewed-by: Chad Versace <chadversary@chromium.org>
This commit is contained in:
Jason Ekstrand
2017-06-28 15:13:58 -07:00
parent 361eb1c6e7
commit 14ce44a7bc
2 changed files with 25 additions and 0 deletions

View File

@@ -105,6 +105,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 * If the format has an alpha channel, and there exists a non-alpha
* variant of the format with an identical bit layout, then return * variant of the format with an identical bit layout, then return

View File

@@ -748,6 +748,9 @@ _mesa_test_formats(void);
extern mesa_format extern mesa_format
_mesa_get_srgb_format_linear(mesa_format format); _mesa_get_srgb_format_linear(mesa_format format);
extern mesa_format
_mesa_get_linear_format_srgb(mesa_format format);
extern mesa_format extern mesa_format
_mesa_get_uncompressed_format(mesa_format format); _mesa_get_uncompressed_format(mesa_format format);