def decode(self, buf, out=None): buf = ensure_contiguous_ndarray(buf) if out is not None: out = ensure_contiguous_ndarray(out) tiled = jpeg_decode(buf) return ndarray_copy(tiled, out)
def decode(self, buf, out=None): return imagecodecs.jpeg_decode( buf, bitspersample=self.bitspersample, tables=self.tables, header=self.header, colorspace=self.colorspace_jpeg, outcolorspace=self.colorspace_data, out=out, )
def _jpeg(self, tile: bytes) -> np.ndarray: """Internal method to decompress JPEG image bytes and convert to numpy array""" jpeg_tables = self.JPEGTables jpeg_table_bytes = struct.pack( f"{self._file_reader._endian}{jpeg_tables.count}{jpeg_tables.tag_type.format}", *self.JPEGTables.value, ) # # https://github.com/mapbox/COGDumper/tree/master/cogdumper if jpeg_table_bytes: if tile[0] == 0xFF and tile[1] == 0xD8: # insert tables, first removing the SOI and EOI tile = tile[0:2] + jpeg_table_bytes[2:-2] + tile[2:] else: raise Exception("Missing SOI marker for JPEG tile") decoded = imagecodecs.jpeg_decode(tile) return np.rollaxis(decoded, 2, 0)
def decode(self, buf, out=None): """The method to decode a jpeg image into a raw format. Parameters ---------- buf : contiguous_ndarray The jpeg image to be decoded into raw format. out : contiguous_ndarray, optional Another location to write the raw image to. Returns ------- ndarray The image in raw format """ buf = ensure_contiguous_ndarray(buf) if out is not None: out = ensure_contiguous_ndarray(out) tiled = jpeg_decode(buf) return ndarray_copy(tiled, out)