As few bits per pixel as possible

Hi guys,

I’m admiring the NES’s capability of using a 4-color palette for each tile. This jam-packs one color into two bits, fitting four pixels into a byte. I admire this lightweight style.

So for fun I want to mimic that in my own SDL application, but I’m not sure if it’s possible. I see that there are different built-in pixel formats, but it looks like the smallest is one byte (SDL_PACKEDLAYOUT_332).

If there is no way to represent a pixel in two bits, then maybe there’s a way to store the pixel information this way to the executable’s ROM and just expand it to 8-bit RGB when you load it?

(You may protest this is unnecessary, but remember, I’m doing this for pleasure.)

Any help is appreciated. Thanks!
Michael

You could use your own loader to create SDL surfaces out of a smaller representation.

However, you’ll probably find better compression code available.
Memory IO is definitely the bottleneck on many systems, and it’s very useful to use compression.

There’s some nice code by Ulf Ekstrom included in pygame to do 1 bit ‘masks’. It’s really lots faster to be able to fit 32 or 64 pixels into one machine word. This is mostly used in pygame for image processing tasks, and collision detection.

Consider something like blosc, and see their posts about how many ‘CPU’ bound functions are actually memory bound. http://blosc.org/

Also see the RLE stuff that was in SDL. If your data was appropriate, this could be very fast.

Using compression, or reduced sized data it’s ‘easy’ to get 4x performance (per core).