PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Image Formats

Moose or Chuck · 22 Oct 2001, 23:08 UTC
Howdy, I've been thinking about sprite engines lately and wonder about the color depth vs size trade off of images.

If a tile engine used sprites of 32x32 (1024 pixels) in size (roughly 7.5w x 10h to tile a pocketpc screen), the uncompressed storage size in memory is about 16k for a 16bit image.  

I don't see really having that many unique colors per tile (on something this small) so what color depth seems to be the best with size being a key factor?

Also, as far as the easyCE framebuffer goes, it pretty much expects 16bit color data? So if another color depth was used, would the speed of translating that to 16bit be worth the space savings?

I welcome your thoughts. - Ketamine
I'd probably look at RLE compression.

try either RLE or ZIP or jpg compression, depends what style your image is and what you expect from it. Using higher color depth is good thru, if you use effects like alpha-blending, cause it does some work on colors and with poor color depth you pretty fast end-up with poor results (ie colors change by "jumping" , not smooth, very easy to spot by human eye. (using 4444 image with alpha-blending in 32bpp mode really suxx;)
RLE will allow you to use the compressed image, while with other compression formats you'll need to decompress the image into a buffer first.  This means that a game using RLE will have a smaller working set but will probably require a bit more disk space to store the images compared to zip or jpeg.  

As Mirek said, a lot of this depends on your sprite data.  RLE works great for images that contain spans of the same color, or multiple spans containing the same patterns of pixels.  Your tile sizes are relatively small, so you won't get a tremendous win by using RLE.  It can help quite a bit if alpha blending though.

Moose or Chuck · 23 Oct 2001, 22:27 UTC
I am not sure that RLE is the way to go.  I tried it on a few sample tiles and the savings really weren't that great. Most bloated due to the adjacent pixels being of a different color.  I could optimize my sprites to work with this but I would really prefer something to work with a universal / generic tile / sprite set.  

So, as far as the on the fly decompression, that would save the space on the storage side but I am not sure that I have been swayed due to the decompression phase.

most hand held devices (pocket pc / pspc) have a 16bit color depth?  What would be the benefit of using a 32bit image?  It's not like I am going to be alpha blending that many layers due to the overall speed of these machines.

what have most of you used for your projects?

- ketamine
Perhaps I misunderstood your original question.  Do you want to reduce the size of your game on the disk, or do you want to reduce the amount of RAM it takes to run the game?

My sprites are 16-bpp, but any alpha blending is done at 24-bpp, with a separate 8-bpp alpha mask.

katamine:if you use "real world images" RLE compression won't bring you anywhere. RLE compression is only good for "cartoon-like" images where you use several colors per image mostly. If you want compress "real world images" (ie scanned pictures) you can get good results with both zip and jpg (you lose quality with jpg thru, but get much better results for images where zip can't find any decent patterns) There are both free zip and jpg libraries to use. The only drawback is that you have to first unpack a jpg/zip into a buffer in mem before using it. So you end up using less disk space and the same mem space (and you have a longer loading time because you need to uncompress images)

Personally I'm going to use ZIP to compress all my pictures into one/few pack(s), which will be uncompressed during loading time. All tiles in memory will be kept in full 16bpp format without any kind of compression (well actually alpha-blended ones might end up with a kind of RLE compression of alpha channel) all other images will end exactly the same way (ie if it's transparent or has alpha-channel then alpha-channel is compressed with RLE, other pictures stay uncompressed)

Hope it helps you a bit:)