2 # gfxprimconfig - Class for (global) GfxPrim configuration
4 # 2011 - Tomas Gavenciak <gavento@ucw.cz>
5 # 2011-2014 - Cyril Hrubis <metan@ucw.cz>
9 from pixeltype
import PixelType
10 from pixelsize
import PixelSize
12 class GfxPrimConfig(object):
13 def __init__(self
, pixel_type
= None, pixel_size
=None, pixelsizes
=None,
15 """Initialize GfxPrim code generation config
17 pixel_type: name of C type for a pixel value
18 pixel_size: number of bits of pixel_type
19 pixelsizes: list of generated and allowed PixelSizes
20 pixelsizes_by_bpp: dictionary of bitendians by BPP
21 pixeltypes: list of generated PixelTypes, not incl. UNKNOWN
24 self
.pixel_type
= pixel_type
25 assert self
.pixel_type
26 assert isinstance(self
.pixel_type
, str)
28 self
.pixel_size
= pixel_size
29 assert isinstance(self
.pixel_size
, int)
30 assert self
.pixel_size
% 8 == 0
31 assert self
.pixel_size
> 0
33 # Allowed bit-sizes of pixel types
34 self
.pixelsizes
= pixelsizes
35 assert isinstance(self
.pixelsizes
, list)
36 assert self
.pixel_size
in [i
.size
for i
in self
.pixelsizes
]
37 for i
in self
.pixelsizes
:
38 assert i
.size
<= self
.pixel_size
40 # Dictionary of all pixelsizes by BPP { bpp : list of BE, LE }
41 self
.pixelsizes_by_bpp
= dict()
42 for i
in self
.pixelsizes
:
43 if i
.size
not in self
.pixelsizes_by_bpp
:
44 self
.pixelsizes_by_bpp
[i
.size
] = [i
.bit_endian
]
46 self
.pixelsizes_by_bpp
[i
.size
].append(i
.bit_endian
)
48 # Set of all encountered channel names
51 # Dictionary of all pixeltypes { name : PixelType }
52 self
.pixeltypes_dict
= {}
53 # List of all PixelTypes in order. "Unknown" MUST be first.
56 self
.add_pixeltype(PixelType("UNKNOWN", PixelSize(0), []))
61 def add_pixeltype(self
, pixeltype
):
62 "Add a PixelType and check its against the config"
64 assert pixeltype
not in self
.pixeltypes
65 self
.pixeltypes
.append(pixeltype
)
66 assert pixeltype
.name
not in self
.pixeltypes_dict
67 self
.pixeltypes_dict
[pixeltype
.name
] = pixeltype
68 self
.channels
.update(set(pixeltype
.chans
.keys()))
70 pixeltype
.valid_for_config(self
)
71 except AssertionError:
72 log
.error("Error checking PixelType %s\n" % pixeltype
.name
)