From 01c55405fa55add25a469bdaee8c562ab3ab8941 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 26 Feb 2021 14:20:47 +0100 Subject: Add QColorSpace::description A way to read the description of the profile from ICC, or set one yourself. Change-Id: I68622e30ee209cac99c41f3df934712c3548c0de Reviewed-by: Friedemann Kleint Reviewed-by: Eirik Aavitsland --- src/gui/painting/qcolorspace.cpp | 29 +++++++++++++++++++++++++++++ src/gui/painting/qcolorspace.h | 3 +++ src/gui/painting/qcolorspace_p.h | 1 + src/gui/painting/qicc.cpp | 2 +- 4 files changed, 34 insertions(+), 1 deletion(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qcolorspace.cpp b/src/gui/painting/qcolorspace.cpp index e1f8d0b63b..e770d929d3 100644 --- a/src/gui/painting/qcolorspace.cpp +++ b/src/gui/painting/qcolorspace.cpp @@ -1014,6 +1014,35 @@ QColorSpace::operator QVariant() const return QVariant::fromValue(*this); } +/*! + 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. + + \since 6.2 +*/ +QString QColorSpace::description() const noexcept +{ + if (d_ptr) + return d_ptr->userDescription.isEmpty() ? d_ptr->description : d_ptr->userDescription; + return QString(); +} + +/*! + Sets the name or short description of the color space to \a description. + + If set to empty description() will return original or guessed descriptions + instead. + + \since 6.2 +*/ +void QColorSpace::setDescription(const QString &description) +{ + detach(); + d_ptr->userDescription = description; +} + /***************************************************************************** QColorSpace stream functions *****************************************************************************/ diff --git a/src/gui/painting/qcolorspace.h b/src/gui/painting/qcolorspace.h index 1620c75473..43ae2257c0 100644 --- a/src/gui/painting/qcolorspace.h +++ b/src/gui/painting/qcolorspace.h @@ -118,6 +118,9 @@ public: TransferFunction transferFunction() const noexcept; float gamma() const noexcept; + QString description() const noexcept; + void setDescription(const QString &description); + void setTransferFunction(TransferFunction transferFunction, float gamma = 0.0f); void setTransferFunction(const QList &transferFunctionTable); void setTransferFunctions(const QList &redTransferFunctionTable, diff --git a/src/gui/painting/qcolorspace_p.h b/src/gui/painting/qcolorspace_p.h index 65e5bcf5ff..b5e5263cae 100644 --- a/src/gui/painting/qcolorspace_p.h +++ b/src/gui/painting/qcolorspace_p.h @@ -133,6 +133,7 @@ public: QColorMatrix toXyz; QString description; + QString userDescription; QByteArray iccProfile; static QBasicMutex s_lutWriteLock; diff --git a/src/gui/painting/qicc.cpp b/src/gui/painting/qicc.cpp index 2e6d295ce5..8196ccc595 100644 --- a/src/gui/painting/qicc.cpp +++ b/src/gui/painting/qicc.cpp @@ -407,7 +407,7 @@ QByteArray toIccProfile(const QColorSpace &space) } descOffset = currentOffset; - QByteArray description = spaceDPtr->description.toUtf8(); + QByteArray description = space.description().toUtf8(); stream << uint(Tag::desc) << uint(0); stream << uint(description.size() + 1); stream.writeRawData(description.constData(), description.size() + 1); -- cgit v1.2.3