diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-02-26 14:55:33 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-08-02 21:07:54 +0200 |
commit | 05251bca1dc5aabdd1e4548a1bf1bf757f615791 (patch) | |
tree | 377406bb433923001f2aa937eaf8fc89ecf23be7 /tests | |
parent | 092074f9df073c9af075810602d61ac54a115d89 (diff) |
Add an easier way to change colorspaces
Adds setters for transfer-functions and primaries.
This allows us to remove use of private QColorSpace API from the PNG
handler.
Change-Id: Ieeff81c813c253649500acd1e53f35247b872325
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp index c0f3559f57..bc1a45013c 100644 --- a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp +++ b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp @@ -66,6 +66,9 @@ private slots: void primaries2_data(); void primaries2(); void invalidPrimaries(); + + void changeTransferFunction(); + void changePrimaries(); }; tst_QColorSpace::tst_QColorSpace() @@ -375,5 +378,49 @@ void tst_QColorSpace::invalidPrimaries() QCOMPARE(custom.colorSpaceId(), QColorSpace::Undefined); } +void tst_QColorSpace::changeTransferFunction() +{ + QColorSpace sRgb = QColorSpace::SRgb; + + QColorSpace sRgbLinear = sRgb.withTransferFunction(QColorSpace::TransferFunction::Linear); + QCOMPARE(sRgbLinear.transferFunction(), QColorSpace::TransferFunction::Linear); + QCOMPARE(sRgbLinear.gamma(), 1.0f); + QCOMPARE(sRgbLinear.primaries(), QColorSpace::Primaries::SRgb); + QCOMPARE(sRgbLinear.colorSpaceId(), QColorSpace::SRgbLinear); + QCOMPARE(sRgbLinear, QColorSpace(QColorSpace::SRgbLinear)); + QVERIFY(sRgbLinear != sRgb); + QCOMPARE(sRgbLinear.withTransferFunction(QColorSpace::TransferFunction::SRgb), sRgb); + + QColorSpace aRgb = QColorSpace::AdobeRgb; + aRgb.setTransferFunction(QColorSpace::TransferFunction::SRgb); + QCOMPARE(aRgb.transferFunction(), QColorSpace::TransferFunction::SRgb); + QCOMPARE(aRgb.primaries(), QColorSpace::Primaries::AdobeRgb); + QCOMPARE(aRgb.colorSpaceId(), QColorSpace::Unknown); + QVERIFY(aRgb != QColorSpace(QColorSpace::AdobeRgb)); + QVERIFY(aRgb != sRgb); + QCOMPARE(aRgb.withTransferFunction(QColorSpace::TransferFunction::Gamma, 2.2f), + QColorSpace(QColorSpace::AdobeRgb)); + QVERIFY(aRgb != QColorSpace(QColorSpace::AdobeRgb)); + aRgb.setTransferFunction(QColorSpace::TransferFunction::Gamma, 2.2f); + QVERIFY(aRgb == QColorSpace(QColorSpace::AdobeRgb)); + + QColorSpace undefined; + QCOMPARE(undefined.withTransferFunction(QColorSpace::TransferFunction::Linear), undefined); + undefined.setTransferFunction(QColorSpace::TransferFunction::SRgb); + QCOMPARE(undefined, QColorSpace()); +} + +void tst_QColorSpace::changePrimaries() +{ + QColorSpace cs = QColorSpace::SRgb; + cs.setPrimaries(QColorSpace::Primaries::DciP3D65); + QVERIFY(cs.isValid()); + QCOMPARE(cs, QColorSpace(QColorSpace::DisplayP3)); + cs.setTransferFunction(QColorSpace::TransferFunction::Linear); + cs.setPrimaries(QPointF(0.3127, 0.3290), QPointF(0.640, 0.330), + QPointF(0.3000, 0.6000), QPointF(0.150, 0.060)); + QCOMPARE(cs, QColorSpace(QColorSpace::SRgbLinear)); +} + QTEST_MAIN(tst_QColorSpace) #include "tst_qcolorspace.moc" |