From 5942b3660281c848ec372b43f7ab7ab195893cd5 Mon Sep 17 00:00:00 2001 From: 24_PetrovIA <24_PetrovIA@iux.local> Date: Tue, 14 Apr 2026 12:02:19 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D1=82=D1=8C=20de?= =?UTF-8?q?bug=5Fdecode.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- debug_decode.py | 80 ------------------------------------------------- 1 file changed, 80 deletions(-) delete mode 100644 debug_decode.py diff --git a/debug_decode.py b/debug_decode.py deleted file mode 100644 index c36eaa2..0000000 --- a/debug_decode.py +++ /dev/null @@ -1,80 +0,0 @@ -cat > debug_decode.py << 'EOF' -print("Отладка decode_dct") - -from core.dct import _apply_dct, _extract_bits_from_block, MID_FREQ_INDICES -from core.utils import bits_to_text -from PIL import Image -import numpy as np - -# Загружаем закодированное изображение -print("Загружаем out_min.png...") -img = Image.open("out_min.png").convert('L') -pixels = np.array(img, dtype=np.float64) -height, width = pixels.shape -print(f"Размер: {height}x{width}") - -# Извлекаем все биты -print("\nИзвлекаем биты из всех блоков...") -all_bits = [] -block_count = 0 - -for i in range(0, height - 8 + 1, 8): - for j in range(0, width - 8 + 1, 8): - block = pixels[i:i+8, j:j+8] - dct_block = _apply_dct(block) - bits_from_block = _extract_bits_from_block(dct_block, len(MID_FREQ_INDICES)) - all_bits.extend(bits_from_block) - block_count += 1 - - if block_count <= 5: - print(f"Блок {block_count}: биты={bits_from_block[:20]}...") - -print(f"\nВсего извлечено битов: {len(all_bits)}") - -# Покажем первые 50 битов -print(f"\nПервые 50 битов: {all_bits[:50]}") - -# Поиск стоп-маркера (8 нулей подряд) -print("\nПоиск стоп-маркера (8 нулей подряд)...") -stop_counter = 0 -stop_position = -1 -for i, bit in enumerate(all_bits): - if bit == 0: - stop_counter += 1 - if stop_counter == 8: - stop_position = i - 7 - print(f"Стоп-маркер найден на позиции бита {stop_position}") - break - else: - stop_counter = 0 - -if stop_position == -1: - print("Стоп-маркер НЕ НАЙДЕН!") - # Покажем где встречаются нули - print("\nПоиск 8 нулей подряд:") - for i in range(len(all_bits) - 7): - if all_bits[i:i+8] == [0,0,0,0,0,0,0,0]: - print(f" Найдено на позиции {i}") - break -else: - print(f"Битов до стоп-маркера: {stop_position}") - bits_to_use = all_bits[:stop_position] - - # Преобразуем в байты - print("\nБайты до стоп-маркера:") - for k in range(0, len(bits_to_use), 8): - if k + 8 <= len(bits_to_use): - byte_bits = bits_to_use[k:k+8] - byte_val = 0 - for b in byte_bits: - byte_val = (byte_val << 1) | b - print(f" Байт {k//8}: {byte_val:3d} (0x{byte_val:02x}) биты={byte_bits}") - - # Декодируем - bits_string = ''.join(str(b) for b in bits_to_use) - try: - decoded = bits_to_text(bits_string) - print(f"\nДекодировано: '{decoded}'") - except Exception as e: - print(f"\nОшибка декодирования: {e}") -EOF