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++

Implement LCH for Lab and YCbCr

Wolthera van Hövell tot Westerflierfe0e19ca6eeb
diff --git a/libs/widgets/KisVisualColorModel.cpp b/libs/widgets/KisVisualColorModel.cpp
index 6e41c5a957..e85951777e 100644
--- a/libs/widgets/KisVisualColorModel.cpp
+++ b/libs/widgets/KisVisualColorModel.cpp
@@ -31,6 +31,7 @@ struct KisVisualColorModel::Private
const KoColorSpace *currentCS {0};
bool exposureSupported {false};
bool isRGBA {false};
+ bool isLABlike {false};
bool isLinear {false};
bool applyGamma {false};
bool allowUpdates {true};
@@ -250,6 +251,10 @@ KoColor KisVisualColorModel::convertChannelValuesToKoColor(const QVector4D &valu
baseValues[i] = pow(baseValues[i], 2.2);
}
}
+ } else if (m_d->model != ColorModel::Channel && m_d->isLABlike) {
+ QVector<qreal> tempVec({baseValues[0], baseValues[1], baseValues[2]});
+ LCHToLab(values.z(), values.y(), values.x(), &tempVec[0], &tempVec[1], &tempVec[2]);
+ baseValues = QVector4D(tempVec[0], tempVec[1], tempVec[2], 0);
}
if (m_d->exposureSupported) {
@@ -322,6 +327,17 @@ QVector4D KisVisualColorModel::convertKoColorToChannelValues(KoColor c) const
coordinates = QVector4D(hsy[0], hsy[1], hsy[2], 0.f);
}
// if we couldn't determine a hue, keep last value
+ if (coordinates[0] < 0) {
+ coordinates[0] = m_d->channelValues[0];
+ }
+ for (int i=0; i<3; i++) {
+ coordinates[i] = qBound(0.f, coordinates[i], 1.f);
+ }
+ } else if (m_d->model != ColorModel::Channel && m_d->isLABlike) {
+ qreal lch[3];
+ LabToLCH(channelValuesDisplay[0], channelValuesDisplay[1], channelValuesDisplay[2], &lch[0], &lch[1], &lch[2]);
+ coordinates = QVector4D(lch[2], lch[1], lch[0], 0.f);
+
if (coordinates[0] < 0) {
coordinates[0] = m_d->channelValues[0];
}
@@ -414,6 +430,7 @@ void KisVisualColorModel::loadColorSpace(const KoColorSpace *cs)
m_d->exposureSupported = false;
}
m_d->isRGBA = (cs->colorModelId() == RGBAColorModelID);
+ m_d->isLABlike = (cs->colorModelId() == LABAColorModelID || cs->colorModelId() == YCbCrAColorModelID);
const KoColorProfile *profile = cs->profile();
m_d->isLinear = (profile && profile->isLinear());
@@ -425,7 +442,7 @@ void KisVisualColorModel::loadColorSpace(const KoColorSpace *cs)
QVector <qreal> luma = cs->lumaCoefficients();
memcpy(m_d->lumaRGB, luma.constData(), 3*sizeof(qreal));
m_d->model = m_d->modelRGB;
- } else {
+ } else if (!m_d->isLABlike) {
m_d->model = KisVisualColorModel::Channel;
}