CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
operation_pipeline_executor_cpu.cpp
Go to the documentation of this file.
1
11
12#include <spdlog/spdlog.h>
13
15
17{
18 Halide::Var x("x"), y("y"), c("c");
19
20 // 1. Chunky input from Halide::ImageParam (x,y,c) -> (x,y,c)
21 Halide::Func chunky_input("chunky_input");
22 chunky_input(x, y, c) = m_input(x, y, c);
23
24 // ====================================================================
25 // CPU : BOUNDARY TRANSPOSE (Chunky -> Logique Planar)
26 // ====================================================================
27 Halide::Func planar_input("planar_input");
28 planar_input(c, y, x) = chunky_input(x, y, c); //Transpose for planar logic (c,y,x) for math operations
29
30 Halide::Func cpu_ready_input("cpu_ready_input");
31 cpu_ready_input(x, y, c) = planar_input(c, y, x); // Transpose back to (x,y,c) for Halide processing
32
33 // ====================================================================
34 // CPU : OKLAB COLOR SPACE + OPERATIONS
35 // ====================================================================
36 Halide::Func oklab_image { ColorSpace::rgbToOklab(cpu_ready_input, x, y, c) };
37 Halide::Func ops_result { applyOperations(oklab_image, x, y, c) }; // Apply all operations in the pipeline to the Oklab image
38 Halide::Func rgb_planar { ColorSpace::oklabToRgb(ops_result, x, y, c) };
39
40 // ====================================================================
41 // CPU : BOUNDARY TRANSPOSE (Logique Planar -> Chunky)
42 // ====================================================================
43 Halide::Func planar_output("planar_output");
44 planar_output(c, y, x) = rgb_planar(x, y, c);
45
46 Halide::Func final_chunky_output("final_chunky_output");
47 final_chunky_output(x, y, c) = planar_output(c, y, x);
48
49 // ====================================================================
50 // SCHEDULING & COMPILATION CPU
51 // ====================================================================
52 final_chunky_output.output_buffer().dim(0).set_stride(4);
53 final_chunky_output.output_buffer().dim(2).set_stride(1);
54
55 Halide::Target target { Config::AppConfig::getHalideTarget() };
56 applyScheduling(final_chunky_output, x, y, c);
57
58 try {
59 final_chunky_output.compile_jit(target);
60 m_pipeline = Halide::Pipeline(final_chunky_output);
61 m_chain_built = true;
62 spdlog::info("[OperationPipelineExecutorCPU::buildOperationChain]: Pipeline compiled (Chunky->Planar->Oklab->Ops->Planar->Chunky).");
63 } catch (const Halide::CompileError& e) {
64 spdlog::critical("[OperationPipelineExecutorCPU::buildOperationChain]: {}", e.what());
65 m_chain_built = false;
66 }
67}
68
69void OperationPipelineExecutorCPU::applyScheduling(Halide::Func& pipeline, Halide::Var& x, Halide::Var& y, Halide::Var& c) const
70{
71 Halide::Var yo, yi;
72 pipeline.bound(c, 0, 4).reorder(c, x, y).split(y, yo, yi, 32).parallel(yo).unroll(c);
73 spdlog::trace("[OperationPipelineExecutorCPU::applyScheduling]: Applying CPU scheduling.");
74}
75
77{
78 auto* cpu_impl{dynamic_cast<ImageProcessing::WorkingImageCPU_Halide*>(&working_image)};
79
80 if (!cpu_impl || !cpu_impl->isHalideBufferValid() || !cpu_impl->isOriginalHalideBufferValid()) {
81 spdlog::error("[OperationPipelineExecutorCPU::execute]: Invalid Halide buffer or CPU implementation.");
82 return false;
83 }
84
85 return executeOnHalideBuffer(cpu_impl->getOriginalHalideBuffer(), cpu_impl->getHalideBuffer());
86}
87
88} // namespace CaptureMoment::Core::Pipeline
static const Halide::Target & getHalideTarget()
Gets the configured Halide Target object.
Abstract interface representing an image used as a working buffer.
Updates the internal image data from a CPU-based ImageRegion.
Halide::ImageParam m_input
The shared Halide Input Parameter.
bool execute(ImageProcessing::IWorkingImageHardware &working_image) override
Executes the compiled pipeline on a generic working image.
void buildOperationChain() override
Builds the Halide function graph based on m_operations.
bool m_chain_built
Flag indicating if the pipeline has been successfully built and compiled.
Halide::Func applyOperations(const Halide::Func &input, const Halide::Var &x, const Halide::Var &y, const Halide::Var &c)
Applies all operations to the input function.
bool executeOnHalideBuffer(Halide::Buffer< float > &input_buffer, Halide::Buffer< float > &output_buffer) override
Executes the compiled pipeline directly on a Halide buffer.
Halide::Pipeline m_pipeline
The compiled Halide pipeline object.
Halide::Func oklabToRgb(const Halide::Func &input, const Halide::Var &x, const Halide::Var &y, const Halide::Var &c)
Converts a Chunky Oklab Halide::Func back to linear RGB.
Halide::Func rgbToOklab(const Halide::Func &input, const Halide::Var &x, const Halide::Var &y, const Halide::Var &c)
Converts RGB Halide::Func to Oklab.
Declaration of OperationPipelineExecutorCPU (Fused Adjustment Pipeline).
implementation of of image working buffer on CPU using Halide for processing.
CaptureMoment — footer