Crate retro_pixel [] [src]

This is a crate primarily for working with "retro" image data, but it also works with modern full-color images.

There are two main types of image that we support:

  • An Indexmap has one byte per pixel location, representing an index into some color palette elsewhere. Because it's 1 byte per pixel, the type allows for up to 256 colors at once. The exact colors mapped by each index value aren't tracked by the individual Indexmap instances. If you're trying to emulate the look of an old system (EGA, VGA, NES, GB, etc), you probably only need a single color palette. If you're interested in doing some sort of cool color cycle animation then you'll be wanting to swap around palettes every frame. Either way, the Indexmap doesn't care. Using an Indexmap means you can't do color blending (since no actual colors are known), so you're limited to very basic blits and transforms. At the same time, it does mean the "rendering" happens blazing fast and all that other rust hype.

  • A Bitmap has an actual set of RGBA channel data per pixel. Because of this, you can blend between colors when doing blits, which allows for nice transforms and sub-pixel accurate blits. This library supports both 16 bit pixels (5 bits each for RGB, and 1 A bit) and 32 bit pixels (8 bits each for RGBA). The former is what the SNES, GBC/GBA, and NDS use, the latter is just a normal pixel on any modern screen. In both cases you can ignore the alpha information for a given operation (as appropriate).

Operations are done CPU-side for simplicity, but they also use SIMD as available, so it stays zippy. Most retro setups are very low resolution. VGA is 640x480, the SNES went up to 512x448, and everything else is even smaller than those. You're expected to do the final hardware-accelerated upscale (if any) in whatever graphics system you're displaying the rendered image with (OpenGL, Vulkan, SDL, etc). An example using the winit and gl-rs crates is provided.

Modules

indexmap

The module for images that use indexed color.