Mono Color Sprite

I was trying to make a black and white game.
And I was wondering in what format to store the sprites on.

I couldnt find anything on the web about image files where each pixel is just one bite (black or white). I could store them as any other format, but It does not feel right to waste so much memory. If theres a format like that i also would be interested in which programs can be used to paint such sprites.

And alongside this, i wanted to know if there is documentation about every format in PixelFormatEnum, cause i cant find that either ;-;

Thanks in advance

Even a monochrome sprite needs an alpha (opacity) channel, so it would need at least two bytes per pixel: one for the color and one for the alpha (for an 8-bit antialiased sprite). But I don’t think there are any suitable two-byte formats.

You could perhaps use SDL_PIXELFORMAT_INDEX8, with a 4-bit monochrome color and a 4-bit alpha, but the size of the palette (1024 bytes) might make that unattractive for small sprites.

There’s this.

1 Like

If we are talking about graphic file formats capable of storing 1-bit images (black or white pixels), you can use the standard BMP format, because it supports 1-bit color depth. You can create and export such files even in MS Paint, although it is better to use a more advanced editor, such as Paint.NET, due to the greater number of tools. In it, during export, you can select 1-bit depth and even apply dithering:

The downside is that AFAIK this format does not compress its content, so to save disk space you will have to compress their content yourself for the purposes of creating such files and decompress their content to be able to load them as an SDL surface/texture.

The top right there’s a link to “offline html” that lets you download all the pages as a zip so you can browse offline. offline html

Almost every lossless image file format includes support for 1-bit color. In particular, both BMP and PNG

PNG also has support for 1-bit color plus 1-bit alpha. If you need full alpha, though, you might find it tricky. (PNG can support a palette with e.g. 1-bit color and 7-bit alpha, but in my experience a lot of image editing tools will just switch to full grayscale+alpha at that point, unless you make extra effort to explicitly define the palette.)

I may be repeating Brian_Raiter’s advice, but if I had the choice here, I would suggest this;

Just store your images as PNG.
Nothing fancy, but limit your palette to black and white alpha-transparent in the image editor (PNG is super optimized for compressing 2 color images).
Then use whatever format the window output is: SDL_GetWindowPixelFormat.
This way your data is optimized for rendering on whatever screen it is asked to be drawn on.

If you load your data into a different format than what the window expects to output, then the machine will be forced to convert the data to the window format behind the scenes in order to display it anyway.

1 Like