code: def _read_data(self, fh, byteorder='>'):
          
          fh.seek(len(self.header))
          data = fh.read()
          dtype = 'u1' if self.maxval < 256 else byteorder + 'u2'
          depth = 1 if self.magicnum == b"P7 332" else self.depth
          shape = [-1, self.height, self.width, depth]
          size = numpy.prod(shape[1:])
          if self.magicnum in b"P1P2P3":
              data = numpy.array(data.split(None, size)[:size], dtype)
              data = data.reshape(shape)
          elif self.maxval == 1:
              shape[2] = int(math.ceil(self.width / 8))
              data = numpy.frombuffer(data, dtype).reshape(shape)
              data = numpy.unpackbits(data, axis=-2)[:, :, :self.width, :]
          else:
              data = numpy.frombuffer(data, dtype)
              data = data[:size * (data.size // size)].reshape(shape)
          if data.shape[0] < 2:
              data = data.reshape(data.shape[1:])
          if data.shape[-1] < 2:
              data = data.reshape(data.shape[:-1])
          if self.magicnum == b"P7 332":
              rgb332 = numpy.array(list(numpy.ndindex(8, 8, 4)), numpy.uint8)
              rgb332 *= [36, 36, 85]
              data = numpy.take(rgb332, data, axis=0)
          return data
docs: Return image data from open file as numpy array.