PySide6.QtGui.QPixelFormat¶
- class QPixelFormat¶
QPixelFormatis a class for describing different pixel layouts in graphics buffers.Details
In Qt there is a often a need to represent the layout of the pixels in a graphics buffer.
QPixelFormatcan describe up to 5 color channels and 1 alpha channel, including details about how these channels are represented in memory individually and in relation to each other.The
typeInterpretation()andbyteOrder()determines how each pixel should be read/interpreted, whilealphaSize(),alphaUsage(),alphaPosition(), andpremultiplied()describes the position and properties of the possible alpha channel.There is no support for describing YUV’s macro pixels. Instead a list of
YUV formatsis provided. When aQPixelFormatdescribes a YUV format, thebitsPerPixel()value is deduced from the YUV layout.Synopsis¶
Methods¶
def
__init__()def
alphaPosition()def
alphaSize()def
alphaUsage()def
bitsPerPixel()def
blackSize()def
blueSize()def
brightnessSize()def
byteOrder()def
channelCount()def
colorModel()def
cyanSize()def
greenSize()def
hueSize()def
lightnessSize()def
magentaSize()def
__ne__()def
__eq__()def
premultiplied()def
redSize()def
saturationSize()def
subEnum()def
yellowSize()def
yuvLayout()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
- class FieldWidth¶
- class Field¶
- class ColorModel¶
This enum describes the
color modelof the pixel format.Constant
Description
QPixelFormat.ColorModel.RGB
The color model is RGB.
QPixelFormat.ColorModel.BGR
This is logically the opposite endian version of RGB. However, for ease of use it has its own model.
QPixelFormat.ColorModel.Indexed
The color model uses a color palette.
QPixelFormat.ColorModel.Grayscale
The color model is Grayscale.
QPixelFormat.ColorModel.CMYK
The color model is CMYK.
QPixelFormat.ColorModel.HSL
The color model is HSL.
QPixelFormat.ColorModel.HSV
The color model is HSV.
QPixelFormat.ColorModel.YUV
The color model is YUV.
QPixelFormat.ColorModel.Alpha
[since 5.5] There is no color model, only alpha is used.
- class AlphaUsage¶
This enum describes the
alpha usageof the pixel format.Constant
Description
QPixelFormat.AlphaUsage.IgnoresAlpha
The alpha channel is not used.
QPixelFormat.AlphaUsage.UsesAlpha
The alpha channel is used.
See also
- class AlphaPosition¶
This enum describes the
alpha positionof the pixel format.Constant
Description
QPixelFormat.AlphaPosition.AtBeginning
The alpha channel will be put in front of the color channels. E.g. ARGB.
QPixelFormat.AlphaPosition.AtEnd
The alpha channel will be put in the back of the color channels. E.g. RGBA.
See also
- class AlphaPremultiplied¶
This enum describes whether the alpha channel of the pixel format is
premultipliedinto the color channels or not.Constant
Description
QPixelFormat.AlphaPremultiplied.NotPremultiplied
The alpha channel is not multiplied into the color channels.
QPixelFormat.AlphaPremultiplied.Premultiplied
The alpha channel is multiplied into the color channels.
See also
- class TypeInterpretation¶
This enum describes the
type interpretationof the pixel format.Constant
Description
QPixelFormat.TypeInterpretation.UnsignedInteger
The pixels should be read as one or more
unsigned int.QPixelFormat.TypeInterpretation.UnsignedShort
The pixels should be read as one or more
unsigned short.QPixelFormat.TypeInterpretation.UnsignedByte
The pixels should be read as one or more
byte.QPixelFormat.TypeInterpretation.FloatingPoint
The pixels should be read as one or more floating point numbers, with the concrete type defined by the color/alpha channel, ie.
qfloat16for 16-bit half-float formats andfloatfor 32-bit full-float formats.See also
- class YUVLayout¶
This enum describes the
YUV layoutof the pixel format, given that it has a color model ofYUV.Constant
Description
QPixelFormat.YUVLayout.YUV444
QPixelFormat.YUVLayout.YUV422
QPixelFormat.YUVLayout.YUV411
QPixelFormat.YUVLayout.YUV420P
QPixelFormat.YUVLayout.YUV420SP
QPixelFormat.YUVLayout.YV12
QPixelFormat.YUVLayout.UYVY
QPixelFormat.YUVLayout.YUYV
QPixelFormat.YUVLayout.NV12
QPixelFormat.YUVLayout.NV21
QPixelFormat.YUVLayout.IMC1
QPixelFormat.YUVLayout.IMC2
QPixelFormat.YUVLayout.IMC3
QPixelFormat.YUVLayout.IMC4
QPixelFormat.YUVLayout.Y8
QPixelFormat.YUVLayout.Y16
- class ByteOrder¶
This enum describes the
byte orderof the pixel format.Constant
Description
QPixelFormat.ByteOrder.LittleEndian
The byte order is little endian.
QPixelFormat.ByteOrder.BigEndian
The byte order is big endian.
QPixelFormat.ByteOrder.CurrentSystemEndian
This enum will not be stored, but is converted in the constructor to the endian enum that matches the enum of the current system.
See also
- __init__()¶
Creates a null pixelformat. This format maps to
Format_Invalid.- __init__(colorModel, firstSize, secondSize, thirdSize, fourthSize, fifthSize, alphaSize, alphaUsage, alphaPosition, premultiplied, typeInterpretation[, byteOrder=QPixelFormat.ByteOrder.CurrentSystemEndian[, subEnum=0]])
- Parameters:
colorModel –
ColorModelfirstSize – int
secondSize – int
thirdSize – int
fourthSize – int
fifthSize – int
alphaSize – int
alphaUsage –
AlphaUsagealphaPosition –
AlphaPositionpremultiplied –
AlphaPremultipliedtypeInterpretation –
TypeInterpretationbyteOrder –
ByteOrdersubEnum – int
Creates a
QPixelFormatwhich assigns its data to the attributes.colorModelwill be put into a buffer which is 4 bits long.firstSizesecondSizethirdSizefourthSizefifthSizealphaSizeare all meant to represent the size of a channel. The channels will be used for different uses dependent on thecolorModel. For RGB the firstSize will represent the Red channel. On CMYK it will represent the value of the Cyan channel.alphaUsagerepresents if the alpha channel is used or not.alphaPositionis the position of the alpha channel.premultipliedrepresents if the alpha channel is already multiplied with the color channels.typeInterpretationis how the pixel is interpreted.byteOrderrepresents the endianness of the pixelformat. This defaults toCurrentSystemEndian, which will be resolve to the system’s endianness for non-byte-ordered formats, andBigEndianforUnsignedByte.subEnumis used for colorModels that have to store some extra information with supplying an extra enum. This is used by YUV to store the YUV type The default value is 0.Note
BGR formats have their own color model, and should not be described by using the opposite endianness of an RGB format.
- alphaPosition()¶
- Return type:
Accessor function for the position of the alpha channel relative to the color channels.
For formats where the individual channels map to individual units, the alpha position is relative to these units. For example for
Format_RGBA16FPx4which has an alpha position ofAtEnd, the alpha is the lastqfloat16read.For formats where multiple channels are packed into a single unit, the
AtBeginningandAtEndvalues map to the most significant and least significant bits of the packed unit, with respect to the format’s ownbyteOrder().For example, for
Format_ARGB32, which has a type interpretation ofUnsignedIntegerand abyteOrder()that always matches the host system, the alpha position ofAtBeginningmeans that the alpha can always be found at0xFF000000.If the pixel format and host endianness does not match care must be taken to correctly map the pixel format layout to the host memory layout.
See also
- alphaSize()¶
- Return type:
int
Accessor function for the alpha channel size.
- alphaUsage()¶
- Return type:
Accessor function for whether the alpha channel is used or not.
Sometimes the pixel format reserves place for an alpha channel, so
alphaSize()will return > 0, but the alpha channel is not used/ignored.For example, for
Format_RGB32, thebitsPerPixel()is 32, because the alpha channel has a size of 8, but alphaUsage() reflectsIgnoresAlpha.Note that in such situations the
positionof the unused alpha channel is still important, as it affects the placement of the color channels.See also
- bitsPerPixel()¶
- Return type:
int
Accessor function for the bits used per pixel. This function returns the sum of all the color channels + the size of the alpha channel.
- blackSize()¶
- Return type:
int
Accessor function for the black/key color channel.
- blueSize()¶
- Return type:
int
Accessor function for the size of the blue color channel.
- brightnessSize()¶
- Return type:
int
Accessor function for the brightness channel size.
The byte order of the pixel format determines the memory layout of the individual type units, as described by the
typeInterpretation().This function will never return
CurrentSystemEndianas this value is translated to the system’s endian value in the constructor.For pixel formats with
typeInterpretation()UnsignedBytethis will typically beBigEndian, while other type interpretations will typically reflect the endianness of the current system.If the byte order of the pixel format matches the current system the individual type units can be read and manipulated using the same bit masks and operations, regardless of the host system endianness. For example, with
Format_ARGB32, which has aUnsignedIntegertype interpretation, the alpha can always be read by masking theunsigned intby0xFF000000, regardless of the host endianness.If the pixel format and host endianness does not match care must be taken to account for this. Classes like
QImagedo not swap the internal bits to match the host system endianness in these cases.See also
- channelCount()¶
- Return type:
int
Accessor function for the channel count.
The channel count represents channels (color and alpha) with a size > 0.
- colorModel()¶
- Return type:
Accessor function for the color model.
Note that for
YUVthe individual macro pixels can not be described. Instead a list ofYUV formatsis provided, and thebitsPerPixel()value is deduced from the YUV layout.- cyanSize()¶
- Return type:
int
Accessor function for the cyan color channel.
- greenSize()¶
- Return type:
int
Accessor function for the size of the green color channel.
- hueSize()¶
- Return type:
int
Accessor function for the hue channel size.
- lightnessSize()¶
- Return type:
int
Accessor function for the lightness channel size.
- magentaSize()¶
- Return type:
int
Accessor function for the megenta color channel.
- __ne__(fmt2)¶
- Parameters:
fmt2 –
QPixelFormat- Return type:
bool
- __eq__(fmt2)¶
- Parameters:
fmt2 –
QPixelFormat- Return type:
bool
- premultiplied()¶
- Return type:
Accessor function for the whether the alpha channel is multiplied in to the color channels.
- redSize()¶
- Return type:
int
Accessor function for the size of the red color channel.
- saturationSize()¶
- Return type:
int
Accessor function for the saturation channel size.
- subEnum()¶
- Return type:
int
- typeInterpretation()¶
- Return type:
The type interpretation determines how each pixel should be read.
Each pixel is represented as one or more units of the given type, laid out sequentially in memory.
Note
The
byte orderof the pixel format and the endianness of the host system only affect the memory layout of each individual unit being read — not the relative ordering of the units.For example,
Format_Monohas apixel formatof 1 bits per pixel and aUnsignedBytetype interpretation, which should be read as a singlebyte. Similarly,Format_RGB888has apixel formatof 24 bits per pixel, and and aUnsignedBytetype interpretation, which should be read as three consecutivebytes.Many of the
QImageformatsare 32-bit with a type interpretation ofUnsignedInteger, which should be read as a singleunsigned int.For
FloatingPointformats likeFormat_RGBA16FPx4orFormat_RGBA32FPx4the type is determined based on the size of the individual color/alpha channels, withqfloat16for 16-bit half-float formats andfloatfor 32-bit full-float formats.See also
- yellowSize()¶
- Return type:
int
Accessor function for the yellow color channel.
Accessor function for the
YUVLayout. It is difficult to describe the color channels of a YUV pixel format since YUV color model uses macro pixels. Instead the layout of the pixels are stored as an enum.