Lately I ve been interested in representing uncompressed bitmaps in memory. However, one thing I m not sure how to implement properly is binary transparency. E.g., I start out with something like this:
struct RGBPixel {
uint8_t red;
uint8_t green;
uint8_t blue;
};
struct bitmap {
struct RGBPixel *data;
size_t width;
size_t height;
size_t bytesPerPixel;
size_t bytewidth;
/* etc. */
};
I suppose the simplest way would be this:
struct RGBPixel {
uint8_t red;
uint8_t green;
uint8_t blue;
bool transparent;
};
But that seems a bit wasteful (you might as well add a full alpha channel). The only other possibility I can think of is to reserve one of the colors as being transparent, but then you lose the ability to display that color. Is there a standard way to do this?
How do common formats (GIF, 8-bit PNG, etc.) represent this?