def compress_zip_prediction(fd, # type: BinaryIO
image, # type: np.ndarray
depth, # type: int
version # type: int
): # type: (...) -> None
"""
Write a Numpy array to a zip (zlib) with prediction compressed
stream.
Not supported for 1- or 32-bit images.
{}
"""
if depth == 1: # pragma: no cover
raise ValueError(
"zip with prediction is not supported for 1-bit images")
elif depth == 32: # pragma: no cover
raise ValueError(
"zip with prediction is not implemented for 32-bit images")
elif depth == 8:
encoder = packbits.encode_prediction_8bit
elif depth == 16:
encoder = packbits.encode_prediction_16bit
compressor = zlib.compressobj()
for row in image:
encoder(row.flatten())
row = util.ensure_bigendian(row)
fd.write(compressor.compress(row))
fd.write(compressor.flush())
评论列表
文章目录