Загрузка данных


from PIL import Image

# Load uploaded pixel art
img = Image.open('/mnt/data/DCEF0E1F-FFA8-43C9-9C40-E6280C03B7E5.png').convert('RGB')
img = img.resize((128, 128), Image.NEAREST)

pixels = img.load()

output_lines = []

channels = [
    ("RED", 0),
    ("GREEN", 1),
    ("BLUE", 2)
]

for channel_name, idx in channels:
    output_lines.append(f"========== {channel_name} ==========")

    for y in range(128):
        runs = []
        x = 0

        while x < 128:
            value = pixels[x, y][idx]
            hex_value = format(value, '02X')

            count = 1
            while x + count < 128 and pixels[x + count, y][idx] == value:
                count += 1

            runs.append(f"{count}x{hex_value}")
            x += count

        output_lines.append(f"Строка {y+1}: " + " | ".join(runs))

    output_lines.append("")

# Save txt
output_path = "/mnt/data/pikachu_true_pixelart_rgb_hex.txt"

with open(output_path, "w", encoding="utf-8") as f:
    f.write("\n".join(output_lines))

print("Готово:", output_path)