Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Why does windows GDI use RGBA format for `COLORREF` instead of BGRA?

MSDN states:

When specifying an explicit RGB color, the COLORREF value has the following hexadecimal form:

0x00bbggrr

The low-order byte contains a value for the relative intensity of red; the second byte contains a value for green; and the third byte contains a value for blue. The high-order byte must be zero. The maximum value for a single byte is 0xFF.

From wingdi.h

#define RGB(r,g,b)          ((COLORREF)((BYTE)(r) | ((BYTE)(g) << 8) | ((BYTE)(b) << 16)))

#define GetRValue(rgb)      ((BYTE)  (rgb) )
#define GetGValue(rgb)      ((BYTE) ((rgb) >> 8))
#define GetBValue(rgb)      ((BYTE) ((rgb) >> 16))

As windows is little endian, COLORREF is in RGBA format. This looks strange because isn't the color format that Windows use internally, BGR(A)?

The RGBQUAD structure is defined as

typedef struct tagRGBQUAD {
  BYTE rgbBlue;
  BYTE rgbGreen;
  BYTE rgbRed;
  BYTE rgbReserved;
} RGBQUAD;

which is, unlike COLORREF, BGRA.

Since the bitblt function expects an array of COLORREF values, this means that there is always an additional conversion going on from RGBA to BGRA during every call, if Windows use BGRA as its native format.

I don't remember correctly, but I also read somewhere that there is a strange mix in the pixel format used in the winapi.

Can someone please explain?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

COLORREFs date way back to when there was much less standardization in pixel formats. Many graphics adapters were still using palettes rather than full 24- or 32-bit color, so even if your adapter required a byte re-order, you didn't need to do very many of them. Some graphics adapters even stored images in separate color planes rather than a single plane of multi-channel colors. There was no "right" answer back then.

RGBQUADs came from the BMP format, which as Raymond Chen mentioned in the comments, comes from the OS/2 bitmap format.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!