-- Leo's gemini proxy

-- Connecting to ew.srht.site:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

indexed-to-chr


This Python script converts an indexed image to the 2-bits-per-pixel "chr" format used by the Uxn emulator's PPU.


0x00 0x00 0x01 0x01 0x02 0x02 0x03 0x03
                  ...
└──────────────────┬──────────────────┘
                   ▼
         0b00110011 0b00001111

indexed-to-chr.py


Preparation


Using GIMP, open your image and change the color mode to indexed by selecting "Image → Mode → Indexed...". Then, select either "Generate optimum palette" with a maximum of 4 colors, or "Use a custom palette" and select a palette you have created with exactly four colors.


Then export your raw image data by selecting "File → Export..." and at the bottom of the file dialog, select a file type of "Raw image data". After exporting, you will have two files. The file with a .data extension contains the indexed pixel color data starting from the top left corner, one byte per pixel (color one is 0x00, color two is 0x01, color three is 0x02, color four is 0x03). The second with a .pal extension indicates the palette used for each color; the first three bytes indicate the RGB components for color one, the next three bytes for color two, and so on.


The image dimensions must be evenly divisible by 8, the dimensions of a sprite.


Usage


input: path to raw image input, where each pixel is one byte between 0x00 and 0x03 inclusive

output: path to chr output file

width: image width in number of 8x8 sprites (not pixels)


./indexed-to-chr.py [input] [output] [width]
./indexed-to-chr.py input.data output.chr 12

Resources


Compudanzas has an excellent tutorial explaining sprite usage in Uxn.

uxn tutorial: day 2, the screen

-- Response ended

-- Page fetched on Sat May 18 07:07:42 2024