diff options
author | Jason Ekstrand <[email protected]> | 2017-06-28 15:10:34 -0700 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2017-07-12 21:15:46 -0700 |
commit | 361eb1c6e765c393cb0b398124772b60a24ac36c (patch) | |
tree | 68169554d3ff932aff4c817a73fd0c151f54f86c /src/mesa | |
parent | 34e1ccbfbe851ecf4ebbfc86d70da384d176d994 (diff) |
main/formats: Autogenerate _mesa_get_srgb_format_linear
Due to the wonders of autogeneration, this new version covers a few
formats that the old version was missing:
MESA_FORMAT_SRGB8_ALPHA8_ASTC_3x3x3
MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x3x3
MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x3
MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x4
MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4x4
MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x4
MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x5
MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5x5
MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x5
MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x6
Reviewed-by: Chad Versace <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/main/format_fallback.py | 46 | ||||
-rw-r--r-- | src/mesa/main/formats.c | 117 |
2 files changed, 46 insertions, 117 deletions
diff --git a/src/mesa/main/format_fallback.py b/src/mesa/main/format_fallback.py index 7782e493d1d..a833eabf664 100644 --- a/src/mesa/main/format_fallback.py +++ b/src/mesa/main/format_fallback.py @@ -38,6 +38,34 @@ def parse_args(): p.add_argument("out") return p.parse_args() +def get_unorm_to_srgb_map(formats): + names = set(fmt.name for fmt in formats) + + for fmt in formats: + if fmt.colorspace != 'srgb': + continue; + + replacements = [ + ('SRGB', 'RGB'), + ('SRGB', 'UNORM'), + ('SRGB8_ALPHA8', 'RGBA'), + ('SRGB8_ALPHA8', 'RGBA8'), + ('SRGB_ALPHA_UNORM', 'RGBA_UNORM'), + ] + found_unorm_name = False + for rep in replacements: + if fmt.name.find(rep[0]) == -1: + continue + + unorm_name = fmt.name.replace(rep[0], rep[1]) + if unorm_name in names: + yield unorm_name, fmt.name + found_unorm_name = True + break + + # Every sRGB format MUST have a UNORM equivalent + assert found_unorm_name + def get_rgbx_to_rgba_map(formats): names = set(fmt.name for fmt in formats) @@ -61,6 +89,23 @@ TEMPLATE = Template(COPYRIGHT + """ #include "formats.h" /** + * For an sRGB format, return the corresponding linear color space format. + * For non-sRGB formats, return the format as-is. + */ +mesa_format +_mesa_get_srgb_format_linear(mesa_format format) +{ + switch (format) { +%for unorm, srgb in unorm_to_srgb_map: + case ${srgb}: + return ${unorm}; +%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 * the non-alpha format. Otherwise return the original format. @@ -94,6 +139,7 @@ def main(): formats = list(format_parser.parse(pargs.csv)) template_env = { + 'unorm_to_srgb_map': list(get_unorm_to_srgb_map(formats)), 'rgbx_to_rgba_map': list(get_rgbx_to_rgba_map(formats)), } diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c index 9d9830f8bf4..5c29d37bb44 100644 --- a/src/mesa/main/formats.c +++ b/src/mesa/main/formats.c @@ -622,123 +622,6 @@ _mesa_is_format_etc2(mesa_format format) /** - * For an sRGB format, return the corresponding linear color space format. - * For non-sRGB formats, return the format as-is. - */ -mesa_format -_mesa_get_srgb_format_linear(mesa_format format) -{ - switch (format) { - case MESA_FORMAT_BGR_SRGB8: - format = MESA_FORMAT_BGR_UNORM8; - break; - case MESA_FORMAT_A8B8G8R8_SRGB: - format = MESA_FORMAT_A8B8G8R8_UNORM; - break; - case MESA_FORMAT_B8G8R8A8_SRGB: - format = MESA_FORMAT_B8G8R8A8_UNORM; - break; - case MESA_FORMAT_A8R8G8B8_SRGB: - format = MESA_FORMAT_A8R8G8B8_UNORM; - break; - case MESA_FORMAT_R8G8B8A8_SRGB: - format = MESA_FORMAT_R8G8B8A8_UNORM; - break; - case MESA_FORMAT_L_SRGB8: - format = MESA_FORMAT_L_UNORM8; - break; - case MESA_FORMAT_L8A8_SRGB: - format = MESA_FORMAT_L8A8_UNORM; - break; - case MESA_FORMAT_A8L8_SRGB: - format = MESA_FORMAT_A8L8_UNORM; - break; - case MESA_FORMAT_SRGB_DXT1: - format = MESA_FORMAT_RGB_DXT1; - break; - case MESA_FORMAT_SRGBA_DXT1: - format = MESA_FORMAT_RGBA_DXT1; - break; - case MESA_FORMAT_SRGBA_DXT3: - format = MESA_FORMAT_RGBA_DXT3; - break; - case MESA_FORMAT_SRGBA_DXT5: - format = MESA_FORMAT_RGBA_DXT5; - break; - case MESA_FORMAT_R8G8B8X8_SRGB: - format = MESA_FORMAT_R8G8B8X8_UNORM; - break; - case MESA_FORMAT_X8B8G8R8_SRGB: - format = MESA_FORMAT_X8B8G8R8_UNORM; - break; - case MESA_FORMAT_ETC2_SRGB8: - format = MESA_FORMAT_ETC2_RGB8; - break; - case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC: - format = MESA_FORMAT_ETC2_RGBA8_EAC; - break; - case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: - format = MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1; - break; - case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM: - format = MESA_FORMAT_BPTC_RGBA_UNORM; - break; - case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4: - format = MESA_FORMAT_RGBA_ASTC_4x4; - break; - case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4: - format = MESA_FORMAT_RGBA_ASTC_5x4; - break; - case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5: - format = MESA_FORMAT_RGBA_ASTC_5x5; - break; - case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5: - format = MESA_FORMAT_RGBA_ASTC_6x5; - break; - case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6: - format = MESA_FORMAT_RGBA_ASTC_6x6; - break; - case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5: - format = MESA_FORMAT_RGBA_ASTC_8x5; - break; - case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6: - format = MESA_FORMAT_RGBA_ASTC_8x6; - break; - case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8: - format = MESA_FORMAT_RGBA_ASTC_8x8; - break; - case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5: - format = MESA_FORMAT_RGBA_ASTC_10x5; - break; - case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6: - format = MESA_FORMAT_RGBA_ASTC_10x6; - break; - case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8: - format = MESA_FORMAT_RGBA_ASTC_10x8; - break; - case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10: - format = MESA_FORMAT_RGBA_ASTC_10x10; - break; - case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10: - format = MESA_FORMAT_RGBA_ASTC_12x10; - break; - case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12: - format = MESA_FORMAT_RGBA_ASTC_12x12; - break; - case MESA_FORMAT_B8G8R8X8_SRGB: - format = MESA_FORMAT_B8G8R8X8_UNORM; - break; - case MESA_FORMAT_X8R8G8B8_SRGB: - format = MESA_FORMAT_X8R8G8B8_UNORM; - break; - default: - break; - } - return format; -} - - -/** * If the given format is a compressed format, return a corresponding * uncompressed format. */ |