docs: def unpack_rgb(data, dtype=None, bitspersample=None, rescale=True):
      """Return array from byte string containing packed samples.
  
      Use to unpack RGB565 or RGB555 to RGB888 format.
  
      Parameters
      ----------
      data : byte str
          The data to be decoded. Samples in each pixel are stored consecutively.
          Pixels are aligned to 8, 16, or 32 bit boundaries.
      dtype : numpy.dtype
          The sample data type. The byteorder applies also to the data stream.
      bitspersample : tuple
          Number of bits for each sample in a pixel.
      rescale : bool
          Upscale samples to the number of bits in dtype.
  
      Returns
      -------
      numpy.ndarray
          Flattened array of unpacked samples of native dtype.
  
      Examples
      --------
      >>> data = struct.pack('BBBB', 0x21, 0x08, 0xff, 0xff)
      >>> print(unpack_rgb(data, '<B', (5, 6, 5), False))
      [ 1  1  1 31 63 31]
      >>> print(unpack_rgb(data, '<B', (5, 6, 5)))
      [  8   4   8 255 255 255]
      >>> print(unpack_rgb(data, '<B', (5, 5, 5)))
      [ 16   8   8 255 255 255]
  
      """
      if bitspersample is None:
          bitspersample = (5, 6, 5)
      if dtype is None:
          dtype = '<B'
      dtype = numpy.dtype(dtype)
      bits = int(numpy.sum(bitspersample))
      if not (bits <= 32 and all(i <= dtype.itemsize*8 for i in bitspersample)):
          raise ValueError('sample size not supported: %s' % str(bitspersample))
      dt = next(i for i in 'BHI' if numpy.dtype(i).itemsize*8 >= bits)
      data = numpy.frombuffer(data, dtype.byteorder+dt)
      result = numpy.empty((data.size, len(bitspersample)), dtype.char)
      for i, bps in enumerate(bitspersample):
          t = data >> int(numpy.sum(bitspersample[i+1:]))
          t &= int('0b'+'1'*bps, 2)
          if rescale:
              o = ((dtype.itemsize * 8) // bps + 1) * bps
              if o > data.dtype.itemsize * 8:
                  t = t.astype('I')
              t *= (2**o - 1) // (2**bps - 1)
              t //= 2**(o - (dtype.itemsize * 8))
          result[:, i] = t
      return result.reshape(-1)