further fixes to ensure smooth transitions to clipped colours

This commit is contained in:
Alberto Griggio
2018-04-04 01:05:23 +02:00
parent acfdf220ec
commit 4344603a3d
3 changed files with 78 additions and 73 deletions

View File

@@ -45,6 +45,16 @@ namespace rtengine
class ToneCurve;
class ColorAppearance;
template <typename T>
void setUnlessOOG(T &r, T &g, T &b, const T &rr, const T &gg, const T &bb)
{
if (!OOG(r) || !OOG(g) || !OOG(b)) {
r = rr;
g = gg;
b = bb;
}
}
namespace curves {
inline void setLutVal(const LUTf &lut, float &val)
@@ -60,6 +70,21 @@ inline void setLutVal(const LUTf &lut, float &val)
}
}
inline void setLutVal(const LUTf &lut, float &rval, float &gval, float &bval)
{
if (!OOG(rval) || !OOG(gval) || !OOG(bval)) {
rval = lut[std::max(rval, 0.f)];
gval = lut[std::max(rval, 0.f)];
bval = lut[std::max(rval, 0.f)];
} else {
setLutVal(lut, rval);
setLutVal(lut, gval);
setLutVal(lut, bval);
}
}
inline void setLutVal(float &val, float lutval, float maxval)
{
if (!OOG(val)) {
@@ -69,6 +94,7 @@ inline void setLutVal(float &val, float lutval, float maxval)
}
}
} // namespace curves
class CurveFactory
@@ -907,9 +933,7 @@ inline void StandardToneCurve::Apply (float& r, float& g, float& b) const
assert (lutToneCurve);
curves::setLutVal(lutToneCurve, r);
curves::setLutVal(lutToneCurve, g);
curves::setLutVal(lutToneCurve, b);
curves::setLutVal(lutToneCurve, r, g, b);
}
inline void StandardToneCurve::BatchApply(
@@ -936,9 +960,7 @@ inline void StandardToneCurve::BatchApply(
break;
#endif
}
curves::setLutVal(lutToneCurve, r[i]);
curves::setLutVal(lutToneCurve, g[i]);
curves::setLutVal(lutToneCurve, b[i]);
curves::setLutVal(lutToneCurve, r[i], g[i], b[i]);
i++;
}
@@ -946,7 +968,7 @@ inline void StandardToneCurve::BatchApply(
float tmpr[4] ALIGNED16;
float tmpg[4] ALIGNED16;
float tmpb[4] ALIGNED16;
float mv = lutToneCurve[MAXVALF];
// float mv = lutToneCurve[MAXVALF];
for (; i + 3 < end; i += 4) {
__m128 r_val = LVF(r[i]);
__m128 g_val = LVF(g[i]);
@@ -955,17 +977,16 @@ inline void StandardToneCurve::BatchApply(
STVF(tmpg[0], lutToneCurve[g_val]);
STVF(tmpb[0], lutToneCurve[b_val]);
for (int j = 0; j < 4; ++j) {
curves::setLutVal(r[i+j], tmpr[j], mv);
curves::setLutVal(g[i+j], tmpg[j], mv);
curves::setLutVal(b[i+j], tmpb[j], mv);
setUnlessOOG(r[i+j], g[i+j], b[i+j], tmpr[j], tmpg[j], tmpb[j]);
// curves::setLutVal(r[i+j], tmpr[j], mv);
// curves::setLutVal(g[i+j], tmpg[j], mv);
// curves::setLutVal(b[i+j], tmpb[j], mv);
}
}
// Remainder in non-SSE.
for (; i < end; ++i) {
curves::setLutVal(lutToneCurve, r[i]);
curves::setLutVal(lutToneCurve, g[i]);
curves::setLutVal(lutToneCurve, b[i]);
curves::setLutVal(lutToneCurve, r[i], g[i], b[i]);
}
#endif
}
@@ -1003,9 +1024,7 @@ inline void AdobeToneCurve::Apply (float& ir, float& ig, float& ib) const
}
}
setUnlessOOG(ir, r);
setUnlessOOG(ig, g);
setUnlessOOG(ib, b);
setUnlessOOG(ir, ig, ib, r, g, b);
}
inline void AdobeToneCurve::RGBTone (float& r, float& g, float& b) const
@@ -1034,9 +1053,7 @@ inline void LuminanceToneCurve::Apply(float &ir, float &ig, float &ib) const
g = LIM<float>(g * coef, 0.f, 65535.f);
b = LIM<float>(b * coef, 0.f, 65535.f);
setUnlessOOG(ir, r);
setUnlessOOG(ig, g);
setUnlessOOG(ib, b);
setUnlessOOG(ir, ig, ib, r, g, b);
}
inline float WeightedStdToneCurve::Triangle(float a, float a1, float b) const
@@ -1094,9 +1111,7 @@ inline void WeightedStdToneCurve::Apply (float& ir, float& ig, float& ib) const
g = CLIP<float>(g1 * 0.25f + g2 * 0.50f + g3 * 0.25f);
b = CLIP<float>(b1 * 0.25f + b2 * 0.25f + b3 * 0.50f);
setUnlessOOG(ir, r);
setUnlessOOG(ig, g);
setUnlessOOG(ib, b);
setUnlessOOG(ir, ig, ib, r, g, b);
}
inline void WeightedStdToneCurve::BatchApply(const size_t start, const size_t end, float *r, float *g, float *b) const {
@@ -1154,9 +1169,7 @@ inline void WeightedStdToneCurve::BatchApply(const size_t start, const size_t en
STVF(tmpg[0], LIMV(g1 * zd25v + g2 * zd5v + g3 * zd25v, ZEROV, c65535v));
STVF(tmpb[0], LIMV(b1 * zd25v + b2 * zd25v + b3 * zd5v, ZEROV, c65535v));
for (int j = 0; j < 4; ++j) {
setUnlessOOG(r[i+j], tmpr[j]);
setUnlessOOG(g[i+j], tmpg[j]);
setUnlessOOG(b[i+j], tmpb[j]);
setUnlessOOG(r[i+j], g[i+j], b[i+j], tmpr[j], tmpg[j], tmpb[j]);
}
}
@@ -1201,9 +1214,7 @@ inline void SatAndValueBlendingToneCurve::Apply (float& ir, float& ig, float& ib
}
Color::hsv2rgbdcp(h, s, v + dV, r, g, b);
setUnlessOOG(ir, r);
setUnlessOOG(ig, g);
setUnlessOOG(ib, b);
setUnlessOOG(ir, ig, ib, r, g, b);
}
}