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)
#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.
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)),
}
/**
- * 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.
*/