4 /**************************************************************************
6 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 **************************************************************************/
36 UNSIGNED
, SIGNED
, FIXED
, FLOAT
= 'u', 's', 'h', 'f'
41 def __init__(self
, kind
, norm
, size
):
56 def __init__(self
, name
, layout
, block_width
, block_height
, in_types
, out_swizzle
, colorspace
):
59 self
.block_width
= block_width
60 self
.block_height
= block_height
61 self
.in_types
= in_types
62 self
.out_swizzle
= out_swizzle
64 self
.colorspace
= colorspace
71 for type in self
.in_types
:
77 stream
= open(filename
)
81 fields
= [field
.strip() for field
in line
.split(',')]
84 block_width
, block_height
= map(int, fields
[2:4])
86 for field
in fields
[4:8]:
99 in_type
= Type(kind
, norm
, size
)
100 in_types
.append(in_type
)
101 out_swizzle
= fields
[8]
102 colorspace
= fields
[9]
103 formats
.append(Format(name
, layout
, block_width
, block_height
, in_types
, out_swizzle
, colorspace
))
107 def layout_map(layout
):
108 return 'UTIL_FORMAT_LAYOUT_' + str(layout
).upper()
111 def colorspace_map(colorspace
):
112 return 'UTIL_FORMAT_COLORSPACE_' + str(colorspace
).upper()
115 colorspace_channels_map
= {
119 'yuv': ['y1', 'y2', 'u', 'v'],
125 '': "UTIL_FORMAT_TYPE_VOID",
126 'x': "UTIL_FORMAT_TYPE_VOID",
127 UNSIGNED
: "UTIL_FORMAT_TYPE_UNSIGNED",
128 SIGNED
: "UTIL_FORMAT_TYPE_SIGNED",
129 FIXED
: "UTIL_FORMAT_TYPE_FIXED",
130 FLOAT
: "UTIL_FORMAT_TYPE_FLOAT",
142 'x': "UTIL_FORMAT_SWIZZLE_X",
143 'y': "UTIL_FORMAT_SWIZZLE_Y",
144 'z': "UTIL_FORMAT_SWIZZLE_Z",
145 'w': "UTIL_FORMAT_SWIZZLE_W",
146 '0': "UTIL_FORMAT_SWIZZLE_0",
147 '1': "UTIL_FORMAT_SWIZZLE_1",
148 '_': "UTIL_FORMAT_SWIZZLE_NONE",
152 def write_format_table(formats
):
153 print '/* This file is autogenerated by u_format_table.py from u_format.csv. Do not edit directly. */'
155 # This will print the copyright message on the top of this file
156 print __doc__
.strip()
158 print '#include "u_format.h"'
160 print 'const struct util_format_description'
161 print 'util_format_description_table[] = '
163 for format
in formats
:
165 print " %s," % (format
.name
,)
166 print " \"%s\"," % (format
.name
,)
167 print " {%u, %u, %u}, /* block */" % (format
.block_width
, format
.block_height
, format
.block_size())
168 print " %s," % (layout_map(format
.layout
),)
171 type = format
.in_types
[i
]
176 print " {%s, %s, %u}%s /* %s */" % (kind_map
[type.kind
], bool_map(type.norm
), type.size
, sep
, "xyzw"[i
])
180 swizzle
= format
.out_swizzle
[i
]
186 comment
= layout_channels_map
[format
.layout
][i
]
189 print " %s%s /* %s */" % (swizzle_map
[swizzle
], sep
, comment
)
191 print " %s," % (colorspace_map(format
.colorspace
),)
194 print " PIPE_FORMAT_NONE,"
195 print " \"PIPE_FORMAT_NONE\","
198 print " {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}},"
199 print " {0, 0, 0, 0},"
208 for arg
in sys
.argv
[1:]:
209 formats
.extend(parse(arg
))
210 write_format_table(formats
)
213 if __name__
== '__main__':