CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
operation_blacks.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_blacks,
18 const Halide::Var& x,
19 const Halide::Var& y,
20 const Halide::Var& c)
21{
22 Halide::Func blacks_func("blacks_op");
23
24 // 1. In Oklab, channel 0 IS the perceptual luminance. No RGB formula needed.
25 Halide::Expr L = input(x, y, 0);
26
27 // 2. Create a smooth mask targeting the shadow range (0.0 to 0.3)
28 // Note: We invert the subtraction compared to highlights because we want
29 // full effect at L=0.0 and no effect at L=0.3.
30 Halide::Expr t = clamp((0.3f - L) / (0.3f - 0.0f), 0.0f, 1.0f);
31
32 // Apply the smoothstep polynomial curve: 3t^2 - 2t^3
33 // This prevents harsh transitions in the midtones.
34 Halide::Expr mask = t * t * (3.0f - 2.0f * t);
35
36 // 3. Clamp the input parameter to the operation's defined valid range.
37 Halide::Expr safe_val = clamp(
38 param_blacks,
41 );
42
43 // 4. Apply adjustment only to channel 0 (L)
44 // NO CLAMP here to avoid hue shifts in the shadows during oklab_to_rgb conversion.
45 blacks_func(x, y, c) = select(
46 c == 0,
47 L + safe_val * mask,
48 input(x, y, c) // a, b, and Alpha channels remain untouched
49 );
50
51 return blacks_func;
52}
53
54// ============================================================================
55// IOperationFusionLogic Implementation
56// ============================================================================
57
59 const Halide::Func& input_func,
60 const Halide::Var& x,
61 const Halide::Var& y,
62 const Halide::Var& c,
63 const Halide::Param<float>& param
64 ) const
65{
66 spdlog::trace("OperationBlacks::appendToFusedPipeline: Fusing with Halide Param");
67 return applyBlacksAdjustment(input_func, param, x, y, c);
68}
69
70} // namespace CaptureMoment::Core::Operations
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...
static constexpr float MAX_BLACKS_VALUE
Maximum allowed blacks value. Defined by OperationRanges::getBlacksMaxValue().
static constexpr float MIN_BLACKS_VALUE
Minimum allowed blacks value. Defined by OperationRanges::getBlacksMinValue().
Halide::Func applyBlacksAdjustment(const InputType &input, const Halide::Param< float > &param_blacks, const Halide::Var &x, const Halide::Var &y, const Halide::Var &c)
Concrete implementation of Blacks adjustment.
CaptureMoment — footer