haroldo-ok / choice4genesis

A ChoiceScript clone that generates SGDK-compatible C source for the Sega Genesis
https://haroldo-ok.itch.io/choice4genesis
MIT License
18 stars 2 forks source link

When converting certain images, the converter does not reduce them to 16 colors #115

Closed haroldo-ok closed 8 months ago

haroldo-ok commented 9 months ago
          [ezek (44) - original.zip](https://github.com/haroldo-ok/choice4genesis/files/12823111/ezek.44.-.original.zip)

OK, thanks; testing it: on the first try, it presented this error:

Error: cannot compile resource 'IMAGE ezek44v10_png "ezek44v10_png.png" APLIB ALL'
java.lang.IllegalArgumentException: 'D:\Pessoal\Projetos\choice4genesis\examples\ezek (44)\res\ezek44v10_png.png' has color index in [64..127] range, IMAGE resource requires image with a maximum of 64 colors

Then, I noticed that ezek44v10.png already had its colors reduced, as you reported; on the other hand, res/ezek44v10_png.png was paletized, but still using way more than 16 colors.

After that, I deleted the "src", "res", and "out" folders, and compiled again: it produced the same errors.

Opening the image in GIMP and saving it again didn't work, either; saving is as true color gave the same end results.

Only after resizing it to 320x224 and reducing it to 16 colors again, did it work, for that one image.

Now, it was complaining about ezek44v28.png; resizing it to 320x224 and reducing it to 16 colors worked around the bug, but now, the problem was on ezek44v29.png.

After using the same trick on ezek44v29.png, the project compiled.

I will open an issue to look at the cause of this bug, later.

Corrected project: ezek (44) - corrected.zip

Originally posted by @haroldo-ok in https://github.com/haroldo-ok/choice4genesis/issues/66#issuecomment-1749612119

haroldo-ok commented 8 months ago

It looks like Imagemagick messes up the palette when resizing an image.

In order to work around this, the routine now always reduces color when resizing, even if the original palette was already correct.