MCPcopy Create free account
hub / github.com/MearaY/StegaPy / __init__

Method __init__

StegaPy/plugin/lsb/lsb_input_stream.py:14–34  ·  view source on GitHub ↗
(self, image: Image.Image, config: LSBConfig)

Source from the content-addressed store, hash-verified

12 """LSB 输入流,按顺序从图像各像素通道的最低有效位中还原数据。"""
13
14 def __init__(self, image: Image.Image, config: LSBConfig):
15 self.config = config
16 self.pixels = np.array(image)
17 self.height, self.width, self.channels = self.pixels.shape
18 self._bit_offset = 0
19
20 # 先读固定部分以获取 filename_len,再读变长文件名
21 fixed_size = (len(LSBDataHeader.DATA_STAMP) + len(LSBDataHeader.HEADER_VERSION)
22 + LSBDataHeader.FIXED_HEADER_LENGTH + LSBDataHeader.CRYPT_ALGO_LENGTH)
23 fixed_bytes = self._read_bytes(fixed_size)
24
25 fixed_header_offset = len(LSBDataHeader.DATA_STAMP) + len(LSBDataHeader.HEADER_VERSION)
26 filename_len = fixed_bytes[fixed_header_offset + 5]
27
28 filename_bytes = self._read_bytes(filename_len) if filename_len > 0 else b''
29 try:
30 self.header = LSBDataHeader.from_bytes(fixed_bytes + filename_bytes, config)
31 except Exception as e:
32 raise ValueError(f"无法解析数据头: {e}")
33
34 self.channel_bits_used = self.header.get_channel_bits_used()
35
36 def _read_bytes(self, n_bytes: int) -> bytes:
37 bits_per_ch = getattr(self, 'channel_bits_used', None) or self.config.get_max_bits_used_per_channel()

Callers

nothing calls this directly

Calls 3

_read_bytesMethod · 0.95
from_bytesMethod · 0.80
get_channel_bits_usedMethod · 0.80

Tested by

no test coverage detected