diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-12-12 11:33:58 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-02-01 00:31:01 +0100 |
commit | 967e55a628fcddde38c67791665969e9a530d4d8 (patch) | |
tree | 377f5a5e8d906c8d4428b34b5ae8ecb9630712e0 /src/gui/painting | |
parent | c76dd72dc6b78c34edb4dfc5196bb93a51cc488f (diff) |
Allow creating a valid QColorSpace one value at a time
The change to using setters left a quirk from the previous un-mutable
design where you couldn't set values on an invalid color space and
create a valid one.
This changes that so it works as expected for an imperative API, but
is also needed for the declarative QML bindings.
Change-Id: I246cfc38b364b156238151c42c1df82a3f1cc9d3
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src/gui/painting')
-rw-r--r-- | src/gui/painting/qcolorspace.cpp | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/gui/painting/qcolorspace.cpp b/src/gui/painting/qcolorspace.cpp index 7ebd5f1bf4..7e7bbec870 100644 --- a/src/gui/painting/qcolorspace.cpp +++ b/src/gui/painting/qcolorspace.cpp @@ -549,8 +549,12 @@ float QColorSpace::gamma() const noexcept */ void QColorSpace::setTransferFunction(QColorSpace::TransferFunction transferFunction, float gamma) { - if (!isValid() || transferFunction == QColorSpace::TransferFunction::Custom) + if (transferFunction == TransferFunction::Custom) + return; + if (!d_ptr) { + d_ptr = new QColorSpacePrivate(Primaries::Custom, transferFunction, gamma); return; + } if (d_ptr->transferFunction == transferFunction && d_ptr->gamma == gamma) return; QColorSpacePrivate::getWritable(*this); // detach @@ -585,8 +589,12 @@ QColorSpace QColorSpace::withTransferFunction(QColorSpace::TransferFunction tran */ void QColorSpace::setPrimaries(QColorSpace::Primaries primariesId) { - if (!isValid() || primariesId == QColorSpace::Primaries::Custom) + if (primariesId == Primaries::Custom) return; + if (!d_ptr) { + d_ptr = new QColorSpacePrivate(primariesId, TransferFunction::Custom, 0.0f); + return; + } if (d_ptr->primaries == primariesId) return; QColorSpacePrivate::getWritable(*this); // detach @@ -605,11 +613,13 @@ void QColorSpace::setPrimaries(QColorSpace::Primaries primariesId) void QColorSpace::setPrimaries(const QPointF &whitePoint, const QPointF &redPoint, const QPointF &greenPoint, const QPointF &bluePoint) { - if (!isValid()) - return; QColorSpacePrimaries primaries(whitePoint, redPoint, greenPoint, bluePoint); if (!primaries.areValid()) return; + if (!d_ptr) { + d_ptr = new QColorSpacePrivate(primaries, TransferFunction::Custom, 0.0f); + return; + } QColorMatrix toXyz = primaries.toXyzMatrix(); if (QColorVector(primaries.whitePoint) == d_ptr->whitePoint && toXyz == d_ptr->toXyz) return; @@ -692,12 +702,14 @@ bool operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2) const bool valid1 = colorSpace1.isValid(); const bool valid2 = colorSpace2.isValid(); - if (!valid1 && !valid2) - return colorSpace1.d_ptr->iccProfile == colorSpace2.d_ptr->iccProfile; - else if (!valid1 || !valid2) + if (valid1 != valid2) return false; + if (!valid1 && !valid2) { + if (!colorSpace1.d_ptr->iccProfile.isEmpty() || !colorSpace2.d_ptr->iccProfile.isEmpty()) + return colorSpace1.d_ptr->iccProfile == colorSpace2.d_ptr->iccProfile; + } - // At this point one or both color spaces are unknown but valid, and must be compared in detail instead + // At this point one or both color spaces are unknown, and must be compared in detail instead if (colorSpace1.primaries() != QColorSpace::Primaries::Custom && colorSpace2.primaries() != QColorSpace::Primaries::Custom) { if (colorSpace1.primaries() != colorSpace2.primaries()) |