14.26: adaptive Contrast, Highlights and Shadows; Dehaze, Texture, Clarity and Sharpening

This commit is contained in:
ZacharyZhang-NY committed 2026-10-11 13:33:45 -04:00
1 parent a1453df517
commit 32f6362787
12 files changed
+289 -153

No files matched your search

+4 -28
View File
@@ -2,7 +2,7 @@
#include <QtTest>
#include <cmath>
// Swift 1.4.8: Shadows and Highlights keep tones in order.
// Swift 1.4.9: Shadows and Highlights keep tones in order.
using namespace CameraRawFixtures;
namespace {
@@ -25,19 +25,12 @@ std::vector<int> levels(double shadows, double highlights)
out.push_back(pixel[1]);
return out;
}
// Swift's bump, u(1 - 2u)² to a half, apart.
double bump(double u)
{
return u <= 0 || u >= 0.5 ? 0 : u * (1 - 2 * u) * (1 - 2 * u);
}
}
class CameraRawToneOrderTests : public QObject {
Q_OBJECT
private slots:
void shadowsAndHighlightsKeepTonesInOrder();
void eachToneFollowsSwiftsCurve();
};
void CameraRawToneOrderTests::shadowsAndHighlightsKeepTonesInOrder()
@@ -45,27 +38,10 @@ void CameraRawToneOrderTests::shadowsAndHighlightsKeepTonesInOrder()
for (const auto &[shadows, highlights] : std::vector<std::pair<double, double>>{{100, 0}, {-100, 0}, {0, 100}, {0, -100}}) {
const std::vector<int> out = levels(shadows, highlights);
QVERIFY2(std::ranges::is_sorted(out), qPrintable(QStringLiteral("shadows %1, highlights %2").arg(shadows).arg(highlights)));
QVERIFY2(out[0] <= 2 && out[255] >= 253, qPrintable(QStringLiteral("black %1, white %2").arg(out[0]).arg(out[255])));
}
QVERIFY(levels(100, 0)[45] >= 45 + 20);
}
void CameraRawToneOrderTests::eachToneFollowsSwiftsCurve()
{
// Gray stays gray; Highlights first, then Shadows.
for (const auto &[shadows, highlights] : std::vector<std::pair<double, double>>{{100, 0}, {-100, 0}, {60, 0}, {-50, 0}, {0, 100}, {0, -100}, {0, -40}, {0, 50}, {60, -40}, {-50, 50}}) {
const std::vector<int> out = levels(shadows, highlights);
const double low = shadows / 100, high = highlights / 100;
for (int level = 0; level < 256; ++level) {
const double y = level / 255.0;
const double lit = std::clamp(y + high * (high >= 0 ? 1.0 : 2.5) * bump(1 - y), 0.0, 1.0);
const double lifted = std::clamp(lit + low * (low >= 0 ? 2.5 : 1.0) * bump(lit), 0.0, 1.0);
QVERIFY2(std::abs(out[size_t(level)] - std::lround(lifted * 255)) <= 1,
qPrintable(QStringLiteral("%1, %2 at %3: %4").arg(shadows).arg(highlights).arg(level).arg(out[size_t(level)])));
}
// Black, middle gray and white stay where they were.
QVERIFY(out[0] <= 1 && std::abs(out[128] - 128) <= 1 && out[255] >= 254);
// Photoshop's Highlights −100 brings white to 239 here.
QVERIFY2(out[0] <= 2 && out[255] >= (highlights < 0 ? 235 : 253), qPrintable(QStringLiteral("black %1, white %2").arg(out[0]).arg(out[255])));
}
QVERIFY(levels(100, 0)[45] >= 45 + 12);
}
QTEST_MAIN(CameraRawToneOrderTests)