QPixelFormat Class
QPixelFormat is a class for describing different pixel layouts in graphics buffers. More...
Header: | #include <QPixelFormat> |
qmake: | QT += gui |
Since: | Qt 5.4 |
Public Types
enum | AlphaPosition { AtBeginning, AtEnd } |
enum | AlphaPremultiplied { NotPremultiplied, Premultiplied } |
enum | AlphaUsage { IgnoresAlpha, UsesAlpha } |
enum | ByteOrder { LittleEndian, BigEndian, CurrentSystemEndian } |
enum | ColorModel { RGB, BGR, Indexed, Grayscale, ..., Alpha } |
enum | TypeInterpretation { UnsignedInteger, UnsignedShort, UnsignedByte, FloatingPoint } |
enum | YUVLayout { YUV444, YUV422, YUV411, YUV420P, ..., Y16 } |
Public Functions
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 |
uchar | subEnum() const |
QPixelFormat::TypeInterpretation | typeInterpretation() const |
uchar | yellowSize() const |
QPixelFormat::YUVLayout | yuvLayout() const |
Detailed Description
QPixelFormat is a class for describing different pixel layouts in graphics buffers.
In Qt there is a often a need to represent the layout of the pixels in a graphics buffer. Internally QPixelFormat stores everything in a 64 bit datastructure. This gives performance but also some limitations.
QPixelFormat can describe 5 color channels and 1 alpha channel, each can use 6 bits to describe the size of the color channel.
The position of the alpha channel is described with a separate enum. This is to make it possible to describe QImage formats like ARGB32, and also describe typical OpenGL formats like RBGA8888.
How pixels are suppose to be read is determined by the TypeInterpretation enum. It describes if color values are suppose to be read byte per byte, or if a pixel is suppose to be read as a complete int and then masked.
There is no support for describing YUV's macro pixels. Instead a list of YUV formats has been made. When a QPixelFormat is describing a YUV format, the bitsPerPixel value has been deduced by the YUV Layout enum. Also, the color channels should all be set to zero except the fifth color channel that should store the bitsPerPixel value.
See also TypeInterpretation.
Member Type Documentation
enum QPixelFormat::AlphaPosition
This enum type is used to describe the alpha channels position relative to the color channels.
Constant | Value | Description |
---|---|---|
QPixelFormat::AtBeginning | 0 | The alpha channel will be put in front of the color channels . E.g. ARGB. |
QPixelFormat::AtEnd | 1 | The alpha channel will be put in the back of the color channels. E.g. RGBA. |
enum QPixelFormat::AlphaPremultiplied
This enum type describes the boolean state if the alpha channel is multiplied into the color channels or not.
Constant | Value | Description |
---|---|---|
QPixelFormat::NotPremultiplied | 0 | The alpha channel is not multiplied into the color channels. |
QPixelFormat::Premultiplied | 1 | The alpha channel is multiplied into the color channels. |
enum QPixelFormat::AlphaUsage
This enum describes if the alpha channel is used or not. Sometimes the pixelformat will have a size for the alpha channel, but the pixel format does actually not use the alpha channel. For example RGB32 is such a format. The RGB channels are 8 bits each, and there is no alpha channel. But the complete size for each pixel is 32. Therefore the alpha channel size is 8, but the alpha channel is ignored. Its important to note that in such situations the position of the alpha channel is significant.
Constant | Value | Description |
---|---|---|
QPixelFormat::IgnoresAlpha | 1 | The alpha channel is not used. |
QPixelFormat::UsesAlpha | 0 | The alpha channel is used. |
enum QPixelFormat::ByteOrder
This enum describes the ByteOrder of the pixel format. This enum is mostly ignored but have some use cases for YUV formats. BGR formats have their own color model, and should not be described by using the opposite endianness on an RGB format.
Constant | Value | Description |
---|---|---|
QPixelFormat::LittleEndian | 0 | The byte order is little endian. |
QPixelFormat::BigEndian | 1 | The byte order is big endian. |
QPixelFormat::CurrentSystemEndian | 2 | This enum will not be stored, but is converted in the constructor to the endian enum that matches the enum of the current system. |
enum QPixelFormat::ColorModel
This enum type is used to describe the color model of the pixelformat. Alpha was added in 5.5.
Constant | Value | Description |
---|---|---|
QPixelFormat::RGB | 0 | The color model is RGB. |
QPixelFormat::BGR | 1 | This is logically the opposite endian version of RGB. However, for ease of use it has its own model. |
QPixelFormat::Indexed | 2 | The color model uses a color palette. |
QPixelFormat::Grayscale | 3 | The color model is Grayscale. |
QPixelFormat::CMYK | 4 | The color model is CMYK. |
QPixelFormat::HSL | 5 | The color model is HSL. |
QPixelFormat::HSV | 6 | The color model is HSV. |
QPixelFormat::YUV | 7 | The color model is YUV. |
QPixelFormat::Alpha | 8 | There is no color model, only alpha is used. |
enum QPixelFormat::TypeInterpretation
This enum describes how each pixel is interpreted. If a pixel is read as a full 32 bit unsigned integer and then each channel is masked out, or if each byte is read as unsigned char values. Typically QImage formats interpret one pixel as an unsigned integer and then the color channels are masked out. OpenGL on the other hand typically interpreted pixels "one byte after the other", Ie. unsigned byte.
QImage also have the format Format_RGBA8888 (and its derivatives), where the pixels are interpreted as unsigned bytes. OpenGL has extensions that makes it possible to upload pixel buffers in an unsigned integer format.
The image above shows a ARGB pixel in memory read as an unsigned integer. However, if this pixel was read byte for byte on a little endian system the first byte would be the byte containing the B-channel. The next byte would be the G-channel, then the R-channel and finally the A-channel. This shows that on little endian systems, how each pixel is interpreted is significant for integer formats. This is not the case on big endian systems.
Constant | Value |
---|---|
QPixelFormat::UnsignedInteger | 0 |
QPixelFormat::UnsignedShort | 1 |
QPixelFormat::UnsignedByte | 2 |
QPixelFormat::FloatingPoint | 3 |
enum QPixelFormat::YUVLayout
YUV is not represented by describing the size of the color channels. This is because YUV often use macro pixels, making the concept of sperate color channels invalid. Instead the different YUV layouts are described with this enum.
Constant | Value |
---|---|
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 |
Member Function Documentation
QPixelFormat::QPixelFormat()
Default constructs an instance of QPixelFormat.
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)
Default constructs an instance of QPixelFormat.