CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
operation_brightness.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_brightness,
18 const Halide::Var& x,
19 const Halide::Var& y,
20 const Halide::Var& c)
21{
22 Halide::Func brightness_func("brightness_op");
23
24 // Safety: Clamp the input parameter to the operation's defined valid range.
25 // This ensures robustness even if the cache passes an unexpected value.
26 Halide::Expr safe_brightness = Halide::clamp(
27 param_brightness,
30 );
31
32 // Additive brightness adjustment
33 brightness_func(x, y, c) = Halide::select(
34 c == 0,
35 Halide::clamp(input(x, y, c) + safe_brightness, 0.0f, 1.0f),
36 input(x, y, c) // Alpha unchanged
37 );
38
39 return brightness_func;
40}
41
42// ============================================================================
43// IOperationFusionLogic Implementation
44// ============================================================================
45
47 const Halide::Func& input_func,
48 const Halide::Var& x,
49 const Halide::Var& y,
50 const Halide::Var& c,
51 const Halide::Param<float>& param
52 ) const
53{
54 // to allow dynamic updates via the cache without recompilation.
55 // Halide's optimizer (Constant Folding) will handle the math if the value is 0.
56 spdlog::trace("OperationBrightness::appendToFusedPipeline: Fusing with Halide Param (In-Graph Clamped)");
57 return applyBrightnessAdjustment(input_func, param, x, y, c);
58}
59
60} // 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_BRIGHTNESS_VALUE
Maximum allowed brightness value. Defined by OperationRanges::getBrightnessMaxValue().
static constexpr float MIN_BRIGHTNESS_VALUE
Minimum allowed brightness value. Defined by OperationRanges::getBrightnessMinValue().
Halide::Func applyBrightnessAdjustment(const InputType &input, const Halide::Param< float > &param_brightness, const Halide::Var &x, const Halide::Var &y, const Halide::Var &c)
Concrete implementation of Brightness adjustment.
CaptureMoment — footer