gpt4 book ai didi

c++ - 为什么 windows GDI 对 `COLORREF` 使用 RGBA 格式而不是 BGRA?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:50:42 50 4
gpt4 key购买 nike

MSDN states :

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

0x00bbggrr

The low-order byte contains avalue for the relative intensity of red; the second byte contains avalue for green; and the third byte contains a value for blue. Thehigh-order byte must be zero. The maximum value for a single byte is0xFF.

来自 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))

由于 windows 是小端,COLORREF 是 RGBA 格式。这看起来很奇怪,因为 Windows 内部使用的颜色格式不是 BGR(A) 吗?

RGBQUAD结构定义为

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

COLORREF 不同的是,BGRA。

由于 bitblt 函数需要一个 COLORREF 值数组,这意味着在每次调用期间,如果 Windows 使用BGRA 作为其原生格式。

我记错了,但我也曾在某处读到过,在 winapi 中使用的像素格式有一种奇怪的混合。

有人可以解释一下吗?

最佳答案

COLORREF 可以追溯到像素格式标准化程度低得多的时候。许 multimap 形适配器仍在使用调色板而不是完整的 24 位或 32 位颜色,因此即使您的适配器需要字节重新排序,您也不需要做很多。一些图形适配器甚至将图像存储在单独的颜色平面中,而不是多 channel 颜色的单一平面中。当时没有“正确”答案。

RGBQUADs 来自 BMP 格式,正如 Raymond Chen 在评论中提到的那样,来自 OS/2 位图格式。

关于c++ - 为什么 windows GDI 对 `COLORREF` 使用 RGBA 格式而不是 BGRA?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30883102/

50 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com