Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Allow reading and writing cicp values from icc profiles.

Wolthera van Hövell tot Westerflier946e3b240a80
diff --git a/plugins/color/lcms2engine/colorprofiles/IccColorProfile.cpp b/plugins/color/lcms2engine/colorprofiles/IccColorProfile.cpp
index 5e73824a7d..aec2007b1c 100644
--- a/plugins/color/lcms2engine/colorprofiles/IccColorProfile.cpp
+++ b/plugins/color/lcms2engine/colorprofiles/IccColorProfile.cpp
@@ -163,6 +163,15 @@ IccColorProfile::IccColorProfile(const QVector<double> &colorants,
cmsCIEXYZ media_blackpoint = {0.0, 0.0, 0.0};
cmsWriteTag (iccProfile, cmsSigMediaBlackPointTag, &media_blackpoint);
+ if (colorPrimariesType < 256 && transferFunction < 256) {
+ cmsVideoSignalType cicpValues;
+ cicpValues.ColourPrimaries = quint8(colorPrimariesType);
+ cicpValues.TransferCharacteristics = quint8(transferFunction);
+ cicpValues.MatrixCoefficients = 0;
+ cicpValues.VideoFullRangeFlag = 1; // TODO: double check.
+ cmsWriteTag (iccProfile, cmsSigcicpTag, &cicpValues);
+ }
+
//set the color profile info on the iccProfile;
cmsMLU *mlu;
mlu = cmsMLUalloc (NULL, 1);
@@ -450,6 +459,9 @@ bool IccColorProfile::init()
setInfo(d->shared->lcmsProfile->info());
setManufacturer(d->shared->lcmsProfile->manufacturer());
setCopyright(d->shared->lcmsProfile->copyright());
+ if (d->shared->lcmsProfile->hasCicpValues()) {
+ setCharacteristics(d->shared->lcmsProfile->cicpPrimaries(), d->shared->lcmsProfile->cicpTransfer());
+ }
if (d->shared->lcmsProfile->valid()) {
d->shared->profileInfo = Private::LazyProfileInfo([this] () {
return d->calculateFloatUIMinMax();
diff --git a/plugins/color/lcms2engine/colorprofiles/IccColorProfile.h b/plugins/color/lcms2engine/colorprofiles/IccColorProfile.h
index 2d32577dc3..e434c4916e 100644
--- a/plugins/color/lcms2engine/colorprofiles/IccColorProfile.h
+++ b/plugins/color/lcms2engine/colorprofiles/IccColorProfile.h
@@ -66,6 +66,9 @@ public:
virtual QVector <double> getEstimatedTRC() const = 0;
virtual bool compareTRC(TransferCharacteristics characteristics, float error) const = 0;
virtual QByteArray getProfileUniqueId() const = 0;
+ virtual bool hasCicpValues() const = 0;
+ virtual ColorPrimaries cicpPrimaries() const = 0;
+ virtual TransferCharacteristics cicpTransfer() const = 0;
};
public:
diff --git a/plugins/color/lcms2engine/colorprofiles/LcmsColorProfileContainer.cpp b/plugins/color/lcms2engine/colorprofiles/LcmsColorProfileContainer.cpp
index 5a53f39c41..55d039751e 100644
--- a/plugins/color/lcms2engine/colorprofiles/LcmsColorProfileContainer.cpp
+++ b/plugins/color/lcms2engine/colorprofiles/LcmsColorProfileContainer.cpp
@@ -103,6 +103,8 @@ public:
bool isSaturationCLUT;
bool isMatrixShaper;
+ cmsVideoSignalType *cicpValues {nullptr};
+
QByteArray uniqueId;
};
@@ -298,6 +300,10 @@ bool LcmsColorProfileContainer::init()
d->hasTRC = Private::LazyBool(Private::LazyBool::init_value_tag{}, {});
}
+ if (cmsIsTag(d->profile, cmsSigcicpTag)) {
+ d->cicpValues = ((cmsVideoSignalType *) cmsReadTag (d->profile, cmsSigcicpTag));
+ }
+
// Check if the profile can convert (something->this)
d->suitableForOutput = cmsIsIntentSupported(d->profile, INTENT_PERCEPTUAL, LCMS_USED_AS_OUTPUT);
d->suitableForInput = cmsIsIntentSupported(d->profile, INTENT_PERCEPTUAL, LCMS_USED_AS_INPUT);
@@ -636,6 +642,22 @@ QByteArray LcmsColorProfileContainer::getProfileUniqueId() const
return d->uniqueId;
}
+bool LcmsColorProfileContainer::hasCicpValues() const
+{
+ return (d->cicpValues);
+}
+
+ColorPrimaries LcmsColorProfileContainer::cicpPrimaries() const {
+ if (!d->cicpValues) return PRIMARIES_UNSPECIFIED;
+ return ColorPrimaries(d->cicpValues->ColourPrimaries);
+}
+
+TransferCharacteristics LcmsColorProfileContainer::cicpTransfer() const
+{
+ if (!d->cicpValues) return TRC_UNSPECIFIED;
+ return TransferCharacteristics(d->cicpValues->TransferCharacteristics);
+}
+
bool LcmsColorProfileContainer::compareTRC(TransferCharacteristics characteristics, float error) const
{
if (!*d->hasTRC) {
diff --git a/plugins/color/lcms2engine/colorprofiles/LcmsColorProfileContainer.h b/plugins/color/lcms2engine/colorprofiles/LcmsColorProfileContainer.h
index 3692db33ea..9ac0f2d221 100644
--- a/plugins/color/lcms2engine/colorprofiles/LcmsColorProfileContainer.h
+++ b/plugins/color/lcms2engine/colorprofiles/LcmsColorProfileContainer.h
@@ -95,6 +95,10 @@ public:
QString info() const override;
QByteArray getProfileUniqueId() const override;
+ bool hasCicpValues() const override;
+ ColorPrimaries cicpPrimaries() const override;
+ TransferCharacteristics cicpTransfer() const override;
+
bool compareTRC(TransferCharacteristics characteristics, float error) const override;
static cmsToneCurve* transferFunction(TransferCharacteristics transferFunction);