QColorSpace Class

The QColorSpace class provides a color space abstraction. More...

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

Public Types

enum NamedColorSpace { SRgb, SRgbLinear, AdobeRgb, DisplayP3, ProPhotoRgb }
enum class Primaries { Custom, SRgb, AdobeRgb, DciP3D65, ProPhotoRgb }
enum class TransferFunction { Custom, Linear, Gamma, SRgb, ProPhotoRgb }

Public Functions

QColorSpace()
QColorSpace(QColorSpace::NamedColorSpace namedColorSpace)
QColorSpace(QColorSpace::Primaries primaries, QColorSpace::TransferFunction transferFunction, float gamma = 0.0f)
QColorSpace(QColorSpace::Primaries primaries, float gamma)
QColorSpace(QColorSpace::Primaries gamut, const QList<uint16_t> &transferFunctionTable)
QColorSpace(const QPointF &whitePoint, const QPointF &redPoint, const QPointF &greenPoint, const QPointF &bluePoint, QColorSpace::TransferFunction transferFunction, float gamma = 0.0f)
QColorSpace(const QPointF &whitePoint, const QPointF &redPoint, const QPointF &greenPoint, const QPointF &bluePoint, const QList<uint16_t> &transferFunctionTable)
QColorSpace(const QPointF &whitePoint, const QPointF &redPoint, const QPointF &greenPoint, const QPointF &bluePoint, const QList<uint16_t> &redTransferFunctionTable, const QList<uint16_t> &greenTransferFunctionTable, const QList<uint16_t> &blueTransferFunctionTable)
QString description() const
float gamma() const
QByteArray iccProfile() const
bool isValid() const
QColorSpace::Primaries primaries() const
void setDescription(const QString &description)
void setPrimaries(QColorSpace::Primaries primariesId)
void setPrimaries(const QPointF &whitePoint, const QPointF &redPoint, const QPointF &greenPoint, const QPointF &bluePoint)
void setTransferFunction(QColorSpace::TransferFunction transferFunction, float gamma = 0.0f)
void setTransferFunction(const QList<uint16_t> &transferFunctionTable)
void setTransferFunctions(const QList<uint16_t> &redTransferFunctionTable, const QList<uint16_t> &greenTransferFunctionTable, const QList<uint16_t> &blueTransferFunctionTable)
void swap(QColorSpace &other)
QColorSpace::TransferFunction transferFunction() const
QColorTransform transformationToColorSpace(const QColorSpace &colorspace) const
QColorSpace withTransferFunction(QColorSpace::TransferFunction transferFunction, float gamma = 0.0f) const
QColorSpace withTransferFunction(const QList<uint16_t> &transferFunctionTable) const
QColorSpace withTransferFunctions(const QList<uint16_t> &redTransferFunctionTable, const QList<uint16_t> &greenTransferFunctionTable, const QList<uint16_t> &blueTransferFunctionTable) const
QVariant operator QVariant() const

Static Public Members

QColorSpace fromIccProfile(const QByteArray &iccProfile)
bool operator!=(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2)
QDataStream &operator<<(QDataStream &stream, const QColorSpace &colorSpace)
bool operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2)
QDataStream &operator>>(QDataStream &stream, QColorSpace &colorSpace)

Detailed Description

Color values can be interpreted in different ways, and based on the interpretation can live in different spaces. We call this color spaces.

QColorSpace provides access to creating several predefined color spaces and can generate QColorTransforms for converting colors from one color space to another.

QColorSpace can also represent color spaces defined by ICC profiles or embedded in images, that do not otherwise fit the predefined color spaces.

A color space can generally speaking be conceived as a combination of set of primary colors and a transfer function. The primaries defines the axes of the color space, and the transfer function how values are mapped on the axes. The primaries are defined by three primary colors that represent exactly how red, green, and blue look in this particular color space, and a white color that represents where and how bright pure white is. The range of colors expressible by the primary colors is called the gamut, and a color space that can represent a wider range of colors is also known as a wide-gamut color space.

The transfer function or gamma curve determines how each component in the color space is encoded. These are used because human perception does not operate linearly, and the transfer functions try to ensure that colors will seem evenly spaced to human eyes.

Member Type Documentation

enum QColorSpace::NamedColorSpace

Predefined color spaces.

ConstantValueDescription
QColorSpace::SRgb1The sRGB color space, which Qt operates in by default. It is a close approximation of how most classic monitors operate, and a mode most software and hardware support. ICC registration of sRGB.
QColorSpace::SRgbLinear2The sRGB color space with linear gamma. Useful for gamma-corrected blending.
QColorSpace::AdobeRgb3The Adobe RGB color space is a classic wide-gamut color space, using a gamma of 2.2. ICC registration of Adobe RGB (1998)
QColorSpace::DisplayP34A color-space using the primaries of DCI-P3, but with the whitepoint and transfer function of sRGB. Common in modern wide-gamut screens. ICC registration of DCI-P3
QColorSpace::ProPhotoRgb5The Pro Photo RGB color space, also known as ROMM RGB is a very wide gamut color space. ICC registration of ROMM RGB

enum class QColorSpace::Primaries

Predefined sets of primary colors.

ConstantValueDescription
QColorSpace::Primaries::Custom0The primaries are undefined or does not match any predefined sets.
QColorSpace::Primaries::SRgb1The sRGB primaries
QColorSpace::Primaries::AdobeRgb2The Adobe RGB primaries
QColorSpace::Primaries::DciP3D653The DCI-P3 primaries with the D65 whitepoint
QColorSpace::Primaries::ProPhotoRgb4The ProPhoto RGB primaries with the D50 whitepoint

enum class QColorSpace::TransferFunction

Predefined transfer functions or gamma curves.

ConstantValueDescription
QColorSpace::TransferFunction::Custom0The custom or null transfer function
QColorSpace::TransferFunction::Linear1The linear transfer functions
QColorSpace::TransferFunction::Gamma2A transfer function that is a real gamma curve based on the value of gamma()
QColorSpace::TransferFunction::SRgb3The sRGB transfer function, composed of linear and gamma parts
QColorSpace::TransferFunction::ProPhotoRgb4The ProPhoto RGB transfer function, composed of linear and gamma parts

Member Function Documentation

QColorSpace::QColorSpace()

Creates a new colorspace object that represents an undefined and invalid colorspace.

QColorSpace::QColorSpace(QColorSpace::NamedColorSpace namedColorSpace)

Creates a new colorspace object that represents a namedColorSpace.

QColorSpace::QColorSpace(QColorSpace::Primaries primaries, QColorSpace::TransferFunction transferFunction, float gamma = 0.0f)

Creates a custom color space with the primaries primaries, using the transfer function transferFunction and optionally gamma.

QColorSpace::QColorSpace(QColorSpace::Primaries primaries, float gamma)

Creates a custom color space with the primaries primaries, using a gamma transfer function of gamma.

[since 6.1] QColorSpace::QColorSpace(QColorSpace::Primaries gamut, const QList<uint16_t> &transferFunctionTable)

Creates a custom color space with the primaries gamut, using a custom transfer function described by transferFunctionTable.

The table should contain at least 2 values, and contain an monotonically increasing list of values from 0 to 65535.

This function was introduced in Qt 6.1.

QColorSpace::QColorSpace(const QPointF &whitePoint, const QPointF &redPoint, const QPointF &greenPoint, const QPointF &bluePoint, QColorSpace::TransferFunction transferFunction, float gamma = 0.0f)

Creates a custom colorspace with a primaries based on the chromaticities of the primary colors whitePoint, redPoint, greenPoint and bluePoint, and using the transfer function transferFunction and optionally gamma.

[since 6.1] QColorSpace::QColorSpace(const QPointF &whitePoint, const QPointF &redPoint, const QPointF &greenPoint, const QPointF &bluePoint, const QList<uint16_t> &transferFunctionTable)

Creates a custom color space with primaries based on the chromaticities of the primary colors whitePoint, redPoint, greenPoint and bluePoint, and using the custom transfer function described by transferFunctionTable.

This function was introduced in Qt 6.1.

[since 6.1] QColorSpace::QColorSpace(const QPointF &whitePoint, const QPointF &redPoint, const QPointF &greenPoint, const QPointF &bluePoint, const QList<uint16_t> &redTransferFunctionTable, const QList<uint16_t> &greenTransferFunctionTable, const QList<uint16_t> &blueTransferFunctionTable)

Creates a custom color space with primaries based on the chromaticities of the primary colors whitePoint, redPoint, greenPoint and bluePoint, and using the custom transfer functions described by redTransferFunctionTable, greenTransferFunctionTable, and blueTransferFunctionTable.

This function was introduced in Qt 6.1.

[since 6.2] QString QColorSpace::description() const

Returns the name or short description. If a description hasn't been given in setDescription(), the original name of the profile is returned if the profile is unmodified, a guessed name is returned if the profile has been recognized as a known color space, otherwise an empty string is returned.

This function was introduced in Qt 6.2.

See also setDescription().

[static] QColorSpace QColorSpace::fromIccProfile(const QByteArray &iccProfile)

Creates a QColorSpace from ICC profile iccProfile.

Note: Not all ICC profiles are supported. QColorSpace only supports RGB-XYZ ICC profiles that are three-component matrix-based.

If the ICC profile is not supported an invalid QColorSpace is returned where you can still read the original ICC profile using iccProfile().

See also iccProfile().

float QColorSpace::gamma() const

Returns the gamma value of color spaces with TransferFunction::Gamma, an approximate gamma value for other predefined color spaces, or 0.0 if no approximate gamma is known.

See also transferFunction().

QByteArray QColorSpace::iccProfile() const

Returns an ICC profile representing the color space.

If the color space was generated from an ICC profile, that profile is returned, otherwise one is generated.

Note: Even invalid color spaces may return the ICC profile if they were generated from one, to allow applications to implement wider support themselves.

See also fromIccProfile().

bool QColorSpace::isValid() const

Returns true if the color space is valid.

QColorSpace::Primaries QColorSpace::primaries() const

Returns the predefined primaries of the color space or primaries::Custom if it doesn't match any of them.

See also setPrimaries().

[since 6.2] void QColorSpace::setDescription(const QString &description)

Sets the name or short description of the color space to description.

If set to empty description() will return original or guessed descriptions instead.

This function was introduced in Qt 6.2.

See also description().

void QColorSpace::setPrimaries(QColorSpace::Primaries primariesId)

Sets the primaries to those of the primariesId set.

See also primaries().

void QColorSpace::setPrimaries(const QPointF &whitePoint, const QPointF &redPoint, const QPointF &greenPoint, const QPointF &bluePoint)

Set primaries to the chromaticities of whitePoint, redPoint, greenPoint and bluePoint.

See also primaries().

void QColorSpace::setTransferFunction(QColorSpace::TransferFunction transferFunction, float gamma = 0.0f)

Sets the transfer function to transferFunction and gamma.

See also transferFunction(), gamma(), and withTransferFunction().

[since 6.1] void QColorSpace::setTransferFunction(const QList<uint16_t> &transferFunctionTable)

Sets the transfer function to transferFunctionTable.

This function was introduced in Qt 6.1.

See also withTransferFunction().

[since 6.1] void QColorSpace::setTransferFunctions(const QList<uint16_t> &redTransferFunctionTable, const QList<uint16_t> &greenTransferFunctionTable, const QList<uint16_t> &blueTransferFunctionTable)

Sets the transfer functions to redTransferFunctionTable, greenTransferFunctionTable and blueTransferFunctionTable.

This function was introduced in Qt 6.1.

See also withTransferFunctions().

void QColorSpace::swap(QColorSpace &other)

Swaps color space other with this color space. This operation is very fast and never fails.

QColorSpace::TransferFunction QColorSpace::transferFunction() const

Returns the predefined transfer function of the color space or TransferFunction::Custom if it doesn't match any of them.

See also gamma(), setTransferFunction(), and withTransferFunction().

QColorTransform QColorSpace::transformationToColorSpace(const QColorSpace &colorspace) const

Generates and returns a color space transformation from this color space to colorspace.

QColorSpace QColorSpace::withTransferFunction(QColorSpace::TransferFunction transferFunction, float gamma = 0.0f) const

Returns a copy of this color space, except using the transfer function transferFunction and gamma.

See also transferFunction(), gamma(), and setTransferFunction().

[since 6.1] QColorSpace QColorSpace::withTransferFunction(const QList<uint16_t> &transferFunctionTable) const

Returns a copy of this color space, except using the transfer function described by transferFunctionTable.

This function was introduced in Qt 6.1.

See also transferFunction() and setTransferFunction().

[since 6.1] QColorSpace QColorSpace::withTransferFunctions(const QList<uint16_t> &redTransferFunctionTable, const QList<uint16_t> &greenTransferFunctionTable, const QList<uint16_t> &blueTransferFunctionTable) const

Returns a copy of this color space, except using the transfer functions described by redTransferFunctionTable, greenTransferFunctionTable and blueTransferFunctionTable.

This function was introduced in Qt 6.1.

See also setTransferFunctions().

QVariant QColorSpace::operator QVariant() const

Returns the color space as a QVariant.

Related Non-Members

bool operator!=(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2)

Returns true if colorspace colorSpace1 is not equal to colorspace colorSpace2; otherwise returns false

QDataStream &operator<<(QDataStream &stream, const QColorSpace &colorSpace)

Writes the given colorSpace to the given stream as an ICC profile.

See also QColorSpace::iccProfile() and Serializing Qt Data Types.

bool operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2)

Returns true if colorspace colorSpace1 is equal to colorspace colorSpace2; otherwise returns false

QDataStream &operator>>(QDataStream &stream, QColorSpace &colorSpace)

Reads a color space from the given stream and stores it in the given colorSpace.

See also QColorSpace::fromIccProfile() and Serializing Qt Data Types.

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