Home | History | Annotate | Download | only in main

Lines Matching refs:swizzle

104 class Swizzle:
105 """Describes a swizzle operation.
107 A Swizzle is a mapping from one set of channels in one format to the
119 Sometimes a Swizzle is represented by a 4-character string. In this
140 def __init__(self, swizzle):
141 """Creates a Swizzle object from a string or array."""
142 if isinstance(swizzle, str):
143 swizzle = [Swizzle.__identity_str.index(c) for c in swizzle]
145 swizzle = list(swizzle)
146 for s in swizzle:
147 assert isinstance(s, int) and 0 <= s and s <= Swizzle.SWIZZLE_NONE
149 assert len(swizzle) <= 4
151 self.__list = swizzle + [Swizzle.SWIZZLE_NONE] * (4 - len(swizzle))
155 """Returns an iterator that iterates over this Swizzle.
163 """Returns a string representation of this Swizzle."""
164 return ''.join(Swizzle.__identity_str[i] for i in self.__list)
175 assert idx >= Swizzle.SWIZZLE_X and idx <= Swizzle.SWIZZLE_NONE
176 if idx <= Swizzle.SWIZZLE_W:
194 """Returns the composition of this Swizzle with another Swizzle.
196 The resulting swizzle is such that, for any valid input to
199 assert isinstance(other, Swizzle)
200 return Swizzle(self[x] for x in other)
203 """Returns a pseudo-inverse of this swizzle.
205 Since swizzling isn't necisaraly a bijection, a Swizzle can never
206 be truely inverted. However, the swizzle returned is *almost* the
207 inverse of this swizzle in the sense that, for each i in range(3),
208 a[a.inverse()[i]] is either i or SWIZZLE_NONE. If swizzle is just
214 to lumanence-alpha, we use Swizzle("xxxy").inverse() or "xw__".
219 rev = [Swizzle.SWIZZLE_NONE] * 4
222 if self.__list[j] == i and rev[i] == Swizzle.SWIZZLE_NONE:
224 return Swizzle(rev)
230 def __init__(self, name, layout, block_width, block_height, block_depth, channels, swizzle, colorspace):
246 swizzle -- A Swizzle from this format to rgba
255 assert isinstance(swizzle, Swizzle)
256 self.swizzle = swizzle
264 for (i, s) in enumerate(swizzle):
268 for (i, s) in enumerate(swizzle):
446 # channel information there, we pull it from the swizzle.
447 if str(self.swizzle) == 'xxxx':
449 elif str(self.swizzle)[0:3] in ('xxx', 'yyy'):
453 return self.swizzle['a'] <= Swizzle.SWIZZLE_W
457 return self.swizzle[name] <= Swizzle.SWIZZLE_W
516 def _parse_channels(fields, layout, colorspace, swizzle):
564 swizzle = Swizzle(fields[9])
566 sys.exit("error parsing swizzle for format " + name)
567 channels = _parse_channels(fields[5:9], layout, colorspace, swizzle)
569 yield Format(name, layout, block_width, block_height, block_depth, channels, swizzle, colorspace)