Krita Source Code Documentation
Loading...
Searching...
No Matches
KoGamutMappingUtils::PiecewiseFilmicCurve Struct Reference

The piecewiseFilmicCurve class Implement's Hable's piecewise filmic curve. https://filmicworlds.com/blog/filmic-tonemapping-with-piecewise-power-curves/ License: CC-0. More...

#include <KoGamutMappingUtils.h>

Classes

struct  Segment
 

Public Member Functions

float evalCurve (const float x)
 
 PiecewiseFilmicCurve (float maxWhite, QPointF point0, QPointF point1, QPointF overshootPoint)
 

Static Public Member Functions

static PiecewiseFilmicCurve fromUserParams (float toeStrength=0.5, float toeLength=0.5, float shoulderStrength=2.0, float shoulderLength=0.5, float shoulderAngle=1.0)
 

Public Attributes

float inverseMaxWhite {1.0}
 
QPointF p0
 
QPointF p1
 
QVector< Segment > segments
 

Detailed Description

The piecewiseFilmicCurve class Implement's Hable's piecewise filmic curve. https://filmicworlds.com/blog/filmic-tonemapping-with-piecewise-power-curves/ License: CC-0.

Definition at line 86 of file KoGamutMappingUtils.h.

Constructor & Destructor Documentation

◆ PiecewiseFilmicCurve()

KoGamutMappingUtils::PiecewiseFilmicCurve::PiecewiseFilmicCurve ( float maxWhite,
QPointF point0,
QPointF point1,
QPointF overshootPoint )

Definition at line 57 of file KoGamutMappingUtils.cpp.

58{
60
61 p0 = point0;
62 p1 = point1;
63 QPointF overshoot = overshootPoint;
64
65 inverseMaxWhite = 1.0/maxWhite;
66 // normalize
67
68
69
70 p0.setX(p0.x()/maxWhite);
71 p1.setX(p1.x()/maxWhite);
72
73 overshoot.setX(overshootPoint.x()/maxWhite);
74
75 Segment linear;
76 float m, b;
77 AsSlopeIntercept(m, b, p0.x(), p1.x(), p0.y(), p1.y());
78 const float g = 1.0;
79
80 linear.offsetX = -(b / m);
81 linear.lnA = g * logf(m);
82 linear.b = g;
83
84 segments[1] = linear;
85
86 const float toeM = EvalDerivativeLinearGamma(m, b, g, p0.x());
87 const float shoulderM = EvalDerivativeLinearGamma(m, b, g, p1.x());
88
89 Segment toe;
90 SolveAB(toe.lnA, toe.b, p0.x(), p0.y(), toeM);
91 segments[0] = toe;
92
93 Segment shoulder;
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);
97
98 shoulder.offsetX = (1.0f + overshoot.x());
99 shoulder.offsetY = (1.0f + overshoot.y());
100 shoulder.scaleX = -1.0;
101 shoulder.scaleY = -1.0;
102
103 segments[2] = shoulder;
104
105 {
106 const float scale = shoulder.evalSegment(1.0f);
107 const float invScale = 1.0f / scale;
108
109 segments[0].offsetY *= invScale;
110 segments[0].scaleY *= invScale;
111
112 segments[1].offsetY *= invScale;
113 segments[1].scaleY *= invScale;
114
115 segments[2].offsetY *= invScale;
116 segments[2].scaleY *= invScale;
117 }
118}
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)
static void SolveAB(float &lnA, float &B, float x0, float y0, float m)

References AsSlopeIntercept(), KoGamutMappingUtils::PiecewiseFilmicCurve::Segment::b, EvalDerivativeLinearGamma(), KoGamutMappingUtils::PiecewiseFilmicCurve::Segment::evalSegment(), inverseMaxWhite, KoGamutMappingUtils::PiecewiseFilmicCurve::Segment::lnA, KoGamutMappingUtils::PiecewiseFilmicCurve::Segment::offsetX, KoGamutMappingUtils::PiecewiseFilmicCurve::Segment::offsetY, p0, p1, KoGamutMappingUtils::PiecewiseFilmicCurve::Segment::scaleX, KoGamutMappingUtils::PiecewiseFilmicCurve::Segment::scaleY, segments, and SolveAB().

Member Function Documentation

◆ evalCurve()

float KoGamutMappingUtils::PiecewiseFilmicCurve::evalCurve ( const float x)

Definition at line 120 of file KoGamutMappingUtils.cpp.

121{
122 int index = (x < p0.x()) ? 0 : ((x < p1.x()) ? 1 : 2);
123 Segment s = segments.at(index);
124 return s.evalSegment(x*inverseMaxWhite);
125}

References KoGamutMappingUtils::PiecewiseFilmicCurve::Segment::evalSegment(), p0, and p1.

◆ fromUserParams()

KoGamutMappingUtils::PiecewiseFilmicCurve KoGamutMappingUtils::PiecewiseFilmicCurve::fromUserParams ( float toeStrength = 0.5,
float toeLength = 0.5,
float shoulderStrength = 2.0,
float shoulderLength = 0.5,
float shoulderAngle = 1.0 )
static

Definition at line 134 of file KoGamutMappingUtils.cpp.

135{
136 const float uiGamma = 2.2f;
137
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);
141
142 const float x0 = normalizedToeLength * .5f;
143 const float y0 = (1.0f - normalizedToeStrength) * x0;
144
145 const float remainingY = 1.0f - y0;
146 const float initialW = x0 + remainingY;
147
148 const float y1_offset = (1.0f - shoulderStrength) * remainingY;
149 const float x1 = x0 + y1_offset;
150 const float y1 = y0 + y1_offset;
151
152 const float extraW = exp2f(shoulderLength)-1.0f;
153 const float W = initialW + extraW;
154
155 QPointF point0(powf(x0, uiGamma), powf(y0, uiGamma));
156 QPointF point1(powf(x1, uiGamma), powf(y1, uiGamma));
157 float maxWhite = W;
158
159 QPointF overshoot;
160 overshoot.setX((W * 2.0f) * normalizedShoulderAngle * shoulderStrength);
161 overshoot.setY(0.5f * normalizedShoulderAngle * shoulderStrength);
162
163 return PiecewiseFilmicCurve(maxWhite, point0, point1, overshoot);
164}
PiecewiseFilmicCurve(float maxWhite, QPointF point0, QPointF point1, QPointF overshootPoint)

Member Data Documentation

◆ inverseMaxWhite

float KoGamutMappingUtils::PiecewiseFilmicCurve::inverseMaxWhite {1.0}

Definition at line 91 of file KoGamutMappingUtils.h.

91{1.0};

◆ p0

QPointF KoGamutMappingUtils::PiecewiseFilmicCurve::p0

Definition at line 88 of file KoGamutMappingUtils.h.

◆ p1

QPointF KoGamutMappingUtils::PiecewiseFilmicCurve::p1

Definition at line 89 of file KoGamutMappingUtils.h.

◆ segments

QVector<Segment> KoGamutMappingUtils::PiecewiseFilmicCurve::segments

Definition at line 105 of file KoGamutMappingUtils.h.


The documentation for this struct was generated from the following files: