X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fformat_fallback.py;h=cc388274e750fa6685cf726a1dd637e1c1670fbb;hb=51c1c4d95a05b6eb6fce74e8d624615e4a1b38ab;hp=a833eabf664008fa6b353002570bceeb89bbf70e;hpb=361eb1c6e765c393cb0b398124772b60a24ac36c;p=mesa.git diff --git a/src/mesa/main/format_fallback.py b/src/mesa/main/format_fallback.py index a833eabf664..cc388274e75 100644 --- a/src/mesa/main/format_fallback.py +++ b/src/mesa/main/format_fallback.py @@ -85,8 +85,23 @@ def get_rgbx_to_rgba_map(formats): yield rgbx_name, rgba_name +def get_intensity_to_red_map(formats): + names = set(fmt.name for fmt in formats) + + for fmt in formats: + if str(fmt.swizzle) != 'xxxx': + continue + + i_name = fmt.name + r_name = i_name.replace("_I_", "_R_") + + assert r_name in names + + yield i_name, r_name + TEMPLATE = Template(COPYRIGHT + """ #include "formats.h" +#include "util/macros.h" /** * For an sRGB format, return the corresponding linear color space format. @@ -105,6 +120,45 @@ _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"); + } +} + +/** + * For an intensity format, return the corresponding red format. For other + * formats, return the format as-is. + */ +mesa_format +_mesa_get_intensity_format_red(mesa_format format) +{ + switch (format) { +%for i, r in intensity_to_red_map: + case ${i}: + return ${r}; +%endfor + default: + return format; + } +} + /** * If the format has an alpha channel, and there exists a non-alpha * variant of the format with an identical bit layout, then return @@ -141,6 +195,7 @@ def main(): template_env = { 'unorm_to_srgb_map': list(get_unorm_to_srgb_map(formats)), 'rgbx_to_rgba_map': list(get_rgbx_to_rgba_map(formats)), + 'intensity_to_red_map': list(get_intensity_to_red_map(formats)), } with open(pargs.out, 'w') as f: