简体   繁体   English

为什么Windows GDI使用RGBA格式代替`COLORREF`而不是BGRA?

[英]Why does windows GDI use RGBA format for `COLORREF` instead of BGRA?

MSDN states : MSDN声明

When specifying an explicit RGB color, the COLORREF value has the following hexadecimal form: 指定显式RGB颜色时,COLORREF值具有以下十六进制形式:

0x00bbggrr 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. 单个字节的最大值为0xFF。

From wingdi.h 来自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. 由于windows是小端, COLORREF采用RGBA格式。 This looks strange because isn't the color format that Windows use internally, BGR(A)? 这看起来很奇怪,因为它不是Windows内部使用的颜色格式,BGR(A)?

The RGBQUAD structure is defined as RGBQUAD结构定义为

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

which is, unlike COLORREF , BGRA. 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. 由于bitblt函数需要一个COLORREF值数组,这意味着如果Windows使用BGRA作为其本机格式,则在每次调用期间总会有一个从RGBA到BGRA的额外转换。

I don't remember correctly, but I also read somewhere that there is a strange mix in the pixel format used in the winapi. 我不记得了,但我也读到某处,在winapi中使用的像素格式有一种奇怪的混合。

Can someone please explain? 有人可以解释一下吗?

COLORREFs date way back to when there was much less standardization in pixel formats. COLORREF可以追溯到像素格式标准化程度要低得多的时候。 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. 许多图形适配器仍然使用调色板而不是完整的24位或32位颜色,因此即使您的适配器需要重新排序字节,您也不需要执行很多调整。 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. RGBQUADs来自BMP格式,正如Raymond Chen在评论中提到的那样,来自OS / 2位图格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM