MSX2 png to sprite conversion tool

بواسطة pizzapower

Expert (71)

صورة pizzapower

13-02-2022, 17:27


original image vs. OpenMSX

Yet another python script I'd like to share. This one I created last week, but it was still a little rough around the edges. png2sprites.py converts an RGB PNG image into MSX2 VRAM sprite data. Output is assembly db data, C-style array data or a complete BASIC code that displays the sprites on the screen. User must supply one's own palette data as 16-colour tuple in a separate file and zeroth colour just removes the background from the original PNG file. There is an experimental feature that attempts to minimise sprite count by applying or-colour replacement after palette permutation. It is slow (and stupid) because it is just applying the same algorithm and counting sprites after swapping the palette.

Script code is based on reidrac's ubox python script with same name and requires Python 3.10. Probably.

Login أوregister لوضع تعليقاتك

بواسطة ARTRAG

Enlighted (6840)

صورة ARTRAG

13-02-2022, 18:26

Interesting! I did a similar script in matlab. It is focused on screen 8 sprites, where the palette is fixed (and very odd).

On each row of 16 pixels, it evaluates all 16x16=256 color combinations and the resulting the OR color. It tries to approximate the current row using each color triplet and computes the MSE. The color triplet with the best MSE is selected and the next line is processed.

بواسطة turbor

Champion (498)

صورة turbor

14-02-2022, 11:09

A small remark about openMSX usage:
If you want to have a one-on-one match between an MSX pixel and the output in openMSX, you will have to open the console and type
set horizontal_stretch 320
The default value is 280 so openMSX stretches 280 MSX pixels to 320 SDLlayer pixels make the image wider and causing a horizontal blur (like an old TV screen Smile )

بواسطة pizzapower

Expert (71)

صورة pizzapower

14-02-2022, 18:22

ARTRAG wrote:

Interesting! I did a similar script in matlab. It is focused on screen 8 sprites, where the palette is fixed (and very odd).

On each row of 16 pixels, it evaluates all 16x16=256 color combinations and the resulting the OR color. It tries to approximate the current row using each color triplet and computes the MSE. The color triplet with the best MSE is selected and the next line is processed.

Hey, ARTRAG. That's a cool project! May I add this sprite to my samples? It's the perfect stress test for my code. I fixed some problems in my code using it. I think it is working even better now.

turbor wrote:

A small remark about openMSX usage:
If you want to have a one-on-one match between an MSX pixel and the output in openMSX, you will have to open the console and type
set horizontal_stretch 320
The default value is 280 so openMSX stretches 280 MSX pixels to 320 SDLlayer pixels make the image wider and causing a horizontal blur (like an old TV screen :) )

Thanks for the tip, turbor! That was just to confirm that the image was indeed rendered inside OpenMSX. But I prefer to use screenshot -raw on the Tcl console. ;)

بواسطة ARTRAG

Enlighted (6840)

صورة ARTRAG

14-02-2022, 18:27

Sure, it is the screen 8 palette for sprites with all the OR applied