CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
operation_highlights.cpp
Go to the documentation of this file.
1
9
10#include <spdlog/spdlog.h>
11
13
14template<typename InputType>
16 const InputType& input,
17 const Halide::Param<float>& param_highlights,
18 const Halide::Var& x,
19 const Halide::Var& y,
20 const Halide::Var& c)
21{
22 Halide::Func highlights_func("highlights_op");
23
24 // 1. In Oklab, channel 0 IS the perceptual luminance. No RGB luminance formula needed.
25 Halide::Expr L = input(x, y, 0);
26
27 // 2. Create a smooth mask (Smoothstep equivalent)
28 // Normalize L to a 0.0 - 1.0 range based on the 0.7 to 1.0 thresholds
29 Halide::Expr t = clamp((L - 0.7f) / (1.0f - 0.7f), 0.0f, 1.0f);
30
31 // Apply the smoothstep polynomial curve: 3t^2 - 2t^3
32 // This prevents hard edges/banding in the highlights roll-off.
33 Halide::Expr mask = t * t * (3.0f - 2.0f * t);
34
35 // 3. Clamp the input parameter to the operation's defined valid range.
36 Halide::Expr safe_val = clamp(
37 param_highlights,
40 );
41
42 // 4. Apply adjustment only to channel 0 (L)
43 highlights_func(x, y, c) = select(
44 c == 0,
45 L + safe_val * mask, // Add value weighted by the smooth mask
46 input(x, y, c) // a, b, and Alpha channels remain untouched
47 );
48
49 return highlights_func;
50}
51
52// ============================================================================
53// IOperationFusionLogic Implementation
54// ============================================================================
55
57 const Halide::Func& input_func,
58 const Halide::Var& x,
59 const Halide::Var& y,
60 const Halide::Var& c,
61 const Halide::Param<float>& param
62 ) const
63{
64const Halide::Param<float>& param_highlights = param;
65
66 // Halide's optimizer will simplify the math if the highlights adjustment is effectively zero.
67 spdlog::trace("OperationHighlights::appendToFusedPipeline: Fusing with Halide Param (In-Graph Clamped)");
68 return applyHighlightsAdjustment(input_func, param_highlights, x, y, c);
69}
70
71} // namespace CaptureMoment::Core::Operations
static constexpr float MAX_HIGHLIGHTS_VALUE
Maximum allowed highlights value. Defined by OperationRanges::getHighlightsMaxValue().
static constexpr float MIN_HIGHLIGHTS_VALUE
Minimum allowed highlights value. Defined by OperationRanges::getHighlightsMinValue().
Halide::Func appendToFusedPipeline(const Halide::Func &input_func, const Halide::Var &x, const Halide::Var &y, const Halide::Var &c, const Halide::Param< float > &param) const override
Appends this operation's logic to a fused Halide pipeline. This method is used by the PipelineBuilder...
Halide::Func applyHighlightsAdjustment(const InputType &input, const Halide::Param< float > &param_highlights, const Halide::Var &x, const Halide::Var &y, const Halide::Var &c)
Concrete implementation of Highlights adjustment.
CaptureMoment — footer