r/GraphicsProgramming • • Aug 20 '26

Question On pixel formats

Hi all.

I'm writing a library for representing and managing basic raster RGBA images in D as rectangular arrays of pixels.

Images are represented in row-wise pixel order, either top to bottom (the default) or bottom to top, with each scan line going left to right. Color components are represented as 8-bit integral values ranging between, and including, 0 and 255.

My library doesn't provide any support for other color models, for high dynamic ranges or higher bit depths. What it should allow is reading images from memory that were created with other library.

Some pixel formats are "indexed" (they have a palette) and some are not (they store actual color values). The name implies the structure of the format:

  • Format1bppIndexed
  • Format4bppIndexed
  • Format8bppIndexed
  • Format8bppGray
  • Format16bppRgb555
  • Format16bppRgb565
  • Format24bppRgb
  • Format32bppXrgb
  • Format32bppArgb
  • Format32bppRgba

Formats that use more than 1 byte per pixel allow the user to select between big endian and little endian mode.

I plan to keep supporting all formats I listed here. My question is if there is any I should support in addition to those.

Some candidates may be:

  • Format2bppIndexed (it used to be supported by Microsoft bitmaps and it is by the PNG format).
  • Format16bppGrayAlpha (supported by STB nothings and by the PNG format).
  • Format32bppRgbx (to have an opaque view of an RGBA image).

There may be others I haven't thought or heard of.

The ones I haven't supported seem to me to be less common and of less utility, but maybe there is something I haven't considered.

My question is: what pixel formats should I support in addition to those I already do? Should I support any of the three additional ones I suggested? Why or why not?

Thank you in advance!

4 Upvotes

9 comments sorted by

View all comments

Show parent comment

1

u/fdwr Aug 22 '26

The library is essentially one to write glue code

👍

I plagiarized the name structure from .NET

Yeah, .NET probably copied GDI+'s faux pas. WIC did a little better, but it still has a mix sometimes (like the old GUID_WICPixelFormat32bppRGBA1010102 but then later GUID_WICPixelFormat32bppR10G10B10A2). Then DGXI came along and said "we won't make that same mistake again", and Vulkan is like "indeed, let's improve upon OpenGL's notation".

for example, the XRGB format in little endian mode is the BGRX format that you suggest.

😶 If you have the following pixel format...

struct ______
{
    float32_t r;
    float32_t g;
    float32_t b;
};

...how would you name it? (I know you said your library doesn't support high channel bit sizes, but nonetheless, how would you?) How would you name this one? 🤔

struct ______
{
    uint16_t r;
    uint16_t g;
    uint16_t b;
};

My question is specifically about what representations in memory I should support.

You already support 95% of the interesting formats. So unless you want retro formats and older PC's and video game consoles (particularly bitplane graphics, tiled graphics), I don't see any more to add.

Do you have any idea why the GrayAlpha pixel format even exists?

It can be used for masks in video games with the gray channel multiplied with a mask color for effects (bright lights, decals, clouds, dirt, bullet holes...), used for fonts (prebaked glyph atlases), and video subtitles, but again, I typically see games just upcast to 32-bpp or use one of the BC formats rather than actual alpha+luminance (which isn't as widely supported).