4 /**************************************************************************
6 * Copyright 2010 VMware, Inc.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the
11 * "Software"), to deal in the Software without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sub license, and/or sell copies of the Software, and to
14 * permit persons to whom the Software is furnished to do so, subject to
15 * the following conditions:
17 * The above copyright notice and this permission notice (including the
18 * next paragraph) shall be included in all copies or substantial portions
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
25 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 **************************************************************************/
35 from u_format_parse import *
39 def layout_map(layout):
40 return 'UTIL_FORMAT_LAYOUT_' + str(layout).upper()
43 def colorspace_map(colorspace):
44 return 'UTIL_FORMAT_COLORSPACE_' + str(colorspace).upper()
47 colorspace_channels_map = {
48 'rgb': ['r', 'g', 'b', 'a'],
49 'srgb': ['sr', 'sg', 'sb', 'a'],
51 'yuv': ['y', 'u', 'v'],
56 VOID: "UTIL_FORMAT_TYPE_VOID",
57 UNSIGNED: "UTIL_FORMAT_TYPE_UNSIGNED",
58 SIGNED: "UTIL_FORMAT_TYPE_SIGNED",
59 FIXED: "UTIL_FORMAT_TYPE_FIXED",
60 FLOAT: "UTIL_FORMAT_TYPE_FLOAT",
72 SWIZZLE_X: "UTIL_FORMAT_SWIZZLE_X",
73 SWIZZLE_Y: "UTIL_FORMAT_SWIZZLE_Y",
74 SWIZZLE_Z: "UTIL_FORMAT_SWIZZLE_Z",
75 SWIZZLE_W: "UTIL_FORMAT_SWIZZLE_W",
76 SWIZZLE_0: "UTIL_FORMAT_SWIZZLE_0",
77 SWIZZLE_1: "UTIL_FORMAT_SWIZZLE_1",
78 SWIZZLE_NONE: "UTIL_FORMAT_SWIZZLE_NONE",
82 def write_format_table(formats):
83 print '/* This file is autogenerated by u_format_table.py from u_format.csv. Do not edit directly. */'
85 # This will print the copyright message on the top of this file
86 print CopyRight.strip()
88 print '#include "u_format.h"'
89 print '#include "u_format_s3tc.h"'
90 print '#include "u_format_rgtc.h"'
91 print '#include "u_format_latc.h"'
94 u_format_pack.generate(formats)
96 for format in formats:
97 print 'const struct util_format_description'
98 print 'util_format_%s_description = {' % (format.short_name(),)
99 print " %s," % (format.name,)
100 print " \"%s\"," % (format.name,)
101 print " \"%s\"," % (format.short_name(),)
102 print " {%u, %u, %u},\t/* block */" % (format.block_width, format.block_height, format.block_size())
103 print " %s," % (layout_map(format.layout),)
104 print " %u,\t/* nr_channels */" % (format.nr_channels(),)
105 print " %s,\t/* is_array */" % (bool_map(format.is_array()),)
106 print " %s,\t/* is_bitmask */" % (bool_map(format.is_bitmask()),)
107 print " %s,\t/* is_mixed */" % (bool_map(format.is_mixed()),)
110 channel = format.channels[i]
116 print " {%s, %s, %u}%s\t/* %s = %s */" % (type_map[channel.type], bool_map(channel.norm), channel.size, sep, "xyzw"[i], channel.name)
118 print " {0, 0, 0}%s" % (sep,)
122 swizzle = format.swizzles[i]
128 comment = colorspace_channels_map[format.colorspace][i]
129 except (KeyError, IndexError):
131 print " %s%s\t/* %s */" % (swizzle_map[swizzle], sep, comment)
133 print " %s," % (colorspace_map(format.colorspace),)
134 if format.colorspace != ZS:
135 print " &util_format_%s_unpack_rgba_8unorm," % format.short_name()
136 print " &util_format_%s_pack_rgba_8unorm," % format.short_name()
137 if format.layout == 's3tc' or format.layout == 'rgtc':
138 print " &util_format_%s_fetch_rgba_8unorm," % format.short_name()
140 print " NULL, /* fetch_rgba_8unorm */"
141 print " &util_format_%s_unpack_rgba_float," % format.short_name()
142 print " &util_format_%s_pack_rgba_float," % format.short_name()
143 print " &util_format_%s_fetch_rgba_float," % format.short_name()
145 print " NULL, /* unpack_rgba_8unorm */"
146 print " NULL, /* pack_rgba_8unorm */"
147 print " NULL, /* fetch_rgba_8unorm */"
148 print " NULL, /* unpack_rgba_float */"
149 print " NULL, /* pack_rgba_float */"
150 print " NULL, /* fetch_rgba_float */"
151 if format.colorspace == ZS and format.swizzles[0] != SWIZZLE_NONE:
152 print " &util_format_%s_unpack_z_32unorm," % format.short_name()
153 print " &util_format_%s_pack_z_32unorm," % format.short_name()
154 print " &util_format_%s_unpack_z_float," % format.short_name()
155 print " &util_format_%s_pack_z_float," % format.short_name()
157 print " NULL, /* unpack_z_32unorm */"
158 print " NULL, /* pack_z_32unorm */"
159 print " NULL, /* unpack_z_float */"
160 print " NULL, /* pack_z_float */"
161 if format.colorspace == ZS and format.swizzles[1] != SWIZZLE_NONE:
162 print " &util_format_%s_unpack_s_8uscaled," % format.short_name()
163 print " &util_format_%s_pack_s_8uscaled" % format.short_name()
165 print " NULL, /* unpack_s_8uscaled */"
166 print " NULL /* pack_s_8uscaled */"
170 print "const struct util_format_description *"
171 print "util_format_description(enum pipe_format format)"
173 print " if (format >= PIPE_FORMAT_COUNT) {"
174 print " return NULL;"
177 print " switch (format) {"
178 for format in formats:
179 print " case %s:" % format.name
180 print " return &util_format_%s_description;" % (format.short_name(),)
182 print " return NULL;"
191 for arg in sys.argv[1:]:
192 formats.extend(parse(arg))
193 write_format_table(formats)
196 if __name__ == '__main__':