4 /**************************************************************************
6 * Copyright 2009 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 *
38 def layout_map(layout
):
39 return 'UTIL_FORMAT_LAYOUT_' + str(layout
).upper()
42 def colorspace_map(colorspace
):
43 return 'UTIL_FORMAT_COLORSPACE_' + str(colorspace
).upper()
46 colorspace_channels_map
= {
47 'rgb': ['r', 'g', 'b', 'a'],
48 'srgb': ['sr', 'sg', 'sb', 'a'],
50 'yuv': ['y', 'u', 'v'],
55 VOID
: "UTIL_FORMAT_TYPE_VOID",
56 UNSIGNED
: "UTIL_FORMAT_TYPE_UNSIGNED",
57 SIGNED
: "UTIL_FORMAT_TYPE_SIGNED",
58 FIXED
: "UTIL_FORMAT_TYPE_FIXED",
59 FLOAT
: "UTIL_FORMAT_TYPE_FLOAT",
71 SWIZZLE_X
: "UTIL_FORMAT_SWIZZLE_X",
72 SWIZZLE_Y
: "UTIL_FORMAT_SWIZZLE_Y",
73 SWIZZLE_Z
: "UTIL_FORMAT_SWIZZLE_Z",
74 SWIZZLE_W
: "UTIL_FORMAT_SWIZZLE_W",
75 SWIZZLE_0
: "UTIL_FORMAT_SWIZZLE_0",
76 SWIZZLE_1
: "UTIL_FORMAT_SWIZZLE_1",
77 SWIZZLE_NONE
: "UTIL_FORMAT_SWIZZLE_NONE",
81 def write_format_table(formats
):
82 print '/* This file is autogenerated by u_format_table.py from u_format.csv. Do not edit directly. */'
84 # This will print the copyright message on the top of this file
87 print '#include "u_format.h"'
89 print 'const struct util_format_description'
90 print 'util_format_none_description = {'
91 print " PIPE_FORMAT_NONE,"
92 print " \"PIPE_FORMAT_NONE\","
100 print " {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}},"
101 print " {0, 0, 0, 0},"
105 for format
in formats
:
106 print 'const struct util_format_description'
107 print 'util_format_%s_description = {' % (format
.short_name(),)
108 print " %s," % (format
.name
,)
109 print " \"%s\"," % (format
.name
,)
110 print " \"%s\"," % (format
.short_name(),)
111 print " {%u, %u, %u},\t/* block */" % (format
.block_width
, format
.block_height
, format
.block_size())
112 print " %s," % (layout_map(format
.layout
),)
113 print " %u,\t/* nr_channels */" % (format
.nr_channels(),)
114 print " %s,\t/* is_array */" % (bool_map(format
.is_array()),)
115 print " %s,\t/* is_bitmask */" % (bool_map(format
.is_bitmask()),)
116 print " %s,\t/* is_mixed */" % (bool_map(format
.is_mixed()),)
119 channel
= format
.channels
[i
]
125 print " {%s, %s, %u}%s\t/* %s = %s */" % (type_map
[channel
.type], bool_map(channel
.norm
), channel
.size
, sep
, "xyzw"[i
], channel
.name
)
127 print " {0, 0, 0}%s" % (sep
,)
131 swizzle
= format
.swizzles
[i
]
137 comment
= colorspace_channels_map
[format
.colorspace
][i
]
138 except (KeyError, IndexError):
140 print " %s%s\t/* %s */" % (swizzle_map
[swizzle
], sep
, comment
)
142 print " %s," % (colorspace_map(format
.colorspace
),)
145 print "const struct util_format_description *"
146 print "util_format_description(enum pipe_format format)"
148 print " if (format >= PIPE_FORMAT_COUNT) {"
149 print " return NULL;"
152 print " switch (format) {"
153 print " case PIPE_FORMAT_NONE:"
154 print " return &util_format_none_description;"
155 for format
in formats
:
156 print " case %s:" % format
.name
157 print " return &util_format_%s_description;" % (format
.short_name(),)
160 print " return NULL;"
169 for arg
in sys
.argv
[1:]:
170 formats
.extend(parse(arg
))
171 write_format_table(formats
)
174 if __name__
== '__main__':