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>
This commit is contained in:
parent
c76dd72dc6
commit
967e55a628
@ -549,8 +549,12 @@ float QColorSpace::gamma() const noexcept
|
|||||||
*/
|
*/
|
||||||
void QColorSpace::setTransferFunction(QColorSpace::TransferFunction transferFunction, float gamma)
|
void QColorSpace::setTransferFunction(QColorSpace::TransferFunction transferFunction, float gamma)
|
||||||
{
|
{
|
||||||
if (!isValid() || transferFunction == QColorSpace::TransferFunction::Custom)
|
if (transferFunction == TransferFunction::Custom)
|
||||||
return;
|
return;
|
||||||
|
if (!d_ptr) {
|
||||||
|
d_ptr = new QColorSpacePrivate(Primaries::Custom, transferFunction, gamma);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (d_ptr->transferFunction == transferFunction && d_ptr->gamma == gamma)
|
if (d_ptr->transferFunction == transferFunction && d_ptr->gamma == gamma)
|
||||||
return;
|
return;
|
||||||
QColorSpacePrivate::getWritable(*this); // detach
|
QColorSpacePrivate::getWritable(*this); // detach
|
||||||
@ -585,8 +589,12 @@ QColorSpace QColorSpace::withTransferFunction(QColorSpace::TransferFunction tran
|
|||||||
*/
|
*/
|
||||||
void QColorSpace::setPrimaries(QColorSpace::Primaries primariesId)
|
void QColorSpace::setPrimaries(QColorSpace::Primaries primariesId)
|
||||||
{
|
{
|
||||||
if (!isValid() || primariesId == QColorSpace::Primaries::Custom)
|
if (primariesId == Primaries::Custom)
|
||||||
return;
|
return;
|
||||||
|
if (!d_ptr) {
|
||||||
|
d_ptr = new QColorSpacePrivate(primariesId, TransferFunction::Custom, 0.0f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (d_ptr->primaries == primariesId)
|
if (d_ptr->primaries == primariesId)
|
||||||
return;
|
return;
|
||||||
QColorSpacePrivate::getWritable(*this); // detach
|
QColorSpacePrivate::getWritable(*this); // detach
|
||||||
@ -605,11 +613,13 @@ void QColorSpace::setPrimaries(QColorSpace::Primaries primariesId)
|
|||||||
void QColorSpace::setPrimaries(const QPointF &whitePoint, const QPointF &redPoint,
|
void QColorSpace::setPrimaries(const QPointF &whitePoint, const QPointF &redPoint,
|
||||||
const QPointF &greenPoint, const QPointF &bluePoint)
|
const QPointF &greenPoint, const QPointF &bluePoint)
|
||||||
{
|
{
|
||||||
if (!isValid())
|
|
||||||
return;
|
|
||||||
QColorSpacePrimaries primaries(whitePoint, redPoint, greenPoint, bluePoint);
|
QColorSpacePrimaries primaries(whitePoint, redPoint, greenPoint, bluePoint);
|
||||||
if (!primaries.areValid())
|
if (!primaries.areValid())
|
||||||
return;
|
return;
|
||||||
|
if (!d_ptr) {
|
||||||
|
d_ptr = new QColorSpacePrivate(primaries, TransferFunction::Custom, 0.0f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
QColorMatrix toXyz = primaries.toXyzMatrix();
|
QColorMatrix toXyz = primaries.toXyzMatrix();
|
||||||
if (QColorVector(primaries.whitePoint) == d_ptr->whitePoint && toXyz == d_ptr->toXyz)
|
if (QColorVector(primaries.whitePoint) == d_ptr->whitePoint && toXyz == d_ptr->toXyz)
|
||||||
return;
|
return;
|
||||||
@ -692,12 +702,14 @@ bool operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2)
|
|||||||
|
|
||||||
const bool valid1 = colorSpace1.isValid();
|
const bool valid1 = colorSpace1.isValid();
|
||||||
const bool valid2 = colorSpace2.isValid();
|
const bool valid2 = colorSpace2.isValid();
|
||||||
if (!valid1 && !valid2)
|
if (valid1 != valid2)
|
||||||
return colorSpace1.d_ptr->iccProfile == colorSpace2.d_ptr->iccProfile;
|
|
||||||
else if (!valid1 || !valid2)
|
|
||||||
return false;
|
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() != QColorSpace::Primaries::Custom && colorSpace2.primaries() != QColorSpace::Primaries::Custom) {
|
||||||
if (colorSpace1.primaries() != colorSpace2.primaries())
|
if (colorSpace1.primaries() != colorSpace2.primaries())
|
||||||
|
@ -413,6 +413,7 @@ void tst_QColorSpace::primaries2()
|
|||||||
|
|
||||||
void tst_QColorSpace::invalidPrimaries()
|
void tst_QColorSpace::invalidPrimaries()
|
||||||
{
|
{
|
||||||
|
QTest::ignoreMessage(QtWarningMsg, QRegularExpression("QColorSpace attempted constructed from invalid primaries"));
|
||||||
QColorSpace custom(QPointF(), QPointF(), QPointF(), QPointF(), QColorSpace::TransferFunction::Linear);
|
QColorSpace custom(QPointF(), QPointF(), QPointF(), QPointF(), QColorSpace::TransferFunction::Linear);
|
||||||
QVERIFY(!custom.isValid());
|
QVERIFY(!custom.isValid());
|
||||||
}
|
}
|
||||||
@ -444,8 +445,15 @@ void tst_QColorSpace::changeTransferFunction()
|
|||||||
|
|
||||||
QColorSpace undefined;
|
QColorSpace undefined;
|
||||||
QCOMPARE(undefined.withTransferFunction(QColorSpace::TransferFunction::Linear), undefined);
|
QCOMPARE(undefined.withTransferFunction(QColorSpace::TransferFunction::Linear), undefined);
|
||||||
undefined.setTransferFunction(QColorSpace::TransferFunction::SRgb);
|
|
||||||
QCOMPARE(undefined, QColorSpace());
|
QColorSpace partial;
|
||||||
|
partial.setTransferFunction(QColorSpace::TransferFunction::SRgb);
|
||||||
|
QCOMPARE(partial.transferFunction(), QColorSpace::TransferFunction::SRgb);
|
||||||
|
QVERIFY(!partial.isValid());
|
||||||
|
|
||||||
|
partial.setPrimaries(QColorSpace::Primaries::SRgb);
|
||||||
|
QVERIFY(partial.isValid());
|
||||||
|
QCOMPARE(partial, QColorSpace(QColorSpace::SRgb));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QColorSpace::changePrimaries()
|
void tst_QColorSpace::changePrimaries()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user