2 # gfxprimconfig.py - Class for (global) GfxPrim configuration
4 # 2011 - Tomas Gavenciak <gavento@ucw.cz>
8 class GfxPrimConfig(object):
9 def __init__(self
, pixel_type
= None, pixel_size
=None, sizes
=None,
10 bit_endians
=None, types
=[]):
12 self
.pixel_type
= pixel_type
13 assert self
.pixel_type
14 assert isinstance(self
.pixel_type
, str)
16 self
.pixel_size
= pixel_size
17 assert isinstance(self
.pixel_size
, int)
18 assert self
.pixel_size
% 8 == 0
19 assert self
.pixel_size
> 0
21 # Allowed bit-sizes of pixel types
23 assert isinstance(self
.sizes
, list)
24 assert self
.pixel_size
in self
.sizes
25 assert all(( isinstance(i
, int) and i
> 0 and i
<= self
.pixel_size
29 self
.bit_endians
= bit_endians
30 assert isinstance(self
.bit_endians
, list)
31 assert all(( i
in ["LE", "BE"] for i
in self
.bit_endians
))
33 # Set of all encountered channel names
36 # Dictionary of all pixeltypes { name : PixelType }
38 # List of all PixelTypes in order. "Unknown" must be first.
41 self
.add_pixeltype(PixelType("UNKNOWN", 0, [], bit_endian
=bit_endians
[0]))
45 def add_pixeltype(self
, pixeltype
):
46 "Add a PixelType and check its against the config"
48 assert pixeltype
not in self
.types
49 self
.types
.append(pixeltype
)
50 assert pixeltype
.name
not in self
.types_dict
51 self
.types_dict
[pixeltype
.name
] = pixeltype
52 self
.channels
.update(set(pixeltype
.chans
.keys()))
54 pixeltype
.check_config(self
)
55 except AssertionError:
56 sys
.stderr
.write("Error checking PixelType %s\n" % pixeltype
.name
)