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
):
54 SCALED
, NORM
, SRGB
= 'scaled', 'norm', 'srgb'
59 def __init__(self
, name
, layout
, block_width
, block_height
, in_types
, out_swizzle
, colorspace
):
62 self
.block_width
= block_width
63 self
.block_height
= block_height
64 self
.in_types
= in_types
65 self
.out_swizzle
= out_swizzle
67 self
.colorspace
= colorspace
74 for type in self
.in_types
:
80 stream
= open(filename
)
84 fields
= [field
.strip() for field
in line
.split(',')]
87 block_width
, block_height
= map(int, fields
[2:4])
89 for field
in fields
[4:8]:
102 in_type
= Type(kind
, norm
, size
)
103 in_types
.append(in_type
)
104 out_swizzle
= fields
[8]
105 colorspace
= fields
[9]
106 formats
.append(Format(name
, layout
, block_width
, block_height
, in_types
, out_swizzle
, colorspace
))
110 def layout_map(layout
):
111 return 'UTIL_FORMAT_LAYOUT_' + str(layout
).upper()
114 layout_channels_map
= {
117 'yuv': ['y1', 'y2', 'u', 'v'],
123 '': "UTIL_FORMAT_TYPE_VOID",
124 'x': "UTIL_FORMAT_TYPE_VOID",
125 UNSIGNED
: "UTIL_FORMAT_TYPE_UNSIGNED",
126 SIGNED
: "UTIL_FORMAT_TYPE_SIGNED",
127 FIXED
: "UTIL_FORMAT_TYPE_FIXED",
128 FLOAT
: "UTIL_FORMAT_TYPE_FLOAT",
140 'x': "UTIL_FORMAT_SWIZZLE_X",
141 'y': "UTIL_FORMAT_SWIZZLE_Y",
142 'z': "UTIL_FORMAT_SWIZZLE_Z",
143 'w': "UTIL_FORMAT_SWIZZLE_W",
144 '0': "UTIL_FORMAT_SWIZZLE_0",
145 '1': "UTIL_FORMAT_SWIZZLE_1",
146 '_': "UTIL_FORMAT_SWIZZLE_NONE",
150 def write_format_table(formats
):
151 print '/* This file is autogenerated by u_format_table.py from u_format.csv. Do not edit directly. */'
153 # This will print the copyright message on the top of this file
154 print __doc__
.strip()
156 print '#include "u_format.h"'
158 print 'const struct util_format_description'
159 print 'util_format_description_table[] = '
161 for format
in formats
:
163 print " %s," % (format
.name
,)
164 print " \"%s\"," % (format
.name
,)
165 print " {%u, %u, %u}, /* block */" % (format
.block_width
, format
.block_height
, format
.block_size())
166 print " %s," % (layout_map(format
.layout
),)
169 type = format
.in_types
[i
]
174 print " {%s, %s, %u}%s /* %s */" % (kind_map
[type.kind
], bool_map(type.norm
), type.size
, sep
, "xyzw"[i
])
178 swizzle
= format
.out_swizzle
[i
]
184 comment
= layout_channels_map
[format
.layout
][i
]
187 print " %s%s /* %s */" % (swizzle_map
[swizzle
], sep
, comment
)
189 print " UTIL_FORMAT_COLORSPACE_RGB,"
192 print " PIPE_FORMAT_NONE,"
193 print " \"PIPE_FORMAT_NONE\","
196 print " {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}},"
197 print " {0, 0, 0, 0},"
206 for arg
in sys
.argv
[1:]:
207 formats
.extend(parse(arg
))
208 write_format_table(formats
)
211 if __name__
== '__main__':