docs: def serialtoflat(self, raw, width=None):
          """Convert serial (byte stream) pixel data to flat row flat pixel."""
          if self.bitdepth == 8:
              return raw
          if self.bitdepth == 16:
              raw = bytearray_to_bytes(raw)
              return array('H',
                struct.unpack('!%dH' % (len(raw) // 2), raw))
          assert self.bitdepth < 8
          if width is None:
              width = self.width
          # Samples per byte
          spb = 8 // self.bitdepth
          out = newBarray()
          mask = 2**self.bitdepth - 1
          #                                      reversed range(spb)
          shifts = [self.bitdepth * it for it in range(spb - 1, -1, -1)]
          l = width
          for o in raw:
              out.extend([(mask&(o>>s)) for s in shifts][:l])
              l -= spb
              if l <= 0:
                  l = width
          return out