Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
region.h
Go to the documentation of this file.
1/*
2 This file is part of Ansel,
3 Copyright (C) 2026 Aurélien PIERRE.
4
5 Ansel is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 Ansel is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with darktable. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21// Per-region gather/composite + the region reconstruction driver (CPU + OpenCL).
22// Public API of this highlights harmonic-transposition module (a compiled TU). Include
23// this header to call into the module; internals are static in the .c. See common.h.
24
25#include "common/opencl.h"
27#include <stdint.h>
28
29void _region_guided_filter(float *const restrict interp, const float *const restrict mask,
30 const float *const restrict depth, const int width, const _hl_region_t *const region,
31 const dt_dev_pixelpipe_t *pipe, const float solid_color, const int max_iter,
32 const float noise_level);
33
34#if defined(HAVE_OPENCL) && DT_HL_COEFF_FIELD && DT_HL_SPARSE_SOLVE && (DT_HL_ANISO_SOLVER == 2)
35// CPU offload of one region inside the GPU middle: gather the padded window to host, run the
36// production CPU reconstruction on it (coordinates translated to the window), scatter back.
37// Sequentially consistent with the device regions: the blocking readback drains the in-order
38// queue, and the unpack rewrites the exact window the CPU read.
39//
40// MATHS BRIDGE -- runs the full CPU _region_guided_filter on this window, so ALL stages including
41// the Step-7 all-clip core (biharmonic dome x screened-Poisson chroma) and the Step-8 anisotropic
42// div(D grad r)=0 chroma coherence are the CPU versions annotated in the CPU stages.
43// Used for regions too small for the ~1000-launch GPU path to pay off; no maths of its own.
44cl_int _region_cpu_offload_cl(const int devid, void *gd_void, cl_mem interp, cl_mem mask, cl_mem depth,
45 const int width, const _hl_region_t *const region, const dt_dev_pixelpipe_t *pipe,
46 const float solid_color, const int max_iter, const float noise_level);
47
48// MATHS/PIPELINE BRIDGE -- device-resident per-region reconstruction, the GPU twin of the CPU
49// _region_guided_filter (article §"The algorithm", steps 3-8, and §"The OpenCL pipe": a big region
50// stays resident on the device for its whole rebuild). Same step composition as the CPU header, each
51// step a device stage minimizing the same energy:
52// 3 colour-line coefficient field _cf_stage_cl (E_affine per pixel + E_transport diffusion)
53// 4 HF refit _hf_stage_cl (detail-band re-fit on the colour line)
54// 5-6 floors + gated self-dome _selfdome_stage_cl (E_bihar self-dome, depth-gated by We = R^4)
55// 7 all-clip luminance dome+chroma _joint_core_stage_cl (E_bihar dome x E_chrominance screened Poisson)
56// 8 anisotropic chroma coherence _aniso_stage_cl (E_chrominance div(D grad r)=0)
57// The stage parameters (cf_sigma = clip(R/6, 8, 64), deep channel, shared dome grid ds_shared) come from
58// ONE on-device reduction (kernel_hl_region_stats) so the queue never drains mid-region; only the 8x256
59// reduction partials cross the bus. The reconstructed clipped channels are scattered back on device.
60cl_int _region_guided_filter_cl(const int devid, void *gd_void, cl_mem interp, cl_mem mask, cl_mem depth,
61 const int width, const _hl_region_t *const region, const dt_dev_pixelpipe_t *pipe,
62 const float solid_color);
63#endif
int width
Definition bilateral.h:1
void _region_guided_filter(float *const restrict interp, const float *const restrict mask, const float *const restrict depth, const int width, const _hl_region_t *const region, const dt_dev_pixelpipe_t *pipe, const float solid_color, const int max_iter, const float noise_level)
Definition region.c:149