From dafd028fff0d794972e4fbc1dee40d84185d077d Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Sat, 7 Mar 2026 22:33:44 -0600 Subject: [PATCH] Implemented a conservative saturation approximation in Saturation.cpp: - Replaced per-pixel sqrt(...) with: - Rec.601 fixed-point weighted squared intensity: 77*R*R + 150*G*G + 29*B*B (scaled by >> 8) - Lookup in a precomputed sqrt_lut[0..65025] - This follows standard luma weighting conventions and avoids fast-inverse-sqrt style hacks that can cause visible instability. --- src/effects/Saturation.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/effects/Saturation.cpp b/src/effects/Saturation.cpp index 6e31e65a..a1028425 100644 --- a/src/effects/Saturation.cpp +++ b/src/effects/Saturation.cpp @@ -130,6 +130,14 @@ std::shared_ptr Saturation::GetFrame(std::shared_ptr sqrt_lut = [] { + std::array lut{}; + for (int i = 0; i <= 65025; ++i) + lut[i] = std::sqrt(static_cast(i)); + return lut; + }(); // Loop through pixels unsigned char *pixels = reinterpret_cast(frame_image->bits()); @@ -148,10 +156,10 @@ std::shared_ptr Saturation::GetFrame(std::shared_ptr> 8; + const float p = sqrt_lut[weighted_sq]; // Adjust common saturation R = clamp_i(static_cast(p + (R - p) * saturation_value));