Merge "Add QColorSpace::description"
This commit is contained in:
commit
9fb81fc287
@ -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();
|
||||
|
@ -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
|
||||
*****************************************************************************/
|
||||
|
@ -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,
|
||||
|
@ -133,6 +133,7 @@ public:
|
||||
QColorMatrix toXyz;
|
||||
|
||||
QString description;
|
||||
QString userDescription;
|
||||
QByteArray iccProfile;
|
||||
|
||||
static QBasicMutex s_lutWriteLock;
|
||||
|
@ -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);
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user