In the games I make, sometimes I need to balance the quality of the images I show with the amount of memory they consume. This is especially true for smartphones and other devices with very tight memory constraints.
Most of the time, images are saved in 24 or 32 bit formats, depending on whether or not there is an alpha channel, and graphic programs make use of the full 32 bits.
In order to reduce the memory used by some images, some times I have to reduce the memory they consume by loading them for example in 16 bits: 5 for red, 6 for green and 5 for blue. However, this process creates banding and other nasty artifacts, as the downsampling process is performed by fitting each pixel separately to the reduced palette.
I'm looking for a process to quantize an image to an arbitrary bitdepth, with dithering. In fact, I am a great fan of pngquant, which palettizes an image down to 256 colors, and applies dithering very intelligently to achieve some very impressive results. The problem is that the quantized colors are still 32 bits, and while this may reduce the size of the file, it won't reduce the amount of memory consumed once the image is loaded.
The tool I'm looking for should optimize on the decompressed size of the image, based on an arbitrary texture format, by reducing the amount of bits used by each pixel, and dithering where necessary to minimize the perceived detail and color loss. It doesn't really matter if the image is actually saved with 32 bits per pixel, as long as when it is loaded as a lower depth image, no further truncations occur. Optimally, this tool would also palettize the image, and minimize both file and uncompressed size.
In other words, how do I turn this image:
into, for example, this dithered R1G1B1 image?
Of course, I want to set the bitdepth myself. Notice that this is irrespective of the file format.