[Mesa-dev] [PATCH v2 08/27] main/formats: Autogenerate _mesa_get_srgb_format_linear
Jason Ekstrand
jason at jlekstrand.net
Fri Jun 30 03:13:17 UTC 2017
---
src/mesa/main/format_fallback.py | 46 +++++++++++++++
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 e3b9916..ec86938 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 = {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 = {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 9d9830f..5c29d37 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.
*/
--
2.5.0.400.gff86faf
More information about the mesa-dev
mailing list