QPixelFormat Class
QPixelFormat 是一个用于描述图形缓冲区中不同像素布局的类。更多
| Header: | #include <QPixelFormat> |
| CMake.QPixelFormat | find_package(Qt6 REQUIRED COMPONENTS Gui)target_link_libraries(mytarget PRIVATE Qt6::Gui) |
| qmake: | QT += gui |
公共类型
| enum | AlphaPosition { AtBeginning, AtEnd } |
| enum | AlphaPremultiplied { NotPremultiplied, Premultiplied } |
| enum | AlphaUsage { IgnoresAlpha, UsesAlpha } |
| enum | ByteOrder { LittleEndian, BigEndian, CurrentSystemEndian } |
| enum | ColorModel { RGB, BGR, Indexed, Grayscale, CMYK, …, Alpha } |
| enum | TypeInterpretation { UnsignedInteger, UnsignedShort, UnsignedByte, FloatingPoint } |
| enum | YUVLayout { YUV444, YUV422, YUV411, YUV420P, YUV420SP, …, Y16 } |
公共函数
| QPixelFormat() | |
| QPixelFormat(QPixelFormat::ColorModel colorModel, uchar firstSize, uchar secondSize, uchar thirdSize, uchar fourthSize, uchar fifthSize, uchar alphaSize, QPixelFormat::AlphaUsage alphaUsage, QPixelFormat::AlphaPosition alphaPosition, QPixelFormat::AlphaPremultiplied premultiplied, QPixelFormat::TypeInterpretation typeInterpretation, QPixelFormat::ByteOrder byteOrder = CurrentSystemEndian, uchar subEnum = 0) | |
| QPixelFormat::AlphaPosition | alphaPosition() const |
| uchar | alphaSize() const |
| QPixelFormat::AlphaUsage | alphaUsage() const |
| uchar | bitsPerPixel() const |
| uchar | blackSize() const |
| uchar | blueSize() const |
| uchar | brightnessSize() const |
| QPixelFormat::ByteOrder | byteOrder() const |
| uchar | channelCount() const |
| QPixelFormat::ColorModel | colorModel() const |
| uchar | cyanSize() const |
| uchar | greenSize() const |
| uchar | hueSize() const |
| uchar | lightnessSize() const |
| uchar | magentaSize() const |
| QPixelFormat::AlphaPremultiplied | premultiplied() const |
| uchar | redSize() const |
| uchar | saturationSize() const |
| QPixelFormat::TypeInterpretation | typeInterpretation() const |
| uchar | yellowSize() const |
| QPixelFormat::YUVLayout | yuvLayout() const |
相关非成员
| QPixelFormat | qPixelFormatAlpha(uchar channelSize, QPixelFormat::TypeInterpretation typeInterpretation = QPixelFormat::UnsignedInteger) |
| QPixelFormat | qPixelFormatCmyk(uchar channelSize, uchar alphaSize = 0, QPixelFormat::AlphaUsage alphaUsage = QPixelFormat::IgnoresAlpha, QPixelFormat::AlphaPosition alphaPosition = QPixelFormat::AtBeginning, QPixelFormat::TypeInterpretation typeInterpretation = QPixelFormat::UnsignedInteger) |
| QPixelFormat | qPixelFormatGrayscale(uchar channelSize, QPixelFormat::TypeInterpretation typeInterpretation = QPixelFormat::UnsignedInteger) |
| QPixelFormat | qPixelFormatHsl(uchar channelSize, uchar alphaSize = 0, QPixelFormat::AlphaUsage alphaUsage = QPixelFormat::IgnoresAlpha, QPixelFormat::AlphaPosition alphaPosition = QPixelFormat::AtBeginning, QPixelFormat::TypeInterpretation typeInterpretation = QPixelFormat::FloatingPoint) |
| QPixelFormat | qPixelFormatHsv(uchar channelSize, uchar alphaSize = 0, QPixelFormat::AlphaUsage alphaUsage = QPixelFormat::IgnoresAlpha, QPixelFormat::AlphaPosition alphaPosition = QPixelFormat::AtBeginning, QPixelFormat::TypeInterpretation typeInterpretation = QPixelFormat::FloatingPoint) |
| QPixelFormat | qPixelFormatRgba(uchar redSize, uchar greenSize, uchar blueSize, uchar alphaSize, QPixelFormat::AlphaUsage alphaUsage, QPixelFormat::AlphaPosition alphaPosition, QPixelFormat::AlphaPremultiplied premultiplied = QPixelFormat::NotPremultiplied, QPixelFormat::TypeInterpretation typeInterpretation = QPixelFormat::UnsignedInteger) |
| QPixelFormat | qPixelFormatYuv(QPixelFormat::YUVLayout yuvLayout, uchar alphaSize = 0, QPixelFormat::AlphaUsage alphaUsage = QPixelFormat::IgnoresAlpha, QPixelFormat::AlphaPosition alphaPosition = QPixelFormat::AtBeginning, QPixelFormat::AlphaPremultiplied premultiplied = QPixelFormat::NotPremultiplied, QPixelFormat::TypeInterpretation typeInterpretation = QPixelFormat::UnsignedByte, QPixelFormat::ByteOrder byteOrder = QPixelFormat::BigEndian) |
详细说明
在 Qt 中,经常需要表示图形缓冲区中的像素布局。QPixelFormat 最多可描述 5 个颜色通道和 1 个 alpha 通道,包括这些通道在内存中的单独表示方式和相互关系的详细信息。
typeInterpretation() 和byteOrder() 决定如何读取/解释每个像素,而alphaSize(),alphaUsage(),alphaPosition() 和premultiplied() 则描述可能的 alpha 通道的位置和属性。
不支持描述 YUV 的宏像素。相反,我们提供了一个YUV formats 列表。当 QPixelFormat 描述 YUV 格式时,bitsPerPixel() 值是从 YUV 布局中推导出来的。
成员类型文档
enum QPixelFormat::AlphaPosition
该枚举描述了alpha position 的像素格式。
| 常量 | 值 | 说明 |
|---|---|---|
QPixelFormat::AtBeginning | 0 | alpha 通道将放在颜色通道之前。例如 ARGB。 |
QPixelFormat::AtEnd | 1 | Alpha 通道将放在颜色通道的后面。例如 RGBA。 |
另请参见 alphaSize()、alphaUsage() 和premultiplied()。
enum QPixelFormat::AlphaPremultiplied
该枚举描述了像素格式的 alpha 通道是否premultiplied 到颜色通道中。
| 常量 | 值 | 说明 |
|---|---|---|
QPixelFormat::NotPremultiplied | 0 | 不将 alpha 通道乘以颜色通道。 |
QPixelFormat::Premultiplied | 1 | alpha 通道与颜色通道相乘。 |
另请参阅 alphaSize()、alphaUsage() 和alphaPosition()。
enum QPixelFormat::AlphaUsage
该枚举描述了alpha usage 的像素格式。
| 常量 | 值 | 说明 |
|---|---|---|
QPixelFormat::IgnoresAlpha | 1 | 不使用 alpha 通道。 |
QPixelFormat::UsesAlpha | 0 | 使用了 alpha 通道。 |
另请参阅 alphaSize(),alphaPosition() 和premultiplied()。
enum QPixelFormat::ByteOrder
该枚举描述了byte order 的像素格式。
| 常量 | 值 | 说明 |
|---|---|---|
QPixelFormat::LittleEndian | 0 | 字节顺序为小字节。 |
QPixelFormat::BigEndian | 1 | 字节顺序为大端。 |
QPixelFormat::CurrentSystemEndian | 2 | 该枚举不会被存储,但会在构造函数中转换为与当前系统枚举相匹配的 endian 枚举。 |
另请参见 typeInterpretation()。
enum QPixelFormat::ColorModel
该枚举描述了color model 的像素格式。
| 常量 | 值 | 说明 |
|---|---|---|
QPixelFormat::RGB | 0 | 颜色模型为 RGB。 |
QPixelFormat::BGR | 1 | 从逻辑上讲,它是 RGB 的对端版本。不过,为了便于使用,它有自己的模型。 |
QPixelFormat::Indexed | 2 | 颜色模型使用调色板。 |
QPixelFormat::Grayscale | 3 | 颜色模型是灰度。 |
QPixelFormat::CMYK | 4 | 色彩模型是 CMYK。 |
QPixelFormat::HSL | 5 | 颜色模型是 HSL。 |
QPixelFormat::HSV | 6 | 色彩模型是 HSV。 |
QPixelFormat::YUV | 7 | 颜色模型是 YUV。 |
QPixelFormat::Alpha | 8 | [自 5.5 起] 没有颜色模型,只使用 alpha。 |
enum QPixelFormat::TypeInterpretation
该枚举描述了type interpretation 的像素格式。
| 常量 | 值 | 说明 |
|---|---|---|
QPixelFormat::UnsignedInteger | 0 | 像素应读作一个或多个unsigned int 。 |
QPixelFormat::UnsignedShort | 1 | 像素应读作一个或多个unsigned short 。 |
QPixelFormat::UnsignedByte | 2 | 像素应读作一个或多个byte 。 |
QPixelFormat::FloatingPoint | 3 | 像素应读作一个或多个浮点数,具体类型由颜色/阿尔法通道定义,即qfloat16 表示 16 位半浮点格式,float 表示 32 位全浮点格式。 |
另请参见 byteOrder()。
enum QPixelFormat::YUVLayout
该枚举描述了像素格式的YUV layout ,其色彩模型为QPixelFormat::YUV 。
| 常量 | 值 |
|---|---|
QPixelFormat::YUV444 | 0 |
QPixelFormat::YUV422 | 1 |
QPixelFormat::YUV411 | 2 |
QPixelFormat::YUV420P | 3 |
QPixelFormat::YUV420SP | 4 |
QPixelFormat::YV12 | 5 |
QPixelFormat::UYVY | 6 |
QPixelFormat::YUYV | 7 |
QPixelFormat::NV12 | 8 |
QPixelFormat::NV21 | 9 |
QPixelFormat::IMC1 | 10 |
QPixelFormat::IMC2 | 11 |
QPixelFormat::IMC3 | 12 |
QPixelFormat::IMC4 | 13 |
QPixelFormat::Y8 | 14 |
QPixelFormat::Y16 | 15 |
成员函数文档
[constexpr noexcept] QPixelFormat::QPixelFormat()
创建空像素格式。该格式映射到QImage::Format_Invalid 。
[constexpr noexcept] QPixelFormat::QPixelFormat(QPixelFormat::ColorModel colorModel, uchar firstSize, uchar secondSize, uchar thirdSize, uchar fourthSize, uchar fifthSize, uchar alphaSize, QPixelFormat::AlphaUsage alphaUsage, QPixelFormat::AlphaPosition alphaPosition, QPixelFormat::AlphaPremultiplied premultiplied, QPixelFormat::TypeInterpretation typeInterpretation, QPixelFormat::ByteOrder byteOrder = CurrentSystemEndian, uchar subEnum = 0)
创建一个 QPixelFormat,并将其数据分配给属性。colorModel 将被放入一个 4 位长的缓冲区。
firstSize secondSize thirdSize fourthSize fifthSize alphaSize 所有这些都是为了表示通道的大小。通道的不同用途取决于colorModel 。对于 RGB,firstSize 表示红色通道。对于 CMYK,它代表青色通道的值。
alphaUsage 代表是否使用 alpha 通道。
alphaPosition 是 alpha 通道的位置。
premultiplied 表示 alpha 通道是否已与颜色通道相乘。
typeInterpretation 是像素的解释方式。
byteOrder 表示像素格式的字节序。默认值为CurrentSystemEndian ,对于非字节有序格式,该值将被解析为系统的字节序,对于QPixelFormat::UnsignedByte ,该值将被解析为QPixelFormat::BigEndian 。
subEnum 用于需要通过提供额外枚举来存储一些额外信息的 colorModels。默认值为 0。
注意: BGR 格式有自己的颜色模型,不应使用与 RGB 格式相反的字节序来描述。
[constexpr noexcept] QPixelFormat::AlphaPosition QPixelFormat::alphaPosition() const
阿尔法通道相对于颜色通道位置的访问函数。
对于单个通道映射到单个单位的格式,alpha 位置是相对于这些单位而言的。例如,QImage::Format_RGBA16FPx4 的 alpha 位置为QPixelFormat::AtEnd ,alpha 就是最后读取的qfloat16 。
对于将多个通道打包成一个单元的格式,QPixelFormat::AtBeginning 和QPixelFormat::AtEnd 的值映射到打包单元的最重要位和最不重要位,与格式本身的byteOrder() 相对。
例如,对于QImage::Format_ARGB32 ,其类型解释为QPixelFormat::UnsignedInteger ,而byteOrder() 始终与主机系统相匹配,QPixelFormat::AtBeginning 的 alpha 位置意味着 alpha 始终可以在0xFF000000 找到。
如果像素格式和主机字节序不匹配,必须注意将像素格式布局正确映射到主机内存布局。
另请参阅 alphaUsage()、alphaSize() 和premultiplied()。
[constexpr noexcept] uchar QPixelFormat::alphaSize() const
alpha 通道大小的访问函数。
[constexpr noexcept] QPixelFormat::AlphaUsage QPixelFormat::alphaUsage() const
是否使用 alpha 通道的访问函数。
有时像素格式会为 alpha 通道预留位置,因此alphaSize() 将返回 > 0,但 alpha 通道未被使用/忽略。
例如,对于QImage::Format_RGB32 ,bitsPerPixel() 为 32,因为 alpha 通道的大小为 8,但 alphaUsage() 反映的是QPixelFormat::IgnoresAlpha 。
请注意,在这种情况下,未使用的 alpha 通道的position 仍然很重要,因为它会影响颜色通道的位置。
另请参见 alphaPosition()、alphaSize() 和premultiplied()。
[constexpr noexcept] uchar QPixelFormat::bitsPerPixel() const
每个像素所用比特的访问函数。该函数返回所有颜色通道的总和 + Alpha 通道的大小。
[constexpr noexcept] uchar QPixelFormat::blackSize() const
黑色/关键色通道的辅助功能。
[constexpr noexcept] uchar QPixelFormat::blueSize() const
蓝色通道大小的访问函数。
[constexpr noexcept] uchar QPixelFormat::brightnessSize() const
亮度通道尺寸的访问函数。
[constexpr noexcept] QPixelFormat::ByteOrder QPixelFormat::byteOrder() const
像素格式的字节顺序决定了各个类型单元的内存布局,如typeInterpretation() 所述。
该函数永远不会返回QPixelFormat::CurrentSystemEndian ,因为该值会在构造函数中转换为系统的 endian 值。
对于带有typeInterpretation()QPixelFormat::UnsignedByte 的像素格式,通常会返回QPixelFormat::BigEndian ,而其他类型的解释通常会反映当前系统的字节序。
如果像素格式的字节序与当前系统一致,则无论主机系统的字节序如何,都可以使用相同的位掩码和操作来读取和处理单个类型单元。例如,对于具有QPixelFormat::UnsignedInteger 类型解释的QImage::Format_ARGB32 ,无论主机系统的字节序如何,都可以通过屏蔽unsigned int 和0xFF000000 来读取 alpha。
如果像素格式和主机的 endianness不匹配,则必须考虑到这一点。在这种情况下,像QImage 这样的类不会交换内部位来匹配主机系统的 endianness。
另请参阅 typeInterpretation() 和alphaPosition()。
[constexpr noexcept] uchar QPixelFormat::channelCount() const
通道计数的访问函数。
通道计数代表大小大于 0 的通道(颜色和 Alpha)。
[constexpr noexcept] QPixelFormat::ColorModel QPixelFormat::colorModel() const
颜色模型的访问函数。
请注意,对于QPixelFormat::YUV ,无法描述单个宏像素。取而代之的是提供一个YUV formats 列表,并从 YUV 布局中推导出bitsPerPixel() 值。
[constexpr noexcept] uchar QPixelFormat::cyanSize() const
青色通道的访问函数。
[constexpr noexcept] uchar QPixelFormat::greenSize() const
绿色通道大小的访问函数。
[constexpr noexcept] uchar QPixelFormat::hueSize() const
色调通道大小的访问函数。
[constexpr noexcept] uchar QPixelFormat::lightnessSize() const
亮度通道大小的访问函数。
[constexpr noexcept] uchar QPixelFormat::magentaSize() const
洋红颜色通道的访问函数。
[constexpr noexcept] QPixelFormat::AlphaPremultiplied QPixelFormat::premultiplied() const
访问函数,用于确定是否将 alpha 通道乘以颜色通道。
[constexpr noexcept] uchar QPixelFormat::redSize() const
红色通道大小的访问函数。
[constexpr noexcept] uchar QPixelFormat::saturationSize() const
饱和通道大小的访问函数。
[constexpr noexcept] QPixelFormat::TypeInterpretation QPixelFormat::typeInterpretation() const
类型解释决定了每个像素的读取方式。
每个像素表示为一个或多个指定类型的单元,在内存中按顺序排列。
注意: 像素格式的byte order 和主机系统的 endianness 只影响每个被读单元的内存布局,而不影响单元的相对排序。
例如,QImage::Format_Mono 有一个每像素 1 位的pixel format 和一个QPixelFormat::UnsignedByte 类型解释,应作为单个byte 读取。同样,QImage::Format_RGB888 的pixel format 为每个像素 24 位,而QPixelFormat::UnsignedByte 的类型解释应读作三个连续的bytes。
许多QImage formats 是 32 位的,其类型解释为QPixelFormat::UnsignedInteger ,应读作单个unsigned int 。
对于QPixelFormat::FloatingPoint 格式(如QImage::Format_RGBA16FPx4 或QImage::Format_RGBA32FPx4 ),其类型根据各个颜色/阿尔法通道的大小确定,qfloat16 表示 16 位半浮点格式,float 表示 32 位全浮点格式。
另请参阅 byteOrder() 。
[constexpr noexcept] uchar QPixelFormat::yellowSize() const
黄色通道的访问函数。
[constexpr noexcept] QPixelFormat::YUVLayout QPixelFormat::yuvLayout() const
YUVLayout 的访问函数。由于 YUV 颜色模型使用宏像素,因此很难描述 YUV 像素格式的颜色通道。相反,像素的布局是以枚举形式存储的。
相关非会员
[constexpr noexcept] QPixelFormat qPixelFormatAlpha(uchar channelSize, QPixelFormat::TypeInterpretation typeInterpretation = QPixelFormat::UnsignedInteger)
用于创建 Alpha 格式的构造函数。通过向channelSize 传递 1,可以描述遮罩格式。也可以通过向channelSize 传递 8 和向typeInterpretation 传递FloatingPoint ,使用双倍来描述每个像素,从而定义非常精确的 Alpha 格式。
另请参见 QPixelFormat::TypeInterpretation 。
[constexpr noexcept] QPixelFormat qPixelFormatCmyk(uchar channelSize, uchar alphaSize = 0, QPixelFormat::AlphaUsage alphaUsage = QPixelFormat::IgnoresAlpha, QPixelFormat::AlphaPosition alphaPosition = QPixelFormat::AtBeginning, QPixelFormat::TypeInterpretation typeInterpretation = QPixelFormat::UnsignedInteger)
用于创建 CMYK 格式的构造函数。通道数将为 4 或 5,取决于alphaSize 是否大于 0。CMYK 颜色通道将全部设置为channelSize 的值。
alphaUsage alphaPosition 和typeInterpretation 都可以通过同名访问器访问。
另请参阅 QPixelFormat::TypeInterpretation 。
[constexpr noexcept] QPixelFormat qPixelFormatGrayscale(uchar channelSize, QPixelFormat::TypeInterpretation typeInterpretation = QPixelFormat::UnsignedInteger)
用于创建灰度格式的构造函数。单色格式可以通过向channelSize 传递 1 来描述。也可以通过向channelSize 传递 8 和向typeInterpretation 传递FloatingPoint 来定义非常精确的灰度格式,使用双倍来描述每个像素。
另请参阅 QPixelFormat::TypeInterpretation 。
[constexpr noexcept] QPixelFormat qPixelFormatHsl(uchar channelSize, uchar alphaSize = 0, QPixelFormat::AlphaUsage alphaUsage = QPixelFormat::IgnoresAlpha, QPixelFormat::AlphaPosition alphaPosition = QPixelFormat::AtBeginning, QPixelFormat::TypeInterpretation typeInterpretation = QPixelFormat::FloatingPoint)
用于创建 HSL 格式的构造函数。通道数将为 3 或 4,取决于alphaSize 是否大于 0。
channelSize 将hueSize saturationSize 和lightnessSize 设置为相同的值。
alphaUsage alphaPosition 和typeInterpretation 都可以通过同名访问器访问。
[constexpr noexcept] QPixelFormat qPixelFormatHsv(uchar channelSize, uchar alphaSize = 0, QPixelFormat::AlphaUsage alphaUsage = QPixelFormat::IgnoresAlpha, QPixelFormat::AlphaPosition alphaPosition = QPixelFormat::AtBeginning, QPixelFormat::TypeInterpretation typeInterpretation = QPixelFormat::FloatingPoint)
用于创建 HSV 格式的构造函数。通道数将为 3 或 4,取决于alphaSize 是否大于 0。
channelSize 将hueSize saturationSize 和brightnessSize 设置为相同的值。
alphaUsage alphaPosition 和typeInterpretation 都可以通过同名访问器访问。
[constexpr noexcept] QPixelFormat qPixelFormatRgba(uchar redSize, uchar greenSize, uchar blueSize, uchar alphaSize, QPixelFormat::AlphaUsage alphaUsage, QPixelFormat::AlphaPosition alphaPosition, QPixelFormat::AlphaPremultiplied premultiplied = QPixelFormat::NotPremultiplied, QPixelFormat::TypeInterpretation typeInterpretation = QPixelFormat::UnsignedInteger)
redSize greenSize blueSize 表示每个颜色通道的大小。alphaSize 描述 alpha 通道的大小,其位置用alphaPosition 描述。alphaUsage 用于确定是否使用 alpha 通道。将 alpha 通道大小设为 8,并将alphaUsage 设为IgnoresAlpha ,就可以创建 32 位格式,其中 rgb 通道只使用 24 位组合。premultiplied typeInterpretation 可通过同名访问器访问。
另请参见 QPixelFormat::TypeInterpretation 。
QPixelFormat qPixelFormatYuv(QPixelFormat::YUVLayout yuvLayout, uchar alphaSize = 0, QPixelFormat::AlphaUsage alphaUsage = QPixelFormat::IgnoresAlpha, QPixelFormat::AlphaPosition alphaPosition = QPixelFormat::AtBeginning, QPixelFormat::AlphaPremultiplied premultiplied = QPixelFormat::NotPremultiplied, QPixelFormat::TypeInterpretation typeInterpretation = QPixelFormat::UnsignedByte, QPixelFormat::ByteOrder byteOrder = QPixelFormat::BigEndian)
构造函数,用于创建QPixelFormat ,用yuvLayout 描述 YUV 格式。alphaSize 描述潜在的 alpha 通道的大小,用alphaPosition 描述其位置。第一""第二"...... "第五 "通道均设置为 0。alphaUsage premultiplied typeInterpretation 和byteOrder 将与其他格式一样工作。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.