Convert a packed row of bytes into a row of values. Result will be a freshly allocated object, not shared with the argument.
(self, bs, width=None)
| 1532 | yield self._bytes_to_values(row) |
| 1533 | |
| 1534 | def _bytes_to_values(self, bs, width=None): |
| 1535 | """Convert a packed row of bytes into a row of values. |
| 1536 | Result will be a freshly allocated object, |
| 1537 | not shared with the argument. |
| 1538 | """ |
| 1539 | |
| 1540 | if self.bitdepth == 8: |
| 1541 | return bytearray(bs) |
| 1542 | if self.bitdepth == 16: |
| 1543 | return array("H", struct.unpack("!%dH" % (len(bs) // 2), bs)) |
| 1544 | |
| 1545 | assert self.bitdepth < 8 |
| 1546 | if width is None: |
| 1547 | width = self.width |
| 1548 | # Samples per byte |
| 1549 | spb = 8 // self.bitdepth |
| 1550 | out = bytearray() |
| 1551 | mask = 2**self.bitdepth - 1 |
| 1552 | shifts = [self.bitdepth * i for i in reversed(list(range(spb)))] |
| 1553 | for o in bs: |
| 1554 | out.extend([mask & (o >> i) for i in shifts]) |
| 1555 | return out[:width] |
| 1556 | |
| 1557 | def _iter_straight_packed(self, byte_blocks): |
| 1558 | """Iterator that undoes the effect of filtering; |
no test coverage detected