19 float dL = a[0] - b[0];
20 float dA = a[1] - b[1];
21 float dB = a[2] - b[2];
22 return qSqrt(dL * dL + dA * dA + dB * dB);
27 const float num = linearY * (1.0f + (linearY/(maxY*maxY)));
28 return num / (linearY + 1.0f);
33static void SolveAB(
float & lnA,
float &
B,
float x0,
float y0,
float m)
36 lnA = logf(y0) -
B*logf(x0);
39static void AsSlopeIntercept(
float & m,
float & b,
float x0,
float x1,
float y0,
float y1)
53 float ret = g*m*powf(m*x+b,g-1.0f);
63 QPointF overshoot = overshootPoint;
70 p0.setX(
p0.x()/maxWhite);
71 p1.setX(
p1.x()/maxWhite);
73 overshoot.setX(overshootPoint.x()/maxWhite);
81 linear.
lnA = g * logf(m);
94 const float x0 = (1.0f + overshoot.x()) -
p1.x();
95 const float y0 = (1.0f + overshoot.y()) -
p1.y();
96 SolveAB(shoulder.
lnA, shoulder.
b, x0, y0, shoulderM);
98 shoulder.
offsetX = (1.0f + overshoot.x());
99 shoulder.
offsetY = (1.0f + overshoot.y());
107 const float invScale = 1.0f / scale;
122 int index = (x <
p0.x()) ? 0 : ((x <
p1.x()) ? 1 : 2);
123 Segment s = segments.at(index);
129 float x0 = (x - offsetX) * scaleX;
130 float y0 = x0 > 0? expf(lnA + b * logf(x0)): 0.0;
131 return y0 * scaleY + offsetY;
136 const float uiGamma = 2.2f;
138 const float normalizedToeLength = powf(qBound(0.0f, toeLength, 1.0f), uiGamma);
139 const float normalizedToeStrength = qBound(0.0f, toeStrength, 1.0f);
140 const float normalizedShoulderAngle = qBound(0.0f, shoulderAngle, 1.0f);
142 const float x0 = normalizedToeLength * .5f;
143 const float y0 = (1.0f - normalizedToeStrength) * x0;
145 const float remainingY = 1.0f - y0;
146 const float initialW = x0 + remainingY;
148 const float y1_offset = (1.0f - shoulderStrength) * remainingY;
149 const float x1 = x0 + y1_offset;
150 const float y1 = y0 + y1_offset;
152 const float extraW = exp2f(shoulderLength)-1.0f;
153 const float W = initialW + extraW;
155 QPointF point0(powf(x0, uiGamma), powf(y0, uiGamma));
156 QPointF point1(powf(x1, uiGamma), powf(y1, uiGamma));
160 overshoot.setX((W * 2.0f) * normalizedShoulderAngle * shoulderStrength);
161 overshoot.setY(0.5f * normalizedShoulderAngle * shoulderStrength);
167 0.955473421488075, -0.02309845494876471, 0.06325924320057072, 0.0,
168 -0.0283697093338637, 1.0099953980813041, 0.021041441191917323, 0.0,
169 0.012314014864481998, -0.020507649298898964, 1.330365926242124, 0.0,
176 0.8190224379967030, 0.3619062600528904, -0.1288737815209879, 0.0,
177 0.0329836539323885, 0.9292868615863434, 0.0361446663506424, 0.0,
178 0.0481771893596242, 0.2642395317527308, 0.6335478284694309, 0.0,
185 0.2104542683093140, 0.7936177747023054, -0.0040720430116193, 0.0,
186 1.9779985324311684, -2.4285922420485799, 0.4505937096174110, 0.0,
187 0.0259040424655478, 0.7827717124575296, -0.8086757549230774, 0.0,
194 0.3592832590121217, 0.6976051147779502, -0.0358915932320290, 0.0,
195 -0.1920808463704993, 1.1004767970374321, 0.0753748658519118, 0.0,
196 0.0070797844607479, 0.0748396662186362, 0.8433265453898765, 0.0,
203 2048.0 / 4096.0, 2048.0 / 4096.0, 0.0 , 0.0,
204 6610.0 / 4096.0, -13613.0 / 4096.0, 7003.0 / 4096.0 , 0.0,
205 17933.0 / 4096.0, -17390.0 / 4096.0, -543.0 / 4096.0, 0.0,
214 const QVector4D lmsPrime = QVector4D(cbrtf(lms.x()),
216 cbrtf(lms.z()), 0.0);
223 const QVector4D lms = QVector4D(powf(lmsPrime.x(), 3.0),
224 powf(lmsPrime.y(), 3.0),
225 powf(lmsPrime.z(), 3.0), 0.0);
251 QMap<float, QPointF>
bounds;
260 for (
int i = 0; i < samplesPerChannel; i++) {
261 const float ch = float(i)/float(samplesPerChannel-1);
267 for (
int i = 0; i < samplesPerChannel; i++) {
268 const float ch = float(i)/float(samplesPerChannel-1);
274 for (
int i = 0; i < samplesPerChannel; i++) {
275 const float ch = float(i)/float(samplesPerChannel-1);
282 for (
int i = 0; i < samplesPerChannel; i++) {
283 const float ch = float(i)/float(samplesPerChannel-1);
289 for (
int i = 0; i < samplesPerChannel; i++) {
290 const float ch = float(i)/float(samplesPerChannel-1);
296 for (
int i = 0; i < samplesPerChannel; i++) {
297 const float ch = float(i)/float(samplesPerChannel-1);
308 std::array<qreal, 3> lch;
315 LabToLCH(labChannels[0], labChannels[1], labChannels[2], &lch[0], &lch[1], &lch[2]);
324 if (model ==
ICtCp) {
326 LabToLCH(ictcp.x(), ictcp.y()+0.5, ictcp.z()+0.5, &lch[0], &lch[1], &lch[2]);
329 LabToLCH(okLab.x(), okLab.y()+0.5, okLab.z()+0.5, &lch[0], &lch[1], &lch[2]);
333 bounds.insert(lch[2], QPointF(lch[1], lch[0]));
341 if (gamutCuspDescription.isEmpty())
return QPointF();
343 float firstAngle = 0.0;
344 float secondAngle = 0.0;
346 auto it = gamutCuspDescription.upperBound(hue);
347 if (it == gamutCuspDescription.begin()) {
348 firstAngle = gamutCuspDescription.lastKey();
349 secondAngle = gamutCuspDescription.firstKey();
350 }
else if (it == gamutCuspDescription.end()) {
351 firstAngle = gamutCuspDescription.lastKey();
352 secondAngle = gamutCuspDescription.firstKey();
354 firstAngle = std::prev(it).key();
355 secondAngle = it.key();
358 const float angle = firstAngle;
359 const float nextAngle = secondAngle;
361 QPointF lch1 = gamutCuspDescription.value(angle);
362 QPointF lch2 = gamutCuspDescription.value(nextAngle);
363 const float t = hue < angle
364 ? (hue - angle + 1.0) / (nextAngle + 1.0 - angle)
365 : (hue - angle) / (nextAngle - angle);
366 return QLineF(lch1, lch2).pointAt(t);
void LabToLCH(const qreal l, const qreal a, const qreal b, qreal *L, qreal *C, qreal *H)
const KoID Float32BitsColorDepthID("F32", ki18n("32-bit float/channel"))
const KoID XYZAColorModelID("XYZA", ki18n("XYZ/Alpha"))
const KoID Integer8BitsColorDepthID("U8", ki18n("8-bit integer/channel"))
const KoID CMYKAColorModelID("CMYKA", ki18n("CMYK/Alpha"))
const KoID LABAColorModelID("LABA", ki18n("L*a*b*/Alpha"))
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
ALWAYS_INLINE float applySmpte2048Curve(float x, float refWhite=203.0) noexcept
ALWAYS_INLINE float removeSmpte2048Curve(float x, float refWhite=203.0) noexcept
const QMatrix4x4 XYZtoOkLABLMS
const QMatrix4x4 xyz50To65_inv
static void AsSlopeIntercept(float &m, float &b, float x0, float x1, float y0, float y1)
static float EvalDerivativeLinearGamma(float m, float b, float g, float x)
const QMatrix4x4 XYZd65toDolbyLMS
const QMatrix4x4 xyz50To65
const QMatrix4x4 XYZtoOkLABLMS_inv
static void SolveAB(float &lnA, float &B, float x0, float y0, float m)
const QMatrix4x4 XYZd65toDolbyLMS_inv
const QMatrix4x4 lmsToOkLab_inv
const QMatrix4x4 lmsToICtCp
const QMatrix4x4 lmsToOkLab
const QMatrix4x4 lmsToICtCp_inv
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)
QMap< float, QPointF > KRITAPIGMENT_EXPORT getGamutCuspDescription(const KoColorProfile *profile, KoGamutMappingUtils::MappingModel model, const int samplesPerChannel=5)
getGamutCuspDescription Generates a hexagonal gamut cusp description from a RGB or CMYK profile.
QVector4D KRITAPIGMENT_EXPORT XYZToICtCp(const QVector4D &xyz)
XYZToICtCp Ad-hoc implementation of ICtCp for use in filters. Unlike the official YCbCr-compatible st...
MappingModel
The MappingModel enum This represents the preferred model to do gamut and/or tone mapping in.
QVector4D KRITAPIGMENT_EXPORT XYZToOkLab(const QVector4D &xyz)
XYZToOkLab Ad-hoc implementation of OkLAB. This takes a QVector4D and transforms it to the OkLAB mode...
float KRITAPIGMENT_EXPORT reinhardToneMapping(const float linearY, const float maxY)
reinhardToneMapping Implements 'extended' reinhard tonemapping.
QPointF KRITAPIGMENT_EXPORT cuspForHue(const QMap< float, QPointF > &gamutCuspDescription, const float hue)
virtual QString colorModelID() const
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)
static KoColorSpaceRegistry * instance()
float evalSegment(const float x)
The piecewiseFilmicCurve class Implement's Hable's piecewise filmic curve. https://filmicworlds....
static PiecewiseFilmicCurve fromUserParams(float toeStrength=0.5, float toeLength=0.5, float shoulderStrength=2.0, float shoulderLength=0.5, float shoulderAngle=1.0)
QVector< Segment > segments
float evalCurve(const float x)
PiecewiseFilmicCurve(float maxWhite, QPointF point0, QPointF point1, QPointF overshootPoint)