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 **************************************************************************/
36 VOID
, UNSIGNED
, SIGNED
, FIXED
, FLOAT
= range(5)
38 SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_W
, SWIZZLE_0
, SWIZZLE_1
, SWIZZLE_NONE
, = range(7)
45 '''Describe the type of a color channel.'''
47 def __init__(self
, kind
, norm
, size
):
51 self
.sign
= kind
in (SIGNED
, FIXED
, FLOAT
)
60 def __eq__(self
, other
):
61 return self
.kind
== other
.kind
and self
.norm
== other
.norm
and self
.size
== other
.size
65 '''Describe a pixel format.'''
67 def __init__(self
, name
, layout
, block_width
, block_height
, in_types
, out_swizzle
, colorspace
):
70 self
.block_width
= block_width
71 self
.block_height
= block_height
72 self
.in_types
= in_types
73 self
.out_swizzle
= out_swizzle
75 self
.colorspace
= colorspace
82 for type in self
.in_types
:
87 return self
.block_size()/8
99 _swizzle_parse_map
= {
110 '''Parse the format descrition in CSV format in terms of the
111 Type and Format classes above.'''
113 stream
= open(filename
)
117 fields
= [field
.strip() for field
in line
.split(',')]
120 block_width
, block_height
= map(int, fields
[2:4])
122 for field
in fields
[4:8]:
124 kind
= _kind_parse_map
[field
[0]]
127 size
= int(field
[2:])
130 size
= int(field
[1:])
135 in_type
= Type(kind
, norm
, size
)
136 in_types
.append(in_type
)
137 out_swizzle
= [_swizzle_parse_map
[swizzle
] for swizzle
in fields
[8]]
138 colorspace
= fields
[9]
139 formats
.append(Format(name
, layout
, block_width
, block_height
, in_types
, out_swizzle
, colorspace
))