XRAY

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andrew Davie

@Piledriver over at AA posted an interesting "x-Ray" image of some ROMs. Neat idea; I asked ChatGPT to write a Python script to do this for me. 20 seconds later, here's Boulder Dash's X-RAY. I jiggled a few pixels so you crafty people can't reconstruct a viable ROM from the image :P

BD.jpg

It's clear that the ROM is totally chokka!

Andrew Davie

Here's the script...

import sys
import math
from PIL import Image


def visualize_rom_as_bitmap(file_path):
    # Read the binary file
    with open(file_path, 'rb') as f:
        data = f.read()

    # Calculate the number of columns and rows
    total_bits = len(data) * 8
    width = math.isqrt(total_bits)
    if width % 8 != 0:
        width += 8 - (width % 8)  # Ensure width is a multiple of 8
    height = (total_bits + width - 1) // width

    # Create a new image
    img = Image.new('1', (width, height), color=1)  # '1' for 1-bit pixels, white background

    # Set the pixels
    col = 0
    row = 0
    for byte in data:
        for bit in range(8):
            x = col + bit
            y = row
            pixel_value = (byte >> (7 - bit)) & 1
            img.putpixel((x, y), pixel_value)

        row += 1
        if row >= height:
            row = 0
            col += 8

    # Display the image
    img.show()


if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: python visualize_rom.py <path_to_rom_file>")
    else:
        file_path = sys.argv[1]
        visualize_rom_as_bitmap(file_path)


Here's the query... I had to do a bit of fiddling to get it right, but the fundamentals were there. I subscribed to ChatGPT today as I've found myself using it more and more. It's remarkably capable.

i have a binary ROM of a game. I want to visualise it as a bitmap. The bitmap consists of columns of bytes. Each byte is displayed as 8 horizontal pixels. White for 1 bits, black for 0 bits. When a column becomes too long, it wraps back to the top but 8 pixels shifted to the right. i want the resultant image to be roughly square. Input the image name from the command line.