14.26: adaptive Contrast, Highlights and Shadows; Dehaze, Texture, Clarity and Sharpening
This commit is contained in:
12 files changed
+289
-153
No files matched your search
@@ -130,12 +130,16 @@ void CameraRawRulesTests::theClippingAndMaskViewsShowNothingElse()
|
||||
|
||||
void CameraRawRulesTests::theScaleDefaultsToOneAndReachesTheRadii()
|
||||
{
|
||||
// Glow's reach reads the scale; Clarity's follows the picture.
|
||||
CameraRawSettings settings;
|
||||
settings.clarity = 100;
|
||||
settings.glow = 100;
|
||||
const QImage edge = step();
|
||||
QVERIFY(pixels(settings.apply(edge, std::nullopt, 0)) == pixels(settings.apply(edge, std::nullopt, 1)));
|
||||
QVERIFY(pixels(settings.apply(edge, std::nullopt, -2)) == pixels(settings.apply(edge, std::nullopt, 1)));
|
||||
QVERIFY(pixels(settings.apply(edge, std::nullopt, 0.25)) != pixels(settings.apply(edge, std::nullopt, 1)));
|
||||
CameraRawSettings clear;
|
||||
clear.clarity = 100;
|
||||
QVERIFY(pixels(clear.apply(edge, std::nullopt, 0.25)) == pixels(clear.apply(edge, std::nullopt, 1)));
|
||||
// Grain's units read the scale: a negative one is one.
|
||||
CameraRawSettings grainy;
|
||||
grainy.grainAmount = 60;
|
||||
|
||||
@@ -11,6 +11,7 @@ private slots:
|
||||
void theTablesDecodeAsWritten();
|
||||
void aStageBlendsTheTablesAroundItsValue();
|
||||
void eachSliderPicksItsOwnTables();
|
||||
void theAdaptiveSlidersBlendAcrossBrightness();
|
||||
void neutralizeFindsTheGridsGrayest();
|
||||
void identitySlidersComposeNothing();
|
||||
};
|
||||
@@ -32,14 +33,16 @@ int indexOf(const uint8_t *table)
|
||||
void CameraRawTablesTests::theTablesDecodeAsWritten()
|
||||
{
|
||||
const std::vector<uint8_t> &tables = CameraRawTables::tables();
|
||||
QCOMPARE(tables.size(), size_t(147) * 17 * 17 * 17 * 3);
|
||||
QCOMPARE(tables.size(), size_t(285) * 17 * 17 * 17 * 3);
|
||||
quint64 hash = 0xcbf29ce484222325ULL;
|
||||
for (const uint8_t byte : tables)
|
||||
hash = (hash ^ byte) * 0x100000001b3ULL;
|
||||
QCOMPARE(hash, quint64(0x6a9f829e703f2df6ULL));
|
||||
QCOMPARE(hash, quint64(0x770d674136320424ULL));
|
||||
QCOMPARE(std::vector<int>(entry(40, 2456), entry(40, 2456) + 3), (std::vector<int>{128, 128, 128}));
|
||||
QCOMPARE(std::vector<int>(entry(81, 100), entry(81, 100) + 3), (std::vector<int>{0, 4, 32}));
|
||||
QCOMPARE(std::vector<int>(entry(146, 4912), entry(146, 4912) + 3), (std::vector<int>{255, 255, 255}));
|
||||
QCOMPARE(std::vector<int>(entry(200, 2456), entry(200, 2456) + 3), (std::vector<int>{172, 172, 172}));
|
||||
QCOMPARE(std::vector<int>(entry(284, 100), entry(284, 100) + 3), (std::vector<int>{70, 108, 255}));
|
||||
}
|
||||
|
||||
void CameraRawTablesTests::aStageBlendsTheTablesAroundItsValue()
|
||||
@@ -64,29 +67,62 @@ void CameraRawTablesTests::eachSliderPicksItsOwnTables()
|
||||
CameraRawSettings settings;
|
||||
settings.exposure = 1.25;
|
||||
settings.temperature = 30;
|
||||
settings.contrast = -100;
|
||||
settings.whites = 100;
|
||||
settings.blacks = 12.5;
|
||||
settings.saturation = -62.5;
|
||||
settings.vibrance = 80;
|
||||
const CameraRawTables::Stages stages = CameraRawTables::stages(settings);
|
||||
QCOMPARE(stages.before.size(), size_t(3));
|
||||
QCOMPARE(stages.after.size(), size_t(4));
|
||||
const std::vector<CameraRawStage> stages = CameraRawTables::stages(settings, {});
|
||||
QCOMPARE(stages.size(), size_t(6));
|
||||
const auto pair = [](const CameraRawStage &stage) {
|
||||
return std::vector<double>{double(indexOf(stage.table[0])), double(indexOf(stage.table[1])), stage.weight[0], stage.weight[1]};
|
||||
};
|
||||
QCOMPARE(pair(stages.before[0]), (std::vector<double>{93, 94, 0.5, 0.5}));
|
||||
QCOMPARE(indexOf(stages.before[1].table[0]), 5 * 9 + 4);
|
||||
QCOMPARE(pair(stages.before[2]), (std::vector<double>{102, 103, 1, 0}));
|
||||
QCOMPARE(pair(stages.after[0]), (std::vector<double>{118, 119, 0, 1}));
|
||||
QCOMPARE(pair(stages.after[1]), (std::vector<double>{124, 125, 0.5, 0.5}));
|
||||
QCOMPARE(pair(stages.after[2]), (std::vector<double>{130, 131, 0.5, 0.5}));
|
||||
QVERIFY(indexOf(stages.after[3].table[0]) == 145 && std::abs(stages.after[3].weight[1] - 0.2f) < 1e-6);
|
||||
QCOMPARE(pair(stages[0]), (std::vector<double>{93, 94, 0.5, 0.5}));
|
||||
QCOMPARE(indexOf(stages[1].table[0]), 5 * 9 + 4);
|
||||
QCOMPARE(pair(stages[2]), (std::vector<double>{109, 110, 0, 1}));
|
||||
QCOMPARE(pair(stages[3]), (std::vector<double>{115, 116, 0.5, 0.5}));
|
||||
QCOMPARE(pair(stages[4]), (std::vector<double>{121, 122, 0.5, 0.5}));
|
||||
QVERIFY(indexOf(stages[5].table[0]) == 136 && std::abs(stages[5].weight[1] - 0.2f) < 1e-6);
|
||||
// Tint alone still makes the white balance stage.
|
||||
CameraRawSettings tint;
|
||||
tint.tint = -25;
|
||||
const CameraRawTables::Stages tinted = CameraRawTables::stages(tint);
|
||||
QVERIFY(tinted.before.size() == 1 && tinted.after.empty() && indexOf(tinted.before[0].table[0]) == 4 * 9 + 3);
|
||||
const std::vector<CameraRawStage> tinted = CameraRawTables::stages(tint, {});
|
||||
QVERIFY(tinted.size() == 1 && indexOf(tinted[0].table[0]) == 4 * 9 + 3);
|
||||
}
|
||||
|
||||
// Seven brightnesses down, seven values across, each read alone.
|
||||
void CameraRawTablesTests::theAdaptiveSlidersBlendAcrossBrightness()
|
||||
{
|
||||
const auto four = [](const CameraRawStage &stage) {
|
||||
return std::vector<double>{double(indexOf(stage.table[0])), double(indexOf(stage.table[1])), double(indexOf(stage.table[2])),
|
||||
double(indexOf(stage.table[3])), stage.weight[0], stage.weight[1], stage.weight[2], stage.weight[3]};
|
||||
};
|
||||
CameraRawSettings settings;
|
||||
settings.contrast = 10;
|
||||
settings.highlights = -100;
|
||||
settings.shadows = 100;
|
||||
settings.saturation = 25;
|
||||
const std::vector<CameraRawStage> stages = CameraRawTables::stages(settings, {120, 250, 30});
|
||||
QCOMPARE(stages.size(), size_t(4));
|
||||
QCOMPARE(four(stages[0]), (std::vector<double>{155, 156, 162, 163, 0.23076923191547394, 0.1538461595773697, 0.3692307770252228, 0.2461538463830948}));
|
||||
QCOMPARE(four(stages[1]), (std::vector<double>{187, 188, 194, 195, 1, 0, 0, 0}));
|
||||
QCOMPARE(four(stages[2]), (std::vector<double>{276, 277, 283, 284, 0, 0, 0, 1}));
|
||||
QCOMPARE(indexOf(stages[3].table[0]), 125);
|
||||
// Contrast reads the brightest channel, Highlights the log-average.
|
||||
settings = CameraRawSettings();
|
||||
settings.contrast = -37.5;
|
||||
settings.highlights = 50;
|
||||
const std::vector<CameraRawStage> low = CameraRawTables::stages(settings, {53, 0, 224});
|
||||
QCOMPARE(four(low[0]), (std::vector<double>{139, 140, 146, 147, 0.5, 0.5, 0, 0}));
|
||||
QCOMPARE(four(low[1]), (std::vector<double>{226, 227, 233, 234, 0, 0, 0, 1}));
|
||||
// On a measured point the lower pair takes it whole.
|
||||
settings = CameraRawSettings();
|
||||
settings.shadows = 25;
|
||||
const std::vector<CameraRawStage> on = CameraRawTables::stages(settings, {0, 104, 0});
|
||||
QCOMPARE(four(on[0]), (std::vector<double>{246, 247, 253, 254, 0, 0, 0, 1}));
|
||||
// A mid-gray picture reads 128 by every measure.
|
||||
const QImage mid = gray(8, 8);
|
||||
const CameraRawTables::Brightness read = CameraRawTables::brightness(mid.constBits(), 8, 8, mid.bytesPerLine());
|
||||
QVERIFY(std::abs(read.brightest - 128) < 0.01 && std::abs(read.luminance - 128) < 0.01 && std::abs(read.logBrightest - 128) < 0.01);
|
||||
}
|
||||
|
||||
void CameraRawTablesTests::neutralizeFindsTheGridsGrayest()
|
||||
@@ -118,11 +154,11 @@ void CameraRawTablesTests::neutralizeFindsTheGridsGrayest()
|
||||
|
||||
void CameraRawTablesTests::identitySlidersComposeNothing()
|
||||
{
|
||||
const CameraRawTables::Stages none = CameraRawTables::stages(CameraRawSettings());
|
||||
QVERIFY(none.before.empty() && none.after.empty() && CameraRawTables::compose(none.before).empty());
|
||||
const std::vector<CameraRawStage> none = CameraRawTables::stages(CameraRawSettings(), {});
|
||||
QVERIFY(none.empty() && CameraRawTables::compose(none).empty());
|
||||
CameraRawSettings exposure;
|
||||
exposure.exposure = 0.5;
|
||||
const std::vector<float> composed = CameraRawTables::compose(CameraRawTables::stages(exposure).before);
|
||||
const std::vector<float> composed = CameraRawTables::compose(CameraRawTables::stages(exposure, {}));
|
||||
QCOMPARE(composed.size(), size_t(33) * 33 * 33 * 3);
|
||||
// The corners are its table's own black and white.
|
||||
QVERIFY(composed[0] == entry(92, 0)[0] / 255.0f && composed.back() == entry(92, 4912)[2] / 255.0f);
|
||||
@@ -131,7 +167,7 @@ void CameraRawTablesTests::identitySlidersComposeNothing()
|
||||
three.exposure = 1;
|
||||
three.temperature = 40;
|
||||
three.contrast = 50;
|
||||
const std::vector<float> run = CameraRawTables::compose(CameraRawTables::stages(three).before);
|
||||
const std::vector<float> run = CameraRawTables::compose(CameraRawTables::stages(three, {}));
|
||||
const auto at = [&](int r, int g, int b) {
|
||||
const size_t index = ((size_t(r) * 33 + g) * 33 + b) * 3;
|
||||
return std::array<float, 3>{run[index], run[index + 1], run[index + 2]};
|
||||
@@ -139,8 +175,8 @@ void CameraRawTablesTests::identitySlidersComposeNothing()
|
||||
const auto near = [](std::array<float, 3> got, std::array<float, 3> expected) {
|
||||
return std::abs(got[0] - expected[0]) < 1e-6f && std::abs(got[1] - expected[1]) < 1e-6f && std::abs(got[2] - expected[2]) < 1e-6f;
|
||||
};
|
||||
QVERIFY(near(at(16, 16, 16), {0.94074458f, 0.85085034f, 0.72421813f}));
|
||||
QVERIFY(near(at(16, 4, 28), {0.85322261f, 0.50834316f, 0.98791242f}));
|
||||
QVERIFY(near(at(16, 16, 16), {0.94272572f, 0.86208665f, 0.74603087f}));
|
||||
QVERIFY(near(at(16, 4, 28), {0.86772656f, 0.55830115f, 0.98769760f}));
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(CameraRawTablesTests)
|
||||
|
||||
@@ -63,7 +63,8 @@ void CameraRawTests::tonalSlidersMoveTheEndTheyName()
|
||||
CameraRawSettings settings;
|
||||
settings.highlights = -100;
|
||||
const auto recovered = pixels(settings.apply(brightAndMid));
|
||||
QVERIFY(recovered[0][0] < 200 && std::abs(recovered[1][0] - 128) <= 2);
|
||||
// Photoshop: 230 to 209, mid gray kept.
|
||||
QVERIFY(recovered[0][0] < 222 && std::abs(recovered[1][0] - 128) <= 4);
|
||||
settings = CameraRawSettings();
|
||||
settings.whites = 100;
|
||||
const auto clipped = pixels(settings.apply(brightAndMid));
|
||||
@@ -74,7 +75,8 @@ void CameraRawTests::tonalSlidersMoveTheEndTheyName()
|
||||
settings = CameraRawSettings();
|
||||
settings.shadows = 100;
|
||||
const auto opened = pixels(settings.apply(darkAndMid));
|
||||
QVERIFY(opened[0][0] > 50 && std::abs(opened[1][0] - 128) <= 2);
|
||||
// Photoshop: 20 to 33, mid gray kept.
|
||||
QVERIFY(opened[0][0] > 22 && std::abs(opened[1][0] - 128) <= 6);
|
||||
settings = CameraRawSettings();
|
||||
settings.blacks = -100;
|
||||
const auto crushed = pixels(settings.apply(darkAndMid));
|
||||
@@ -172,15 +174,25 @@ void CameraRawTests::textureAndClaritySharpenAnEdgeAndLeaveAFlatField()
|
||||
|
||||
void CameraRawTests::dehazeDeepensOrLiftsAndKeepsAlpha()
|
||||
{
|
||||
const QImage dark = image(4, 4, 30 / 255.0, 30 / 255.0, 30 / 255.0), pale = image(4, 4, 180 / 255.0, 150 / 255.0, 150 / 255.0);
|
||||
// A shadow under a pale sky; one colour, no haze.
|
||||
QImage skyAndShadow = BrushRaster::context(10, 10, false);
|
||||
{
|
||||
QPainter painter(&skyAndShadow);
|
||||
painter.fillRect(QRect(0, 0, 10, 5), QColor(200, 195, 190));
|
||||
painter.fillRect(QRect(0, 5, 10, 5), QColor(30, 30, 30));
|
||||
}
|
||||
const int shadow = 5 * 10;
|
||||
QCOMPARE(pixels(skyAndShadow)[shadow][0], 30);
|
||||
CameraRawSettings settings;
|
||||
settings.dehaze = 100;
|
||||
QVERIFY(pixels(settings.apply(dark))[0][0] < 30);
|
||||
const std::array<int, 4> paleBefore = pixels(pale)[0];
|
||||
QVERIFY(chroma(pixels(settings.apply(pale))[0]) > chroma(paleBefore));
|
||||
QVERIFY(pixels(settings.apply(skyAndShadow))[shadow][0] < 30);
|
||||
settings.dehaze = -100;
|
||||
QVERIFY(pixels(settings.apply(dark))[0][0] > 30);
|
||||
QVERIFY(chroma(pixels(settings.apply(pale))[0]) < chroma(paleBefore));
|
||||
QVERIFY(pixels(settings.apply(skyAndShadow))[shadow][0] > 30);
|
||||
const QImage pale = image(4, 4, 180 / 255.0, 150 / 255.0, 150 / 255.0);
|
||||
for (const double amount : {100.0, -100.0}) {
|
||||
settings.dehaze = amount;
|
||||
QVERIFY((pixels(settings.apply(pale))[0] == std::array{180, 150, 150, 255}));
|
||||
}
|
||||
const QImage translucent = image(4, 4, 30 / 255.0, 30 / 255.0, 30 / 255.0, 0.5);
|
||||
settings.dehaze = 100;
|
||||
QCOMPARE(pixels(settings.apply(translucent))[0][3], pixels(translucent)[0][3]);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -66,7 +66,7 @@ class CameraRawWiringTests : public QObject {
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void aClipViewShowsOnAnUntouchedGrade();
|
||||
void theTablesRunAroundHighlightsAndShadows();
|
||||
void theTableReadsThePicturesBrightness();
|
||||
void autoAveragesLinearLight();
|
||||
void eachEyeClearsEveryFieldOfItsGroup();
|
||||
void effectsReachTheKernelInOrder();
|
||||
@@ -85,13 +85,13 @@ void CameraRawWiringTests::aClipViewShowsOnAnUntouchedGrade()
|
||||
const QImage picture = noise();
|
||||
const QImage clipped = CameraRawSettings().apply(picture, CameraRawClipping::highlights);
|
||||
const QImage direct = kernel(picture, [](uchar *bytes, size_t w, size_t h, size_t s) {
|
||||
adjust_camera_raw(bytes, w, h, s, nullptr, nullptr, CameraRawTables::grid, 0, 0, int(CameraRawClipping::highlights));
|
||||
adjust_camera_raw(bytes, w, h, s, nullptr, CameraRawTables::grid, int(CameraRawClipping::highlights));
|
||||
});
|
||||
QVERIFY(pixels(clipped) == pixels(direct) && pixels(clipped) != pixels(picture));
|
||||
}
|
||||
|
||||
// Exposure, balance and Contrast first; Whites to Vibrance after.
|
||||
void CameraRawWiringTests::theTablesRunAroundHighlightsAndShadows()
|
||||
// One composed table, its adaptive stages read from the picture.
|
||||
void CameraRawWiringTests::theTableReadsThePicturesBrightness()
|
||||
{
|
||||
const QImage picture = noise();
|
||||
CameraRawSettings settings;
|
||||
@@ -101,15 +101,13 @@ void CameraRawWiringTests::theTablesRunAroundHighlightsAndShadows()
|
||||
settings.shadows = 60;
|
||||
settings.whites = -50;
|
||||
settings.saturation = 30;
|
||||
const CameraRawTables::Stages stages = CameraRawTables::stages(settings);
|
||||
const std::vector<float> before = CameraRawTables::compose(stages.before), after = CameraRawTables::compose(stages.after);
|
||||
const QImage direct = kernel(picture, [&](uchar *bytes, size_t w, size_t h, size_t s) {
|
||||
adjust_camera_raw(bytes, w, h, s, before.data(), after.data(), CameraRawTables::grid, -80, 60, 0);
|
||||
});
|
||||
const QImage swapped = kernel(picture, [&](uchar *bytes, size_t w, size_t h, size_t s) {
|
||||
adjust_camera_raw(bytes, w, h, s, after.data(), before.data(), CameraRawTables::grid, -80, 60, 0);
|
||||
});
|
||||
QVERIFY(pixels(settings.apply(picture)) == pixels(direct) && pixels(direct) != pixels(swapped));
|
||||
const CameraRawTables::Brightness read = CameraRawTables::brightness(picture.constBits(), picture.width(), picture.height(), picture.bytesPerLine());
|
||||
QVERIFY(std::abs(read.brightest - 128) > 5);
|
||||
const auto graded = [&](const CameraRawTables::Brightness &brightness) {
|
||||
const std::vector<float> table = CameraRawTables::compose(CameraRawTables::stages(settings, brightness));
|
||||
return kernel(picture, [&](uchar *bytes, size_t w, size_t h, size_t s) { adjust_camera_raw(bytes, w, h, s, table.data(), CameraRawTables::grid, 0); });
|
||||
};
|
||||
QVERIFY(pixels(settings.apply(picture)) == pixels(graded(read)) && pixels(graded(read)) != pixels(graded({})));
|
||||
}
|
||||
|
||||
void CameraRawWiringTests::autoAveragesLinearLight()
|
||||
|
||||
Reference in new issue
Block a user