def compress_constant_zip_prediction(fd, # type: BinaryIO
value, # type: int
width, # type: int
rows, # type: int
depth, # type: int
version # type: int
): # type: (...) -> np.ndarray
"""
Write a virtual image containing a constant to a zip with
prediction compressed stream.
{}
"""
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
row = _make_constant_row(value, width, depth)
row = row.reshape((1, width))
row = util.ensure_native_endian(row)
encoder(row.flatten())
row = util.ensure_bigendian(row)
row = row.tobytes()
fd.write(zlib.compress(row * rows))
评论列表
文章目录