QPixelFormat Class

QPixelFormat ist eine Klasse zur Beschreibung von verschiedenen Pixel-Layouts in Grafikpuffern. Mehr...

Kopfzeile: #include <QPixelFormat>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui

Öffentliche Typen

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 }

Öffentliche Funktionen

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::LittleEndian)

Detaillierte Beschreibung

In Qt besteht oft die Notwendigkeit, das Layout der Pixel in einem Grafikpuffer darzustellen. Intern speichert QPixelFormat alles in einer 64 Bit Datenstruktur. Das bringt Leistung, aber auch einige Einschränkungen.

QPixelFormat kann 5 Farbkanäle und 1 Alphakanal beschreiben, jeder kann 6 Bits verwenden, um die Größe des Farbkanals zu beschreiben.

Die Position des Alphakanals wird mit einem separaten Enum beschrieben. Damit ist es möglich, QImage Formate wie ARGB32 zu beschreiben, und auch typische OpenGL-Formate wie RBGA8888 zu beschreiben.

Wie die Pixel gelesen werden sollen, wird durch das TypeInterpretation enum bestimmt. Es beschreibt, ob Farbwerte Byte für Byte gelesen werden sollen, oder ob ein Pixel als kompletter int gelesen und dann maskiert werden soll.

Es gibt keine Unterstützung für die Beschreibung von YUV-Makropixeln. Stattdessen wurde eine Liste von YUV-Formaten erstellt. Wenn ein QPixelFormat ein YUV-Format beschreibt, wurde der Wert bitsPerPixel durch das YUV Layout enum abgeleitet. Außerdem sollten die Farbkanäle alle auf Null gesetzt werden, mit Ausnahme des fünften Farbkanals, der den Wert bitsPerPixel speichern sollte.

Siehe auch TypeInterpretation.

Dokumentation der Mitgliedstypen

enum QPixelFormat::AlphaPosition

Dieser Enum-Typ wird verwendet, um die Position der Alphakanäle relativ zu den Farbkanälen zu beschreiben.

KonstanteWertBeschreibung
QPixelFormat::AtBeginning0Der Alphakanal wird den Farbkanälen vorangestellt. Z.B. ARGB.
QPixelFormat::AtEnd1Der Alphakanal wird hinter den Farbkanälen eingefügt. Z.B. RGBA.

enum QPixelFormat::AlphaPremultiplied

Dieser Enum-Typ beschreibt den booleschen Zustand, ob der Alphakanal mit den Farbkanälen multipliziert wird oder nicht.

KonstanteWertBeschreibung
QPixelFormat::NotPremultiplied0Der Alphakanal wird nicht mit den Farbkanälen multipliziert.
QPixelFormat::Premultiplied1Der Alphakanal wird mit den Farbkanälen multipliziert.

enum QPixelFormat::AlphaUsage

Diese Aufzählung beschreibt, ob der Alphakanal verwendet wird oder nicht. Manchmal hat das Pixelformat eine Größe für den Alphakanal, aber das Pixelformat verwendet den Alphakanal eigentlich nicht. RGB32 ist zum Beispiel ein solches Format. Die RGB-Kanäle haben jeweils 8 Bit, und es gibt keinen Alphakanal. Die Gesamtgröße für jedes Pixel beträgt jedoch 32. Daher ist die Größe des Alphakanals 8, aber der Alphakanal wird ignoriert. Es ist wichtig zu beachten, dass in solchen Situationen die Position des Alphakanals von Bedeutung ist.

KonstanteWertBeschreibung
QPixelFormat::IgnoresAlpha1Der Alphakanal wird nicht verwendet.
QPixelFormat::UsesAlpha0Der Alphakanal wird verwendet.

enum QPixelFormat::ByteOrder

Dieses Enum beschreibt die ByteOrder des Pixelformats. Dieses Enum wird meistens ignoriert, aber es gibt einige Anwendungsfälle für YUV-Formate. BGR-Formate haben ihr eigenes Farbmodell und sollten nicht durch die Verwendung der entgegengesetzten Endianness für ein RGB-Format beschrieben werden.

KonstanteWertBeschreibung
QPixelFormat::LittleEndian0Die Byte-Reihenfolge ist Little Endian.
QPixelFormat::BigEndian1Die Byte-Reihenfolge ist Big Endian.
QPixelFormat::CurrentSystemEndian2Diese Aufzählung wird nicht gespeichert, sondern im Konstruktor in die endianische Aufzählung umgewandelt, die der Aufzählung des aktuellen Systems entspricht.

enum QPixelFormat::ColorModel

Dieser Enum-Typ wird verwendet, um das Farbmodell des Pixelformats zu beschreiben. Alpha wurde in 5.5 hinzugefügt.

KonstanteWertBeschreibung
QPixelFormat::RGB0Das Farbmodell ist RGB.
QPixelFormat::BGR1Dies ist logischerweise die entgegengesetzte Endian-Version von RGB. Aus Gründen der Benutzerfreundlichkeit hat es jedoch ein eigenes Modell.
QPixelFormat::Indexed2Das Farbmodell verwendet eine Farbpalette.
QPixelFormat::Grayscale3Das Farbmodell ist Grayscale.
QPixelFormat::CMYK4Das Farbmodell ist CMYK.
QPixelFormat::HSL5Das Farbmodell ist HSL.
QPixelFormat::HSV6Das Farbmodell ist HSV.
QPixelFormat::YUV7Das Farbmodell ist YUV.
QPixelFormat::Alpha8Es gibt kein Farbmodell, es wird nur Alpha verwendet.

enum QPixelFormat::TypeInterpretation

Diese Aufzählung beschreibt, wie jedes Pixel interpretiert wird. Wird ein Pixel als vollständige 32-Bit-Ganzzahl ohne Vorzeichen gelesen und dann jeder Kanal ausmaskiert, oder wird jedes Byte als vorzeichenloser Char-Wert gelesen. Typischerweise interpretieren die Formate von QImage ein Pixel als Ganzzahl ohne Vorzeichen und maskieren dann die Farbkanäle aus. OpenGL hingegen interpretiert Pixel typischerweise "ein Byte nach dem anderen", d.h. Byte ohne Vorzeichen.

QImage haben auch das Format Format_RGBA8888 (und seine Derivate), in dem die Pixel als Bytes ohne Vorzeichen interpretiert werden. OpenGL hat Erweiterungen, die es möglich machen, Pixelpuffer in einem vorzeichenlosen Integer-Format hochzuladen.

An unsigned integer ARGB32 pixel.

Das obige Bild zeigt ein ARGB-Pixel im Speicher, das als vorzeichenlose Ganzzahl gelesen wurde. Wenn dieses Pixel jedoch Byte für Byte auf einem Little-Endian-System gelesen würde, wäre das erste Byte das Byte, das den B-Kanal enthält. Das nächste Byte wäre der G-Kanal, dann der R-Kanal und schließlich der A-Kanal. Dies zeigt, dass es bei Little-Endian-Systemen für Ganzzahlformate von Bedeutung ist, wie die einzelnen Pixel interpretiert werden. Dies ist bei Big-Endian-Systemen nicht der Fall.

KonstanteWert
QPixelFormat::UnsignedInteger0
QPixelFormat::UnsignedShort1
QPixelFormat::UnsignedByte2
QPixelFormat::FloatingPoint3

enum QPixelFormat::YUVLayout

YUV wird nicht durch die Beschreibung der Größe der Farbkanäle dargestellt. Dies liegt daran, dass YUV häufig Makropixel verwendet, wodurch das Konzept der separaten Farbkanäle ungültig wird. Stattdessen werden die verschiedenen YUV-Layouts mit dieser Aufzählung beschrieben.

KonstanteWert
QPixelFormat::YUV4440
QPixelFormat::YUV4221
QPixelFormat::YUV4112
QPixelFormat::YUV420P3
QPixelFormat::YUV420SP4
QPixelFormat::YV125
QPixelFormat::UYVY6
QPixelFormat::YUYV7
QPixelFormat::NV128
QPixelFormat::NV219
QPixelFormat::IMC110
QPixelFormat::IMC211
QPixelFormat::IMC312
QPixelFormat::IMC413
QPixelFormat::Y814
QPixelFormat::Y1615

Dokumentation der Mitgliedsfunktionen

[constexpr noexcept] QPixelFormat::QPixelFormat()

Erzeugt ein Null-Pixelformat. Dieses Format wird auf QImage::Format_Invalid abgebildet.

[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)

Erzeugt ein QPixelFormat, das seine Daten den Attributen zuordnet. colorModel wird in einen 4 Bit langen Puffer gelegt.

firstSize secondSize thirdSize fourthSize fifthSize alphaSize sind alle dazu gedacht, die Größe eines Kanals zu repräsentieren. Die Kanäle werden je nach colorModel für unterschiedliche Zwecke verwendet. Bei RGB steht firstSize für den Rotkanal. Bei CMYK steht er für den Wert des Cyan-Kanals.

alphaUsage gibt an, ob der Alphakanal verwendet wird oder nicht.

alphaPosition ist die Position des Alphakanals.

premultiplied gibt an, ob der Alphakanal bereits mit den Farbkanälen multipliziert wurde.

typeInterpretation steht dafür, wie das Pixel interpretiert wird.

byteOrder steht für die Endianness des Pixelformats. Die Voreinstellung ist CurrentSystemEndian.

subEnum wird für colorModels verwendet, die einige zusätzliche Informationen speichern müssen, indem sie ein zusätzliches Enum liefern. Wird von YUV verwendet, um den YUV-Typ zu speichern. Der Standardwert ist 0.

[constexpr noexcept] QPixelFormat::AlphaPosition QPixelFormat::alphaPosition() const

Accessor-Funktion für alphaPosition.

[constexpr noexcept] uchar QPixelFormat::alphaSize() const

Accessor-Funktion für die Größe des Alphakanals.

[constexpr noexcept] QPixelFormat::AlphaUsage QPixelFormat::alphaUsage() const

Accessor-Funktion für alphaUsage.

[constexpr noexcept] uchar QPixelFormat::bitsPerPixel() const

Accessor-Funktion für die pro Pixel verwendeten Bits. Diese Funktion gibt die Summe der Farbkanäle + die Größe des Alphakanals zurück.

[constexpr noexcept] uchar QPixelFormat::blackSize() const

Accessor-Funktion für den Schwarz/Key-Farbkanal.

[constexpr noexcept] uchar QPixelFormat::blueSize() const

Accessor-Funktion für die Größe des blauen Farbkanals.

[constexpr noexcept] uchar QPixelFormat::brightnessSize() const

Accessor-Funktion für die Größe des Helligkeitskanals.

[constexpr noexcept] QPixelFormat::ByteOrder QPixelFormat::byteOrder() const

Die Bytereihenfolge wird fast immer auf die Bytereihenfolge des aktuellen Systems eingestellt. Sie kann jedoch nützlich sein, um einige YUV-Formate zu beschreiben. Diese Funktion sollte niemals QPixelFormat::CurrentSystemEndian zurückgeben, da dieser Wert im Konstruktor in einen Endian-Wert übersetzt wird.

[constexpr noexcept] uchar QPixelFormat::channelCount() const

Accessor-Funktion zum Ermitteln des channelCount. Die Kanalanzahl wird von Farbkanälen mit einer Größe > 0 abgeleitet und wenn die Größe des Alphakanals > 0 ist.

[constexpr noexcept] QPixelFormat::ColorModel QPixelFormat::colorModel() const

Accessor-Funktion zum Abrufen des colorModel.

[constexpr noexcept] uchar QPixelFormat::cyanSize() const

Accessor-Funktion für den Cyan-Farbkanal.

[constexpr noexcept] uchar QPixelFormat::greenSize() const

Accessor-Funktion für die Größe des grünen Farbkanals.

[constexpr noexcept] uchar QPixelFormat::hueSize() const

Accessor-Funktion für die Größe des Farbtonkanals.

[constexpr noexcept] uchar QPixelFormat::lightnessSize() const

Accessor-Funktion für die Größe des Helligkeitskanals.

[constexpr noexcept] uchar QPixelFormat::magentaSize() const

Accessor-Funktion für den Megenta-Farbkanal.

[constexpr noexcept] QPixelFormat::AlphaPremultiplied QPixelFormat::premultiplied() const

Accessor-Funktion für das AlphaPremultiplied enum. Diese gibt an, ob der Alphakanal mit den Farbkanälen multipliziert wird.

[constexpr noexcept] uchar QPixelFormat::redSize() const

Accessor-Funktion für die Größe des roten Farbkanals.

[constexpr noexcept] uchar QPixelFormat::saturationSize() const

Accessor-Funktion für die Größe des Sättigungskanals.

[constexpr noexcept] QPixelFormat::TypeInterpretation QPixelFormat::typeInterpretation() const

Accessor-Funktion für die Typ-Darstellung eines Farbkanals oder eines Pixels.

Siehe auch TypeInterpretation.

[constexpr noexcept] uchar QPixelFormat::yellowSize() const

Accessor-Funktion für den gelben Farbkanal.

[constexpr noexcept] QPixelFormat::YUVLayout QPixelFormat::yuvLayout() const

Accessor-Funktion für die YUVLayout. Es ist schwierig, die Farbkanäle eines YUV-Pixelformats zu beschreiben, da das YUV-Farbmodell Makropixel verwendet. Stattdessen wird das Layout der Pixel als Enum gespeichert.

Verwandte Nicht-Mitglieder

[constexpr noexcept] QPixelFormat qPixelFormatAlpha(uchar channelSize, QPixelFormat::TypeInterpretation typeInterpretation = QPixelFormat::UnsignedInteger)

Konstruktorfunktion zur Erstellung eines Alpha-Formats. Ein Maskenformat kann durch die Übergabe von 1 an channelSize beschrieben werden. Es ist auch möglich, sehr genaue Alpha-Formate zu definieren, die Doppelwerte zur Beschreibung jedes Pixels verwenden, indem 8 als channelSize und FloatingPoint als typeInterpretation übergeben werden.

Siehe auch 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)

Konstruktorfunktion zur Erstellung von CMYK-Formaten. Die Anzahl der Kanäle wird 4 oder 5 sein, je nachdem, ob alphaSize größer als Null ist oder nicht. Die CMYK-Farbkanäle werden alle auf den Wert von channelSize gesetzt.

alphaUsage alphaPosition und typeInterpretation sind alle über die gleichnamigen Accessoren zugänglich.

Siehe auch QPixelFormat::TypeInterpretation.

[constexpr noexcept] QPixelFormat qPixelFormatGrayscale(uchar channelSize, QPixelFormat::TypeInterpretation typeInterpretation = QPixelFormat::UnsignedInteger)

Konstruktorfunktion zur Erstellung eines Graustufenformats. Monochrome Formate können durch die Übergabe von 1 an channelSize beschrieben werden. Es ist auch möglich, sehr genaue Graustufenformate zu definieren, die Doubles zur Beschreibung jedes Pixels verwenden, indem 8 als channelSize und FloatingPoint als typeInterpretation übergeben werden.

Siehe auch 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)

Konstruktorfunktion zur Erstellung von HSL-Formaten. Die Anzahl der Kanäle wird 3 oder 4 sein, je nachdem, ob alphaSize größer als 0 ist.

channelSize setzt die hueSize saturationSize und lightnessSize auf den gleichen Wert.

alphaUsage alphaPosition und typeInterpretation sind alle über die gleichnamigen Accessoren zugänglich.

[constexpr noexcept] QPixelFormat qPixelFormatHsv(uchar channelSize, uchar alphaSize = 0, QPixelFormat::AlphaUsage alphaUsage = QPixelFormat::IgnoresAlpha, QPixelFormat::AlphaPosition alphaPosition = QPixelFormat::AtBeginning, QPixelFormat::TypeInterpretation typeInterpretation = QPixelFormat::FloatingPoint)

Konstruktorfunktion zur Erstellung von HSV-Formaten. Die Anzahl der Kanäle wird 3 oder 4 sein, je nachdem, ob alphaSize größer als 0 ist.

channelSize setzt die hueSize saturationSize und brightnessSize auf denselben Wert.

alphaUsage alphaPosition und typeInterpretation sind alle über die gleichnamigen Accessoren zugänglich.

[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)

Konstruktorfunktion zur Erstellung eines RGB-Pixelformats. redSize greenSize blueSize stellt die Größe der einzelnen Farbkanäle dar. alphaSize beschreibt die Größe des Alphakanals und seine Position wird mit alphaPosition beschrieben. alphaUsage wird verwendet, um zu bestimmen, ob der Alphakanal verwendet wird oder nicht. Wenn man die Größe des Alphakanals auf 8 und alphaUsage auf IgnoresAlpha setzt, ist es möglich, ein 32-Bit-Format zu erzeugen, bei dem die RGB-Kanäle zusammen nur 24 Bit verwenden. premultiplied typeInterpretation sind über gleichnamige Accessors zugänglich.

Siehe auch 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::LittleEndian)

Konstruktorfunktion zur Erstellung eines QPixelFormat, das ein YUV-Format mit yuvLayout beschreibt. alphaSize beschreibt die Größe eines möglichen Alphakanals und seine Position wird mit alphaPosition beschrieben. Die "ersten" "zweiten" ... "fünften" Kanäle sind alle auf 0 gesetzt. alphaUsage premultiplied typeInterpretation und byteOrder funktionieren wie bei anderen Formaten.

© 2025 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.