- class QColorSpace¶
The
QColorSpace
class provides a color space abstraction. More…Synopsis¶
Methods¶
def
__init__()
def
colorModel()
def
description()
def
gamma()
def
iccProfile()
def
isValid()
def
isValidTarget()
def
__ne__()
def
__eq__()
def
primaries()
def
setDescription()
def
setPrimaries()
def
setWhitePoint()
def
swap()
def
transformModel()
def
whitePoint()
Static functions¶
def
fromIccProfile()
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
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 for
Rgb
color spaces 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. For grayscale color spaces, only a single white primary is needed. 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.
- class NamedColorSpace¶
Predefined color spaces.
Constant
Description
QColorSpace.SRgb
The 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.SRgbLinear
The sRGB color space with linear gamma. Useful for gamma-corrected blending.
QColorSpace.AdobeRgb
The Adobe RGB color space is a classic wide-gamut color space, using a gamma of 2.2. ICC registration of Adobe RGB (1998)
QColorSpace.DisplayP3
A 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.ProPhotoRgb
The Pro Photo RGB color space, also known as ROMM RGB is a very wide gamut color space. ICC registration of ROMM RGB
QColorSpace.Bt2020
BT.2020, also known as Rec.2020 is a basic colorspace of HDR TVs. ICC registration of BT.2020
QColorSpace.Bt2100Pq
BT.2100(PQ), also known as Rec.2100 or HDR10 is an HDR encoding with the same primaries as Bt2020 but using the Perceptual Quantizer transfer function. ICC registration of BT.2100
QColorSpace.Bt2100Hlg
BT.2100 (HLG) is an HDR encoding with the same primaries as Bt2020 but using the Hybrid Log-Gamma transfer function.
- class Primaries¶
Predefined sets of primary colors.
Constant
Description
QColorSpace.Primaries.Custom
The primaries are undefined or does not match any predefined sets.
QColorSpace.Primaries.SRgb
The sRGB primaries
QColorSpace.Primaries.AdobeRgb
The Adobe RGB primaries
QColorSpace.Primaries.DciP3D65
The DCI-P3 primaries with the D65 whitepoint
QColorSpace.Primaries.ProPhotoRgb
The ProPhoto RGB primaries with the D50 whitepoint
QColorSpace.Primaries.Bt2020
The BT.2020 primaries with a D65 whitepoint
- class TransferFunction¶
Predefined transfer functions or gamma curves.
Constant
Description
QColorSpace.TransferFunction.Custom
The custom or null transfer function
QColorSpace.TransferFunction.Linear
The linear transfer functions
QColorSpace.TransferFunction.Gamma
A transfer function that is a real gamma curve based on the value of
gamma()
QColorSpace.TransferFunction.SRgb
The sRGB transfer function, composed of linear and gamma parts
QColorSpace.TransferFunction.ProPhotoRgb
The ProPhoto RGB transfer function, composed of linear and gamma parts
QColorSpace.TransferFunction.Bt2020
The BT.2020 transfer function, composited of linear and gamma parts
QColorSpace.TransferFunction.St2084
The SMPTE ST 2084 transfer function, also known Perceptual Quantizer(PQ).
QColorSpace.TransferFunction.Hlg
The Hybrid log-gamma transfer function.
- class TransformModel¶
Defines the processing model used for color space transforms.
Constant
Description
QColorSpace.TransformModel.ThreeComponentMatrix
The transform consist of a matrix calculated from primaries and set of transfer functions for each color channel. This is very fast and used by all predefined color spaces. Any color space on this form is reversible and always both valid sources and targets.
QColorSpace.TransformModel.ElementListProcessing
The transforms are one or two lists of processing elements that can do many things, each list only process either to the connection color space or from it. This is very flexible, but rather slow, and can only be set by reading ICC profiles (See
fromIccProfile()
). Since the two lists are separate a color space on this form can be a valid source, but not necessarily also a valid target. When changing either primaries or transfer function on a color space on this type it will reset to an empty ThreeComponentMatrix form.Added in version 6.8.
- class ColorModel¶
Defines the color model used by the color space data.
Constant
Description
QColorSpace.ColorModel.Undefined
No color model
QColorSpace.ColorModel.Rgb
An RGB color model with red, green, and blue colors. Can apply to RGB and grayscale data.
QColorSpace.ColorModel.Gray
A gray scale color model. Can only apply to grayscale data.
QColorSpace.ColorModel.Cmyk
Can only represent color data defined with cyan, magenta, yellow, and black colors. In effect only QImage::Format_CMYK32. Note Cmyk color spaces will be
ElementListProcessing
.Added in version 6.8.
- __init__()¶
Creates a new colorspace object that represents an undefined and invalid colorspace.
- __init__(namedColorSpace)
- Parameters:
namedColorSpace –
NamedColorSpace
Creates a new colorspace object that represents a
namedColorSpace
.- __init__(colorSpace)
- Parameters:
colorSpace –
QColorSpace
Creates a new colorspace object that represents a
namedColorSpace
.- __init__(primaries, transferFunctionTable)
- Parameters:
primaries –
Primaries
transferFunctionTable – .list of uint16_t
Creates a custom color space with the primaries
gamut
, using a custom transfer function described bytransferFunctionTable
.The table should contain at least 2 values, and contain an monotonically increasing list of values from 0 to 65535.
- __init__(primaries, gamma)
- Parameters:
primaries –
Primaries
gamma – float
Creates a custom color space with the primaries
primaries
, using a gamma transfer function ofgamma
.- __init__(whitePoint, transferFunctionTable)
- Parameters:
whitePoint –
QPointF
transferFunctionTable – .list of uint16_t
Creates a custom grayscale color space with white point
whitePoint
, and using the custom transfer function described bytransferFunctionTable
.- __init__(primaries, transferFunction[, gamma=0.0f])
- Parameters:
primaries –
Primaries
transferFunction –
TransferFunction
gamma – float
Creates a custom color space with the primaries
primaries
, using the transfer functiontransferFunction
and optionallygamma
.- __init__(whitePoint, transferFunction[, gamma=0.0f])
- Parameters:
whitePoint –
QPointF
transferFunction –
TransferFunction
gamma – float
Creates a custom grayscale color space with the white point
whitePoint
, using the transfer functiontransferFunction
and optionallygamma
.- __init__(whitePoint, redPoint, greenPoint, bluePoint, transferFunctionTable)
Creates a custom color space with primaries based on the chromaticities of the primary colors
whitePoint
,redPoint
,greenPoint
andbluePoint
, and using the custom transfer function described bytransferFunctionTable
.- __init__(whitePoint, redPoint, greenPoint, bluePoint, transferFunction[, gamma=0.0f])
- Parameters:
whitePoint –
QPointF
redPoint –
QPointF
greenPoint –
QPointF
bluePoint –
QPointF
transferFunction –
TransferFunction
gamma – float
Creates a custom colorspace with a primaries based on the chromaticities of the primary colors
whitePoint
,redPoint
,greenPoint
andbluePoint
, and using the transfer functiontransferFunction
and optionallygamma
.- __init__(whitePoint, redPoint, greenPoint, bluePoint, redTransferFunctionTable, greenTransferFunctionTable, blueTransferFunctionTable)
Creates a custom color space with primaries based on the chromaticities of the primary colors
whitePoint
,redPoint
,greenPoint
andbluePoint
, and using the custom transfer functions described byredTransferFunctionTable
,greenTransferFunctionTable
, andblueTransferFunctionTable
.- colorModel()¶
- Return type:
Returns the color model this color space can represent
- description()¶
- Return type:
str
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.See also
- static fromIccProfile(iccProfile)¶
- Parameters:
iccProfile –
QByteArray
- Return type:
Creates a
QColorSpace
from ICC profileiccProfile
.Note
Not all ICC profiles are supported.
QColorSpace
only supports RGB or Gray ICC profiles.If the ICC profile is not supported an invalid
QColorSpace
is returned where you can still read the original ICC profile usingiccProfile()
.See also
- gamma()¶
- Return type:
float
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
- iccProfile()¶
- Return type:
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
- isValid()¶
- Return type:
bool
Returns
true
if the color space is valid. For a color space withTransformModel::ThreeComponentMatrix
that means both primaries and transfer functions set, and impliesisValidTarget()
. For a color space withTransformModel::ElementListProcessing
it means it has a valid source transform, to check if it also a valid target color space useisValidTarget()
.See also
- isValidTarget()¶
- Return type:
bool
Returns
true
if the color space is a valid target color space.- __ne__(colorSpace2)¶
- Parameters:
colorSpace2 –
QColorSpace
- Return type:
bool
Returns
true
if colorspacecolorSpace1
is not equal to colorspacecolorSpace2
; otherwise returnsfalse
- __eq__(colorSpace2)¶
- Parameters:
colorSpace2 –
QColorSpace
- Return type:
bool
Returns
true
if colorspacecolorSpace1
is equal to colorspacecolorSpace2
; otherwise returnsfalse
Returns the predefined primaries of the color space or
primaries::Custom
if it doesn’t match any of them.See also
- setDescription(description)¶
- Parameters:
description – str
Sets the name or short description of the color space to
description
.If set to empty
description()
will return original or guessed descriptions instead.See also
Sets the primaries to those of the
primariesId
set.See also
- setPrimaries(whitePoint, redPoint, greenPoint, bluePoint)
Set primaries to the chromaticities of
whitePoint
,redPoint
,greenPoint
andbluePoint
.See also
- setTransferFunction(transferFunctionTable)¶
- Parameters:
transferFunctionTable – .list of uint16_t
Sets the transfer function to
transferFunctionTable
.See also
- setTransferFunction(transferFunction[, gamma=0.0f])
- Parameters:
transferFunction –
TransferFunction
gamma – float
Sets the transfer function to
transferFunction
andgamma
.- setTransferFunctions(redTransferFunctionTable, greenTransferFunctionTable, blueTransferFunctionTable)¶
- Parameters:
redTransferFunctionTable – .list of uint16_t
greenTransferFunctionTable – .list of uint16_t
blueTransferFunctionTable – .list of uint16_t
Sets the transfer functions to
redTransferFunctionTable
,greenTransferFunctionTable
andblueTransferFunctionTable
.See also
Sets the white point to used for this color space to
whitePoint
.See also
- swap(colorSpace)¶
- Parameters:
colorSpace –
QColorSpace
Swaps color space
other
with this color space. This operation is very fast and never fails.- transferFunction()¶
- Return type:
Returns the predefined transfer function of the color space or
TransferFunction::Custom
if it doesn’t match any of them.- transformModel()¶
- Return type:
Returns the transfrom processing model used for this color space.
- transformationToColorSpace(colorspace)¶
- Parameters:
colorspace –
QColorSpace
- Return type:
Generates and returns a color space transformation from this color space to
colorspace
.Returns the white point used for this color space. Returns a null QPointF if not defined.
See also
- withTransferFunction(transferFunctionTable)¶
- Parameters:
transferFunctionTable – .list of uint16_t
- Return type:
Returns a copy of this color space, except using the transfer function described by
transferFunctionTable
.See also
- withTransferFunction(transferFunction[, gamma=0.0f])
- Parameters:
transferFunction –
TransferFunction
gamma – float
- Return type:
Returns a copy of this color space, except using the transfer function
transferFunction
andgamma
.- withTransferFunctions(redTransferFunctionTable, greenTransferFunctionTable, blueTransferFunctionTable)¶
- Parameters:
redTransferFunctionTable – .list of uint16_t
greenTransferFunctionTable – .list of uint16_t
blueTransferFunctionTable – .list of uint16_t
- Return type:
Returns a copy of this color space, except using the transfer functions described by
redTransferFunctionTable
,greenTransferFunctionTable
andblueTransferFunctionTable
.See also