diff --git a/src/gui/painting/qcolorspace.cpp b/src/gui/painting/qcolorspace.cpp index 3f981c704e..e6f3db8f45 100644 --- a/src/gui/painting/qcolorspace.cpp +++ b/src/gui/painting/qcolorspace.cpp @@ -221,7 +221,7 @@ QColorSpacePrivate::QColorSpacePrivate(const QColorSpacePrimaries &primaries, setTransferFunction(); } -QColorSpacePrivate::QColorSpacePrivate(QColorSpace::Primaries primaries, const QVector &transferFunctionTable) +QColorSpacePrivate::QColorSpacePrivate(QColorSpace::Primaries primaries, const QList &transferFunctionTable) : primaries(primaries) , transferFunction(QColorSpace::TransferFunction::Custom) , gamma(0) @@ -231,7 +231,7 @@ QColorSpacePrivate::QColorSpacePrivate(QColorSpace::Primaries primaries, const Q initialize(); } -QColorSpacePrivate::QColorSpacePrivate(const QColorSpacePrimaries &primaries, const QVector &transferFunctionTable) +QColorSpacePrivate::QColorSpacePrivate(const QColorSpacePrimaries &primaries, const QList &transferFunctionTable) : primaries(QColorSpace::Primaries::Custom) , transferFunction(QColorSpace::TransferFunction::Custom) , gamma(0) @@ -244,6 +244,24 @@ QColorSpacePrivate::QColorSpacePrivate(const QColorSpacePrimaries &primaries, co initialize(); } +QColorSpacePrivate::QColorSpacePrivate(const QColorSpacePrimaries &primaries, + const QList &redTransferFunctionTable, + const QList &greenTransferFunctionTable, + const QList &blueTransferFunctionTable) + : primaries(QColorSpace::Primaries::Custom) + , transferFunction(QColorSpace::TransferFunction::Custom) + , gamma(0) +{ + Q_ASSERT(primaries.areValid()); + toXyz = primaries.toXyzMatrix(); + whitePoint = QColorVector(primaries.whitePoint); + setTransferFunctionTables(redTransferFunctionTable, + greenTransferFunctionTable, + blueTransferFunctionTable); + identifyColorSpace(); + setToXyzMatrix(); +} + void QColorSpacePrivate::identifyColorSpace() { switch (primaries) { @@ -321,7 +339,7 @@ void QColorSpacePrivate::setToXyzMatrix() whitePoint = QColorVector(colorSpacePrimaries.whitePoint); } -void QColorSpacePrivate::setTransferFunctionTable(const QVector &transferFunctionTable) +void QColorSpacePrivate::setTransferFunctionTable(const QList &transferFunctionTable) { QColorTransferTable table(transferFunctionTable.size(), transferFunctionTable); if (!table.isEmpty() && !table.checkValidity()) { @@ -347,6 +365,46 @@ void QColorSpacePrivate::setTransferFunctionTable(const QVector &trans } } +void QColorSpacePrivate::setTransferFunctionTables(const QList &redTransferFunctionTable, + const QList &greenTransferFunctionTable, + const QList &blueTransferFunctionTable) +{ + QColorTransferTable redTable(redTransferFunctionTable.size(), redTransferFunctionTable); + QColorTransferTable greenTable(greenTransferFunctionTable.size(), greenTransferFunctionTable); + QColorTransferTable blueTable(blueTransferFunctionTable.size(), blueTransferFunctionTable); + if (!redTable.isEmpty() && !greenTable.isEmpty() && !blueTable.isEmpty() && + !redTable.checkValidity() && !greenTable.checkValidity() && !blueTable.checkValidity()) { + qWarning() << "Invalid transfer function table given to QColorSpace"; + trc[0].m_type = QColorTrc::Type::Uninitialized; + trc[1].m_type = QColorTrc::Type::Uninitialized; + trc[2].m_type = QColorTrc::Type::Uninitialized; + return; + } + transferFunction = QColorSpace::TransferFunction::Custom; + QColorTransferFunction curve; + if (redTable.asColorTransferFunction(&curve)) { + trc[0].m_type = QColorTrc::Type::Function; + trc[0].m_fun = curve; + } else { + trc[0].m_type = QColorTrc::Type::Table; + trc[0].m_table = redTable; + } + if (greenTable.asColorTransferFunction(&curve)) { + trc[1].m_type = QColorTrc::Type::Function; + trc[1].m_fun = curve; + } else { + trc[1].m_type = QColorTrc::Type::Table; + trc[1].m_table = greenTable; + } + if (blueTable.asColorTransferFunction(&curve)) { + trc[2].m_type = QColorTrc::Type::Function; + trc[2].m_fun = curve; + } else { + trc[2].m_type = QColorTrc::Type::Table; + trc[2].m_table = blueTable; + } +} + void QColorSpacePrivate::setTransferFunction() { switch (transferFunction) { @@ -528,7 +586,7 @@ QColorSpace::QColorSpace(QColorSpace::Primaries primaries, float gamma) \since 6.1 */ -QColorSpace::QColorSpace(QColorSpace::Primaries gamut, const QVector &transferFunctionTable) +QColorSpace::QColorSpace(QColorSpace::Primaries gamut, const QList &transferFunctionTable) : d_ptr(new QColorSpacePrivate(gamut, transferFunctionTable)) { } @@ -558,11 +616,30 @@ QColorSpace::QColorSpace(const QPointF &whitePoint, const QPointF &redPoint, */ QColorSpace::QColorSpace(const QPointF &whitePoint, const QPointF &redPoint, const QPointF &greenPoint, const QPointF &bluePoint, - const QVector &transferFunctionTable) + const QList &transferFunctionTable) : d_ptr(new QColorSpacePrivate({whitePoint, redPoint, greenPoint, bluePoint}, transferFunctionTable)) { } +/*! + Creates a custom color space with primaries based on the chromaticities of the primary colors \a whitePoint, + \a redPoint, \a greenPoint and \a bluePoint, and using the custom transfer functions described by + \a redTransferFunctionTable, \a greenTransferFunctionTable, and \a blueTransferFunctionTable. + + \since 6.1 + */ +QColorSpace::QColorSpace(const QPointF &whitePoint, const QPointF &redPoint, + const QPointF &greenPoint, const QPointF &bluePoint, + const QList &redTransferFunctionTable, + const QList &greenTransferFunctionTable, + const QList &blueTransferFunctionTable) + : d_ptr(new QColorSpacePrivate({whitePoint, redPoint, greenPoint, bluePoint}, + redTransferFunctionTable, + greenTransferFunctionTable, + blueTransferFunctionTable)) +{ +} + QColorSpace::~QColorSpace() = default; QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QColorSpacePrivate) @@ -640,9 +717,9 @@ void QColorSpace::setTransferFunction(QColorSpace::TransferFunction transferFunc Sets the transfer function to \a transferFunctionTable. \since 6.1 - \sa transferFunction() + \sa withTransferFunction() */ -void QColorSpace::setTransferFunction(const QVector &transferFunctionTable) +void QColorSpace::setTransferFunction(const QList &transferFunctionTable) { if (!d_ptr) { d_ptr = new QColorSpacePrivate(Primaries::Custom, transferFunctionTable); @@ -657,6 +734,34 @@ void QColorSpace::setTransferFunction(const QVector &transferFunctionT d_ptr->setTransferFunction(); } +/*! + Sets the transfer functions to \a redTransferFunctionTable, + \a greenTransferFunctionTable and \a blueTransferFunctionTable. + + \since 6.1 + \sa withTransferFunctions() +*/ +void QColorSpace::setTransferFunctions(const QList &redTransferFunctionTable, + const QList &greenTransferFunctionTable, + const QList &blueTransferFunctionTable) +{ + if (!d_ptr) { + d_ptr = new QColorSpacePrivate(); + d_ptr->setTransferFunctionTables(redTransferFunctionTable, + greenTransferFunctionTable, + blueTransferFunctionTable); + d_ptr->ref.ref(); + return; + } + detach(); + d_ptr->description.clear(); + d_ptr->setTransferFunctionTables(redTransferFunctionTable, + greenTransferFunctionTable, + blueTransferFunctionTable); + d_ptr->gamma = 0; + d_ptr->identifyColorSpace(); +} + /*! Returns a copy of this color space, except using the transfer function \a transferFunction and \a gamma. @@ -681,7 +786,7 @@ QColorSpace QColorSpace::withTransferFunction(QColorSpace::TransferFunction tran \since 6.1 \sa transferFunction(), setTransferFunction() */ -QColorSpace QColorSpace::withTransferFunction(const QVector &transferFunctionTable) const +QColorSpace QColorSpace::withTransferFunction(const QList &transferFunctionTable) const { if (!isValid()) return *this; @@ -690,6 +795,25 @@ QColorSpace QColorSpace::withTransferFunction(const QVector &transferF return out; } +/*! + Returns a copy of this color space, except using the transfer functions + described by \a redTransferFunctionTable, \a greenTransferFunctionTable and + \a blueTransferFunctionTable. + + \since 6.1 + \sa setTransferFunctions() +*/ +QColorSpace QColorSpace::withTransferFunctions(const QList &redTransferFunctionTable, + const QList &greenTransferFunctionTable, + const QList &blueTransferFunctionTable) const +{ + if (!isValid()) + return *this; + QColorSpace out(*this); + out.setTransferFunctions(redTransferFunctionTable, greenTransferFunctionTable, blueTransferFunctionTable); + return out; +} + /*! Sets the primaries to those of the \a primariesId set. diff --git a/src/gui/painting/qcolorspace.h b/src/gui/painting/qcolorspace.h index 2d4de4c9a8..1620c75473 100644 --- a/src/gui/painting/qcolorspace.h +++ b/src/gui/painting/qcolorspace.h @@ -86,13 +86,18 @@ public: QColorSpace(NamedColorSpace namedColorSpace); QColorSpace(Primaries primaries, TransferFunction transferFunction, float gamma = 0.0f); QColorSpace(Primaries primaries, float gamma); - QColorSpace(Primaries primaries, const QVector &transferFunctionTable); + QColorSpace(Primaries primaries, const QList &transferFunctionTable); QColorSpace(const QPointF &whitePoint, const QPointF &redPoint, const QPointF &greenPoint, const QPointF &bluePoint, TransferFunction transferFunction, float gamma = 0.0f); QColorSpace(const QPointF &whitePoint, const QPointF &redPoint, const QPointF &greenPoint, const QPointF &bluePoint, - const QVector &transferFunctionTable); + const QList &transferFunctionTable); + QColorSpace(const QPointF &whitePoint, const QPointF &redPoint, + const QPointF &greenPoint, const QPointF &bluePoint, + const QList &redTransferFunctionTable, + const QList &greenTransferFunctionTable, + const QList &blueTransferFunctionTable); ~QColorSpace(); QColorSpace(const QColorSpace &colorSpace) noexcept; @@ -114,9 +119,15 @@ public: float gamma() const noexcept; void setTransferFunction(TransferFunction transferFunction, float gamma = 0.0f); - void setTransferFunction(const QVector &transferFunctionTable); + void setTransferFunction(const QList &transferFunctionTable); + void setTransferFunctions(const QList &redTransferFunctionTable, + const QList &greenTransferFunctionTable, + const QList &blueTransferFunctionTable); QColorSpace withTransferFunction(TransferFunction transferFunction, float gamma = 0.0f) const; - QColorSpace withTransferFunction(const QVector &transferFunctionTable) const; + QColorSpace withTransferFunction(const QList &transferFunctionTable) const; + QColorSpace withTransferFunctions(const QList &redTransferFunctionTable, + const QList &greenTransferFunctionTable, + const QList &blueTransferFunctionTable) const; void setPrimaries(Primaries primariesId); void setPrimaries(const QPointF &whitePoint, const QPointF &redPoint, diff --git a/src/gui/painting/qcolorspace_p.h b/src/gui/painting/qcolorspace_p.h index 9dbedd9e05..65e5bcf5ff 100644 --- a/src/gui/painting/qcolorspace_p.h +++ b/src/gui/painting/qcolorspace_p.h @@ -92,9 +92,13 @@ public: QColorSpacePrivate(); QColorSpacePrivate(QColorSpace::NamedColorSpace namedColorSpace); QColorSpacePrivate(QColorSpace::Primaries primaries, QColorSpace::TransferFunction transferFunction, float gamma); - QColorSpacePrivate(QColorSpace::Primaries primaries, const QVector &transferFunctionTable); + QColorSpacePrivate(QColorSpace::Primaries primaries, const QList &transferFunctionTable); QColorSpacePrivate(const QColorSpacePrimaries &primaries, QColorSpace::TransferFunction transferFunction, float gamma); - QColorSpacePrivate(const QColorSpacePrimaries &primaries, const QVector &transferFunctionTable); + QColorSpacePrivate(const QColorSpacePrimaries &primaries, const QList &transferFunctionTable); + QColorSpacePrivate(const QColorSpacePrimaries &primaries, + const QList &redTransferFunctionTable, + const QList &greenTransferFunctionTable, + const QList &blueRransferFunctionTable); QColorSpacePrivate(const QColorSpacePrivate &other) = default; static const QColorSpacePrivate *get(const QColorSpace &colorSpace) @@ -111,7 +115,10 @@ public: void setToXyzMatrix(); void setTransferFunction(); void identifyColorSpace(); - void setTransferFunctionTable(const QVector &transferFunctionTable); + void setTransferFunctionTable(const QList &transferFunctionTable); + void setTransferFunctionTables(const QList &redTransferFunctionTable, + const QList &greenTransferFunctionTable, + const QList &blueTransferFunctionTable); QColorTransform transformationToColorSpace(const QColorSpacePrivate *out) const; static constexpr QColorSpace::NamedColorSpace Unknown = QColorSpace::NamedColorSpace(0);