def decompress_raw(data, # type: bytes
shape, # type: Tuple[int, int]
depth, # type: int
version # type: int
): # type: (...) -> np.ndarray
"""
Converts raw data to a Numpy array.
{}
"""
depth = enums.ColorDepth(depth)
dtype = color_depth_dtype_map[depth]
itemsize = color_depth_size_map[depth]
# Truncate the data to a multiple of the dtype size
data = data[:(len(data) // itemsize) * itemsize]
arr = np.frombuffer(data, dtype)
if depth == 1:
# Unpack 1-bit image data
arr = np.unpackbits(arr)
# Make 2-dimensional
image = arr.reshape(shape)
return image
评论列表
文章目录