r/GraphicsProgramming • u/Aspie96 • 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:
Format1bppIndexedFormat4bppIndexedFormat8bppIndexedFormat8bppGrayFormat16bppRgb555Format16bppRgb565Format24bppRgbFormat32bppXrgbFormat32bppArgbFormat32bppRgba
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!
View all comments
Show parent comment
1
u/Aspie96 Aug 22 '26
Thank you for your wisdom.
The library is essentially one to write glue code. It should allow creating a view of an image with has been loaded in memory using another library, as well as passing an image that is in memory to an existing library. This essentially provides a unified API that can be used to handle images while using multiple libraries.
I plagiarized the name structure from .NET, while the set of pixel formats I support isn't exactly the same.
As I said, all pixel format with more than 1 byte per pixel are supported in both big endian and little endian mode.
So, for example, the XRGB format in little endian mode is the BGRX format that you suggest.
The thing is, if the user has an image in RGBA (or ABGR) format in memory, they would need an RGBX (or XBGR) format to have an opaque view of that image (without duplicating any data).
In general RGBA is more common than ARGB (which is used by Microsoft), yet I haven't found examples of the RGBX (or XBGR) being used.
Oh, I do load it.
My question is specifically about what representations in memory I should support. From file I load all that is supported.
Do you have any idea why the GrayAlpha pixel format even exists? It seems to me to be of very little utility compared to other formats.