Remove some duplicate code in rtengine/curves.cc

This commit is contained in:
heckflosse
2017-10-23 20:41:20 +02:00
parent fa4444d6d3
commit 841679c6db
2 changed files with 12 additions and 158 deletions

View File

@@ -801,11 +801,6 @@ class StandardToneCurve : public ToneCurve
public:
void Apply(float& r, float& g, float& b) const;
};
class StandardToneCurvebw : public ToneCurve
{
public:
void Apply(float& r, float& g, float& b) const;
};
class AdobeToneCurve : public ToneCurve
{
@@ -816,27 +811,12 @@ public:
void Apply(float& r, float& g, float& b) const;
};
class AdobeToneCurvebw : public ToneCurve
{
private:
void RGBTone(float& r, float& g, float& b) const; // helper for tone curve
public:
void Apply(float& r, float& g, float& b) const;
};
class SatAndValueBlendingToneCurve : public ToneCurve
{
public:
void Apply(float& r, float& g, float& b) const;
};
class SatAndValueBlendingToneCurvebw : public ToneCurve
{
public:
void Apply(float& r, float& g, float& b) const;
};
class WeightedStdToneCurve : public ToneCurve
{
private:
@@ -884,14 +864,6 @@ public:
void Apply(float& r, float& g, float& b, PerceptualToneCurveState & state) const;
};
class WeightedStdToneCurvebw : public ToneCurve
{
private:
float Triangle(float refX, float refY, float X2) const;
public:
void Apply(float& r, float& g, float& b) const;
};
// Standard tone curve
inline void StandardToneCurve::Apply (float& r, float& g, float& b) const
{
@@ -902,16 +874,6 @@ inline void StandardToneCurve::Apply (float& r, float& g, float& b) const
g = lutToneCurve[g];
b = lutToneCurve[b];
}
// Standard tone curve
inline void StandardToneCurvebw::Apply (float& r, float& g, float& b) const
{
assert (lutToneCurve);
r = lutToneCurve[r];
g = lutToneCurve[g];
b = lutToneCurve[b];
}
// Tone curve according to Adobe's reference implementation
// values in 0xffff space
@@ -943,33 +905,6 @@ inline void AdobeToneCurve::Apply (float& r, float& g, float& b) const
}
}
}
inline void AdobeToneCurvebw::Apply (float& r, float& g, float& b) const
{
assert (lutToneCurve);
if (r >= g) {
if (g > b) {
RGBTone (r, g, b); // Case 1: r >= g > b
} else if (b > r) {
RGBTone (b, r, g); // Case 2: b > r >= g
} else if (b > g) {
RGBTone (r, b, g); // Case 3: r >= b > g
} else { // Case 4: r >= g == b
r = lutToneCurve[r];
g = lutToneCurve[g];
b = g;
}
} else {
if (r >= b) {
RGBTone (g, r, b); // Case 5: g > r >= b
} else if (b > g) {
RGBTone (b, g, r); // Case 6: b > g > r
} else {
RGBTone (g, b, r); // Case 7: g >= b > r
}
}
}
inline void AdobeToneCurve::RGBTone (float& r, float& g, float& b) const
{
@@ -979,14 +914,6 @@ inline void AdobeToneCurve::RGBTone (float& r, float& g, float& b) const
b = lutToneCurve[bold];
g = b + ((r - b) * (gold - bold) / (rold - bold));
}
inline void AdobeToneCurvebw::RGBTone (float& r, float& g, float& b) const
{
float rold = r, gold = g, bold = b;
r = lutToneCurve[rold];
b = lutToneCurve[bold];
g = b + ((r - b) * (gold - bold) / (rold - bold));
}
// Modifying the Luminance channel only
inline void LuminanceToneCurve::Apply(float &r, float &g, float &b) const
@@ -1019,23 +946,6 @@ inline float WeightedStdToneCurve::Triangle(float a, float a1, float b) const
return a1;
}
inline float WeightedStdToneCurvebw::Triangle(float a, float a1, float b) const
{
if (a != b) {
float b1;
float a2 = a1 - a;
if (b < a) {
b1 = b + a2 * b / a ;
} else {
b1 = b + a2 * (65535.f - b) / (65535.f - a);
}
return b1;
}
return a1;
}
// Tone curve modifying the value channel only, preserving hue and saturation
// values in 0xffff space
@@ -1061,28 +971,6 @@ inline void WeightedStdToneCurve::Apply (float& r, float& g, float& b) const
b = CLIP<float>(b1 * 0.25f + b2 * 0.25f + b3 * 0.50f);
}
inline void WeightedStdToneCurvebw::Apply (float& r, float& g, float& b) const
{
assert (lutToneCurve);
float r1 = lutToneCurve[r];
float g1 = Triangle(r, r1, g);
float b1 = Triangle(r, r1, b);
float g2 = lutToneCurve[g];
float r2 = Triangle(g, g2, r);
float b2 = Triangle(g, g2, b);
float b3 = lutToneCurve[b];
float r3 = Triangle(b, b3, r);
float g3 = Triangle(b, b3, g);
r = CLIP<float>( r1 * 0.50f + r2 * 0.25f + r3 * 0.25f);
g = CLIP<float>(g1 * 0.25f + g2 * 0.50f + g3 * 0.25f);
b = CLIP<float>(b1 * 0.25f + b2 * 0.25f + b3 * 0.50f);
}
// Tone curve modifying the value channel only, preserving hue and saturation
// values in 0xffff space
inline void SatAndValueBlendingToneCurve::Apply (float& r, float& g, float& b) const
@@ -1099,54 +987,20 @@ inline void SatAndValueBlendingToneCurve::Apply (float& r, float& g, float& b) c
return;
}
bool increase = newLum > lum;
Color::rgb2hsv(r, g, b, h, s, v);
if (increase) {
float dV;
if (newLum > lum) {
// Linearly targeting Value = 1 and Saturation = 0
float coef = (newLum - lum) / (65535.f - lum);
float dV = (1.f - v) * coef;
dV = (1.f - v) * coef;
s *= 1.f - coef;
Color::hsv2rgb(h, s, v + dV, r, g, b);
} else {
// Linearly targeting Value = 0
float coef = (lum - newLum) / lum ;
float dV = v * coef;
Color::hsv2rgb(h, s, v - dV, r, g, b);
}
}
inline void SatAndValueBlendingToneCurvebw::Apply (float& r, float& g, float& b) const
{
assert (lutToneCurve);
float h, s, v;
float lum = (r + g + b) / 3.f;
//float lum = Color::rgbLuminance(r, g, b);
float newLum = lutToneCurve[lum];
if (newLum == lum) {
return;
}
bool increase = newLum > lum;
Color::rgb2hsv(r, g, b, h, s, v);
if (increase) {
// Linearly targeting Value = 1 and Saturation = 0
float coef = (newLum - lum) / (65535.f - lum);
float dV = (1.f - v) * coef;
s *= 1.f - coef;
Color::hsv2rgb(h, s, v + dV, r, g, b);
} else {
// Linearly targeting Value = 0
float coef = (lum - newLum) / lum ;
float dV = v * coef;
Color::hsv2rgb(h, s, v - dV, r, g, b);
float coef = (newLum - lum) / lum ;
dV = v * coef;
}
Color::hsv2rgb(h, s, v + dV, r, g, b);
}
}