Hello, Guest the thread was called519 times and contains 5 replays

last post from Bobaflott at the

PNG to sprite conversion

  • Made a small python script to convert a PNG image to a 16-color and 16-pixels wide sprite, if someone is interested.

    It prints out assembler code to paste into your source code. Don't forget to set the transparent color.

  • Thanks for sharing! :thumbup:

    Are there any specifications for the png image?

    I tried your script (named it "png2sprite.py") with the attached png ("snoopy.png") and get an error message:

    1. > python3 png2sprite.py snoopy.png
    2. Image width: 16
    3. Image height: 16
    4. Traceback (most recent call last):
    5. File "png2sprite.py", line 14, in <module>
    6. print ("Number of colors: "+str(len(colors)))
    7. TypeError: object of type 'NoneType' has no len()


  • It needs to be a indexed color image. Like, with a palette. In photoshop it's called indexed color anyway.

    Thanks! It works now. :thumbup:

  • Found a bug! That last for-loop should start at index 2.

    Also, this program assumes 24-bit graphics. The MEGA65 manual says 23-bit colour depth. Why is that and what bit is missing?

  • Ok, here the newest version, now fixed so the color values are correctly nibble-swapped and the red bit 4 cleared (as it's used for GENLOCK).