Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
core.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// Self-dome fallback and all-clip joint core stages (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 _selfdome(_hl_region_ctx_t *const ctx);
30
31void _joint_core(_hl_region_ctx_t *const ctx);
32
33#if defined(HAVE_OPENCL) && DT_HL_SPARSE_SOLVE
34// The hue-coupled self-dome stage on the GPU: soft clip floor (rounded lower bound at the
35// clip level), ONE shared biharmonic brightness dome over the union hole, harmonically
36// filled chromaticity ratios (each channel divided by the brightness sum), a depth-gated
37// blend (dome takes over where the colour-line fit quality is low AND the pixel is shallow),
38// then a hard clip-floor re-assert. est/vld/bsc/clip0/dep are device buffers (working pixels,
39// validity mask, fit quality, clip thresholds, distance-to-valid depth).
40// Mirrors the DT_HL_SELF_DOME block of _region_guided_filter (CPU): any change here must be
41// mirrored there and re-validated with the HL_DOMECL_TEST self-test
42// (_selfdome_stage_cl_selftest).
43//
44// MATHS BRIDGE -- article "The algorithm" steps 5-6. Step 5: soft saturation floor (rounded lower
45// bound at c0). Step 6: hue-coupled self-dome -- ONE shared biharmonic brightness dome (Delta^2 L_sum
46// = 0, hl_soft_floor->hl_lsb_hole->_biharmonic_dome_cl) times harmonically-filled chromaticity ratios
47// r_c = est_c/L_sum, blended in by the depth-gated keep weight
48// keep = 1 - dome_fraction, dome_fraction = (1 - S_{0.4}^{0.85}(R^2)) * exp(-(delta/1.5 sigma)^2)
49// (hl_dome_blend), then a hard clip-floor re-assert. The hue coupling (dome_c = L_dome * r_c) is what
50// stops three per-channel domes drifting the hue -- the failure that kept the per-channel ancestor off.
51cl_int _selfdome_stage_cl(const int devid, void *gd_void, cl_mem estimate, cl_mem valid, cl_mem model_quality,
52 cl_mem clip0, cl_mem depth, const int region_w, const int region_h, const float cf_sigma,
53 const float reg_radius, const int ds_shared, const dt_dev_pixelpipe_t *pipe);
54
55// All-clipped joint core on the device (pixels where NO channel survived, so no guide
56// exists): shared biharmonic brightness dome (floored at the saturated sum) x
57// screened-Poisson diffused chromaticity (diffusion plus a pull toward the mean valid
58// colour, strength set by the "inpaint a flat colour" user slider) -- ONE host symbolic
59// analysis + GPU numeric factorization serves the three channels, whose right-hand sides are
60// assembled on the device (hl_pde_rhs) so no full-res float plane crosses the bus --
61// composed through the gaussian-feathered core mask. The only downloads are the full-res
62// hole MASK (bytes; the sparse symbolic analysis needs it anyway) and the per-workgroup
63// mean-chromaticity partial sums.
64// Mirrors the all-clip joint-core block of _region_guided_filter (CPU, DT_HL_COEFF_FIELD):
65// any change here must be mirrored there and re-validated with the HL_CORECL_TEST self-test
66// (_joint_core_stage_cl_selftest).
67//
68// MATHS BRIDGE -- Step 7 all-clip core (article §"Filling holes with no survivor"): magnitude =
69// shared biharmonic dome L_dome (Delta^2 L_sum = 0, floored at sum_c clip0_c), chrominance =
70// screened-Poisson rim fill r_c ((lambda_solid*I - Delta) r = lambda_solid*r_target) with
71// r_target = mean valid chromaticity, solved per channel by ONE shared Cholesky factor (direct) or
72// the on-device CG (large cores). Recombine core_c = L_dome * (r_c / sum_j r_j), composed through a
73// gaussian-feathered core mask (no hard hand-off at the core rim).
74cl_int _joint_core_stage_cl(const int devid, void *gd_void, cl_mem estimate, cl_mem valid, cl_mem clip0,
75 const int region_w, const int region_h, const float solid_color,
76 const float reg_radius, const int extent, const dt_dev_pixelpipe_t *pipe);
77
78#endif
void _joint_core(_hl_region_ctx_t *const ctx)
Definition core.c:151
void _selfdome(_hl_region_ctx_t *const ctx)
Definition core.c:37