Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
blur.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#ifndef DT_IOP_HIGHLIGHTS_BLUR_H
20#define DT_IOP_HIGHLIGHTS_BLUR_H
21
22// Gaussian blur helpers + per-region blur, and the OpenCL blur / device-timing runtime prelude.
23// Public API of this highlights harmonic-transposition module (a compiled TU). Include
24// this header to call into the module; internals are static in the .c. See common.h.
25
26#include "pixel/gaussian.h"
27
28#include <string.h>
29
30dt_gaussian_t *_hl_gauss_get(const int width, const int height, const int channels, const float sigma);
31
32void _hl_gauss_cache_flush(void);
33
34// Edge-aware replacement for _region_blur on the coefficient-field fit windows: a domain-transform
35// recursive filter, so the windowed moments are not transported across a silhouette. `guide` is a
36// single-channel image whose edges stop the transport; step_x/step_y are region-sized scratch.
37// See the implementation for why a per-sample photometric test cannot do this job.
38void _region_edge_blur(const float *const restrict in, float *const restrict out,
39 const float *const restrict guide, float *const restrict step_x,
40 float *const restrict step_y, const int region_w, const int region_h,
41 const float sigma_s, const float sigma_r);
42
43static inline void _region_blur(const float *const restrict in, float *const restrict out, const int region_w,
44 const int region_h, const float sigma)
45{
46 dt_gaussian_t *const gaussian = _hl_gauss_get(region_w, region_h, 4, sigma); // cached, do not free
47
48 if(!gaussian)
49 {
50 memcpy(out, in, (size_t)region_w * region_h * 4 * sizeof(float));
51 return;
52 }
53
55}
56
57#ifdef HAVE_OPENCL
58// GPU counterpart of _region_blur: the exact same Young-van-Vliet recursive gaussian, through
59// the existing dt_gaussian OpenCL implementation. in/out are 4-channel image2d of the region.
60cl_int _region_edge_blur_cl(const int devid, void *gd_void, cl_mem in_image, cl_mem out_image,
61 cl_mem guide, cl_mem data, cl_mem step_x, cl_mem step_y, const int region_w,
62 const int region_h, const float sigma_s, const float sigma_r);
63
64dt_gaussian_cl_t *_region_blur_handle(const int devid, const int region_w, const int region_h, const float sigma);
65
66// One-shot gaussian blur of a 4-channel region image on the GPU (init + blur + free).
67// Mirrors _region_blur on the CPU: any change here must be mirrored there and re-validated
68// with the HL_BLURCL_TEST self-test (_region_blur_cl_selftest).
69cl_int _region_blur_cl(const int devid, cl_mem in, cl_mem out, const int region_w, const int region_h,
70 const float sigma);
71#endif
72#endif // DT_IOP_HIGHLIGHTS_BLUR_H
float sigma_s
Definition bilateral.h:3
float sigma_r
Definition bilateral.h:3
static void _region_blur(const float *const restrict in, float *const restrict out, const int region_w, const int region_h, const float sigma)
Definition blur.h:43
void _region_edge_blur(const float *const restrict in, float *const restrict out, const float *const restrict guide, float *const restrict step_x, float *const restrict step_y, const int region_w, const int region_h, const float sigma_s, const float sigma_r)
Definition blur.c:103
cl_int _region_edge_blur_cl(const int devid, void *gd_void, cl_mem in_image, cl_mem out_image, cl_mem guide, cl_mem data, cl_mem step_x, cl_mem step_y, const int region_w, const int region_h, const float sigma_s, const float sigma_r)
Definition blur.c:177
dt_gaussian_t * _hl_gauss_get(const int width, const int height, const int channels, const float sigma)
Definition blur.c:28
void _hl_gauss_cache_flush(void)
Definition blur.c:47
cl_int _region_blur_cl(const int devid, cl_mem in, cl_mem out, const int region_w, const int region_h, const float sigma)
Definition blur.c:74
dt_gaussian_cl_t * _region_blur_handle(const int devid, const int region_w, const int region_h, const float sigma)
Definition blur.c:67
const dt_colormatrix_t dt_aligned_pixel_t out
static float gaussian(float x, float std)
Definition filmic.c:404
void dt_gaussian_blur_4c(dt_gaussian_t *g, const float *const in, float *const out)
Definition gaussian.c:330
uint32_t width
Definition mipmap_cache.c:0
uint32_t height
Definition mipmap_cache.c:1
const float sigma