(self, image: Image.Image, data_length: int,
filename: str, config: LSBConfig)
| 12 | """LSB 输出流,按顺序将数据位嵌入图像各像素通道的最低有效位。""" |
| 13 | |
| 14 | def __init__(self, image: Image.Image, data_length: int, |
| 15 | filename: str, config: LSBConfig): |
| 16 | self.image = image.copy() |
| 17 | self.config = config |
| 18 | self.header = LSBDataHeader(data_length, config.get_max_bits_used_per_channel(), |
| 19 | filename, config) |
| 20 | |
| 21 | self.pixels = np.array(self.image) |
| 22 | self.height, self.width, self.channels = self.pixels.shape |
| 23 | |
| 24 | bits_per_pixel = self.channels * config.get_max_bits_used_per_channel() |
| 25 | total_bits = (len(self.header.to_bytes()) + data_length) * 8 |
| 26 | if (total_bits + bits_per_pixel - 1) // bits_per_pixel > self.width * self.height: |
| 27 | raise ValueError(f"图像太小,无法嵌入 {data_length} 字节的数据") |
| 28 | |
| 29 | self._buffer = bytearray(self.header.to_bytes()) |
| 30 | |
| 31 | def write(self, data: bytes): |
| 32 | self._buffer.extend(data) |
nothing calls this directly
no test coverage detected