Img2spr converter

by andrear1979 on 29-03-2008, 22:43
Topic: Software
Tags: Utilities

A new command line utility for Windows is available at the MSX Software section of andrear's website. With this new tool one can extract sprite patterns from a color 16x16x24bit PNG image (other image formats may work as well), upon which they will be converted to -for instance- MSX-BASIC.

Though very simple, this utility may be of use to the MSX contestants coding for the current MSX contests (among others: 2KBOS, the 25th MSX anniversary BASIC contest and the upcoming MSXdev'08). Source code is included (C language, compiled in Windows with gcc-MinGW).

Relevant link: andrear's website - software section

Comments (6)


Enlighted (6845)

ARTRAG's picture

30-03-2008, 10:23

nice work, but of limited use.
Andrea, what about a screen 2 converter that automatically tries to add details using sprites ?
That is a true challenge, isn't it ?

By andrear1979

Expert (97)

andrear1979's picture

30-03-2008, 13:29

Hi Artrag, yes your suggestion is challenging, though I guess it's *not* a one evening task like img2spr Wink ; but don't want to promise anything Tongue ...

By the way, a reminder to other MSX users (and to myself): you may download ARTRAG's nice scr2converter utility, here at MRC. Source code is included.

By wolf_

Ambassador_ (9971)

wolf_'s picture

30-03-2008, 13:31

I think adding sprites at user-defined locations may work out better than letting an 'AI' decide on that.

By Grauw

Ascended (10603)

Grauw's picture

30-03-2008, 16:16

Idea for something even more challenging: a convertor that takes an image, and creates an optimal set of sprites out of it. E.g. when there are regions of transparency, don’t create a sprite for that region. And when a region contains more than 1 on a line, add a second sprite. And all this without fixed sprite positions of multiples of 16, but variable positions, so that it can determine the positions where the sprites are most effective.

That would be nice Smile. For Guru Logic, we could’ve definitely used such a thing. Because of the variable optimised positions it’s very tricky to create, though.

By andrear1979

Expert (97)

andrear1979's picture

30-03-2008, 19:46

Friends, thanks for all your future development suggestions. In the meantime, I improved a bit img2spr by adding a transparent-color parameter, please have a look at my website if you wish.


Enlighted (6845)

ARTRAG's picture

31-03-2008, 13:24

IMHO a possible algorithm to introduce sprites in the screen 2 conversion is to compute a "local" SNR on a 16x16 sliding window.
After screen 2 conversion, (use your favourite conversion strategy - note that dithering can make things more difficult),
slide the window pixel by pixel on the whole screen and pick up the 32 positions where the "local" SNR is worst (lowest).
Than, you define a sprite in each of the windows in order to to improve the SNR.

There are at least 2 problems with this solution:
1) the 4 sprites per line limit is not guaranteed
2) the use of colour dithering implies that the SNR has to be computed in a special way, i.e. doing spatial filtering before computing the SNR, (the sprite optimization in the selected windows has to be done using the same metric).

Problem 1) needs some solution apart, e.g. some manual refinement, while problem 2) adds only a bit of complications to the development of the code, but it is conceptually straightforward.