29struct xyzToOkLabModel {
30 static ALWAYS_INLINE std::array<qreal, 3> toLCH (
const float* xyzChannels) {
32 std::array<qreal, 3> lch {0.0, 0.0, 0.0};
33 LabToLCH(OkLab.x(), OkLab.y()+0.5, OkLab.z()+0.5, &lch[0], &lch[1], &lch[2]);
37 static ALWAYS_INLINE void fromLCH (
const std::array<qreal, 3> &lch,
float *xyzChannels) {
38 std::array<qreal, 3> output {0.0, 0.0, 0.0};
39 LCHToLab(lch[0], lch[1], lch[2], &output[0], &output[1], &output[2]);
42 xyzChannels[0] = xyz.x();
43 xyzChannels[1] = xyz.y();
44 xyzChannels[2] = xyz.z();
49 static ALWAYS_INLINE float cuberootLightness(
float lightness) {
54struct xyzToICtCpModel {
55 static ALWAYS_INLINE std::array<qreal, 3> toLCH (
const float *xyzChannels) {
56 QVector4D color (xyzChannels[0], xyzChannels[1], xyzChannels[2], 1.0);
58 std::array<qreal, 3> lch {0.0, 0.0, 0.0};
64 static ALWAYS_INLINE void fromLCH (
const std::array<qreal, 3> &lch,
float *xyzChannels) {
65 std::array<qreal, 3> output {0.0, 0.0, 0.0};
66 LCHToLab(lch[0], lch[1], lch[2], &output[0], &output[1], &output[2]);
69 QVector4D color (output[0], output[1]-0.5, output[2]-0.5, 0.0);
71 xyzChannels[0] = xyz.x();
72 xyzChannels[1] = xyz.y();
73 xyzChannels[2] = xyz.z();
77 static ALWAYS_INLINE float cuberootLightness(
float lightness) {
83 static ALWAYS_INLINE std::array<qreal, 3> toLCH (
const float *labChannels) {
84 std::array<qreal, 3> lch {0.0, 0.0, 0.0};
85 LabToLCH(labChannels[0], labChannels[1], labChannels[2], &lch[0], &lch[1], &lch[2]);
89 static ALWAYS_INLINE void fromLCH (
const std::array<qreal, 3> &lch,
float *labChannels) {
90 std::array<qreal, 3> output {0.0, 0.0, 0.0};
91 LCHToLab(lch[0], lch[1], lch[2], &output[0], &output[1], &output[2]);
92 labChannels[0] = output[0];
93 labChannels[1] = output[1];
94 labChannels[2] = output[2];
97 static ALWAYS_INLINE float cuberootLightness(
float lightness) {
109template<
class ModelType,
class DifferenceType>
118 void transform(
const quint8 *srcU8, quint8 *dstU8, qint32 nPixels)
const override
122 qWarning() <<
"no source space!";
126 if (!targetProfile) {
133 qWarning() <<
"no target space!";
140 std::unique_ptr<quint8[]> tmpTarget (
new quint8[targetSpace->
pixelSize()]);
142 std::array<qreal, 3> LCH {0.0, 0.0, 0.0};
144 while (nPixels > 0) {
150 LCH = ModelType::toLCH(originalChannels.data());
152 ModelType::fromLCH(LCH, originalChannels.data());
155 LCH = ModelType::toLCH(originalChannels.data());
164 const float L = ModelType::cuberootLightness(LCH[0]);
165 const float cuspL = ModelType::cuberootLightness(cusp.y());
166 if (LCH[0] > cusp.y()) {
167 const float t = (L - cuspL) / (1.0 - cuspL);
168 const float c = qMax(0.0, cusp.x()* (1.0-t));
170 LCH[1] = qMin(LCH[1], qreal(c));
173 const float t = L / (cuspL);
174 const float c = qMax(0.0, cusp.x()*t);
175 LCH[1] = qMin(LCH[1], qreal(c));
177 ModelType::fromLCH(LCH, originalChannels.data());
185 if (DifferenceType::difference(originalChannels, clippedChannels) > 0.02) {
186 LCH = ModelType::toLCH(originalChannels.data());
191 while (
max-min > 0.0001) {
193 LCH[1] = (
max + min) * 0.5;
194 ModelType::fromLCH(LCH, originalChannels.data());
202 if (DifferenceType::difference(originalChannels, clippedChannels) < 0.02) {
222 list <<
"targetColorProfileName";
223 list <<
"cuspDescription";
229 if (name ==
"targetColorProfileName") {
231 }
else if (name ==
"cuspDescription") {
248 const QVariantMap map = parameter.toMap();
249 Q_FOREACH (QString key, map.keys()){
301 dbgKrita <<
"Unsupported color space " << colorSpace->
id() <<
" in KisGamutMapClipAdjustmentFactory::createTransformation";
void LabToLCH(const qreal l, const qreal a, const qreal b, qreal *L, qreal *C, qreal *H)
void LCHToLab(const qreal L, const qreal C, const qreal H, qreal *l, qreal *a, qreal *b)
const KoID Float32BitsColorDepthID("F32", ki18n("32-bit float/channel"))
const KoID YCbCrAColorModelID("YCbCrA", ki18n("YCbCr/Alpha"))
const KoID GrayAColorModelID("GRAYA", ki18n("Grayscale/Alpha"))
const KoID XYZAColorModelID("XYZA", ki18n("XYZ/Alpha"))
const KoID Integer16BitsColorDepthID("U16", ki18n("16-bit integer/channel"))
const KoID LABAColorModelID("LABA", ki18n("L*a*b*/Alpha"))
ALWAYS_INLINE float removeSmpte2048Curve(float x, float refWhite=203.0) noexcept
KoColorTransformation * createTransformation(const KoColorSpace *colorSpace, QHash< QString, QVariant > parameters) const override
KisGamutMapClipAdjustmentFactory()
QList< QPair< KoID, KoID > > supportedModels() const override
const KoColorSpace * m_sourceSpace
void setParameter(int id, const QVariant ¶meter) override
QMap< float, QPointF > m_cuspDescription
int parameterId(const QString &name) const override
KisGamutMapClipAdjustment(const KoColorSpace *sourceSpace)
void transform(const quint8 *srcU8, quint8 *dstU8, qint32 nPixels) const override
QList< QString > parameters() const override
QString m_targetColorProfileName
virtual quint32 pixelSize() const =0
virtual KoID colorModelId() const =0
virtual quint32 channelCount() const =0
virtual void normalisedChannelsValue(const quint8 *pixel, QVector< float > &channels) const =0
virtual void fromNormalisedChannelsValue(quint8 *pixel, const QVector< float > &values) const =0
virtual bool convertPixelsTo(const quint8 *src, quint8 *dst, const KoColorSpace *dstColorSpace, quint32 numPixels, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags) const
QVector4D KRITAPIGMENT_EXPORT ICtCpToXYZ(const QVector4D &iCtCp)
float KRITAPIGMENT_EXPORT deltaE76(const QVector< float > &a, const QVector< float > &b)
deltaE76 calculates the difference between two colors, represented as normalized channels.
QVector4D KRITAPIGMENT_EXPORT OkLabToXYZ(const QVector4D &okLab)
QVector4D KRITAPIGMENT_EXPORT XYZToICtCp(const QVector4D &xyz)
XYZToICtCp Ad-hoc implementation of ICtCp for use in filters. Unlike the official YCbCr-compatible st...
QVector4D KRITAPIGMENT_EXPORT XYZToOkLab(const QVector4D &xyz)
XYZToOkLab Ad-hoc implementation of OkLAB. This takes a QVector4D and transforms it to the OkLAB mode...
QPointF KRITAPIGMENT_EXPORT cuspForHue(const QMap< float, QPointF > &gamutCuspDescription, const float hue)
constexpr std::enable_if< sizeof...(values)==0, size_t >::type max()
virtual QString colorModelID() const
const KoColorProfile * profileByName(const QString &name) const
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)
static KoColorSpaceRegistry * instance()