Load 2- to 8-bit grayscale PNGs with Lua

This would be super useful for INTERNAL processing, to generate certain effects by checking the pixel values. For example:

  • An image that is a map of how fast you can move around, or how much environmental damage you take. (Need not be full 8 bits.)

  • An image that is used to generate custom dithers or wipe/transition effects.

  • An image that is an internal world map, from which tilemaps are generated as needed.

(Grayscale PNGs might also be displayed directly, using a chosen dither. Dithered images can be prepared externally of course, but doing the dither in-app could be nice for making the dither closely match other game content.)

(Meanwhile, although direct Lua support would be awesome, I'm looking at workarounds like multiple 1-bit PNGs, big numeric tables, and a nifty C library RPDev posted.)

The really old school technique is to convert images to data and compile them into the program. At that point, you can do whatever you want.

1 Like

Another useful technique.

But direct support for PNGs straight out of Photoshop (or wherever) is SUPER productive with 1-bit PNGs, allowing rapid iteration. The same for grayscale would great!

I use multiple, layered 1-bit PNGs.

But you can load any data you want if you give it a name that will not be compiled.

Check out Librif - C library to encode grayscale images for an example.

One issue with 8-bit images is that they're so much larger and speed of access from flash is quite slow.

1 Like