summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/image/qpnghandler.cpp2
-rw-r--r--src/gui/painting/qcolorspace.cpp29
-rw-r--r--src/gui/painting/qcolorspace.h3
-rw-r--r--src/gui/painting/qcolorspace_p.h1
-rw-r--r--src/gui/painting/qicc.cpp2
-rw-r--r--tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp23
6 files changed, 57 insertions, 3 deletions
diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp
index 20a86b4f8f..9943e7261a 100644
--- a/src/gui/image/qpnghandler.cpp
+++ b/src/gui/image/qpnghandler.cpp
@@ -965,7 +965,7 @@ bool QPNGImageWriter::writeImage(const QImage& image, int compression_in, const
// Support the old gamma making it override transferfunction.
if (gamma != 0.0 && !qFuzzyCompare(cs.gamma(), 1.0f / gamma))
cs = cs.withTransferFunction(QColorSpace::TransferFunction::Gamma, 1.0f / gamma);
- QByteArray iccProfileName = QColorSpacePrivate::get(cs)->description.toLatin1();
+ QByteArray iccProfileName = cs.description().toLatin1();
if (iccProfileName.isEmpty())
iccProfileName = QByteArrayLiteral("Custom");
QByteArray iccProfile = cs.iccProfile();
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<uint16_t> &transferFunctionTable);
void setTransferFunctions(const QList<uint16_t> &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);
diff --git a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp
index bc26552311..ce21dbe9b7 100644
--- a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp
+++ b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp
@@ -80,6 +80,8 @@ private slots:
void changePrimaries();
void transferFunctionTable();
+
+ void description();
};
tst_QColorSpace::tst_QColorSpace()
@@ -225,7 +227,7 @@ void tst_QColorSpace::fromIccProfile()
QCOMPARE(fileColorSpace, namedColorSpace);
QCOMPARE(fileColorSpace.transferFunction(), transferFunction);
- QCOMPARE(QColorSpacePrivate::get(fileColorSpace)->description, description);
+ QCOMPARE(fileColorSpace.description(), description);
}
void tst_QColorSpace::imageConversion_data()
@@ -616,5 +618,24 @@ void tst_QColorSpace::transferFunctionTable()
QCOMPARE(customSRgb, QColorSpace::SRgbLinear);
}
+void tst_QColorSpace::description()
+{
+ QColorSpace srgb(QColorSpace::SRgb);
+ QCOMPARE(srgb.description(), QLatin1String("sRGB"));
+
+ srgb.setTransferFunction(QColorSpace::TransferFunction::ProPhotoRgb);
+ QCOMPARE(srgb.description(), QString()); // No longer sRGB
+ srgb.setTransferFunction(QColorSpace::TransferFunction::Linear);
+ QCOMPARE(srgb.description(), QLatin1String("Linear sRGB")); // Auto-detect
+
+ srgb.setTransferFunction(QColorSpace::TransferFunction::ProPhotoRgb);
+ srgb.setDescription(QStringLiteral("My custom sRGB"));
+ QCOMPARE(srgb.description(), QLatin1String("My custom sRGB"));
+ srgb.setTransferFunction(QColorSpace::TransferFunction::Linear);
+ QCOMPARE(srgb.description(), QLatin1String("My custom sRGB")); // User given name not reset
+ srgb.setDescription(QString());
+ QCOMPARE(srgb.description(), QLatin1String("Linear sRGB")); // Set to empty returns default behavior
+}
+
QTEST_MAIN(tst_QColorSpace)
#include "tst_qcolorspace.moc"