First batch of gen config changes
[gfxprim.git] / pylib / gfxprim / generators / gfxprimconfig.py
blob60546d081441e66648e81f0bbb23f94ace89596b
2 # gfxprimconfig.py - Class for (global) GfxPrim configuration
4 # 2011 - Tomas Gavenciak <gavento@ucw.cz>
6 import re, os, sys
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
22 self.sizes = sizes
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
26 for i in self.sizes))
28 # bit_endian values
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
34 self.channels = set()
36 # Dictionary of all pixeltypes { name : PixelType }
37 self.types_dict = {}
38 # List of all PixelTypes in order. "Unknown" must be first.
39 self.types = []
41 self.add_pixeltype(PixelType("UNKNOWN", 0, [], bit_endian=bit_endians[0]))
42 for t in types:
43 self.add_pixeltype(t)
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()))
53 try:
54 pixeltype.check_config(self)
55 except AssertionError:
56 sys.stderr.write("Error checking PixelType %s\n" % pixeltype.name)