Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
blur.c
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// Gaussian blur helpers + per-region blur, and the OpenCL blur / device-timing runtime prelude. (implementation;
20// see blur.h for the public API.)
21
22#include "develop/imageop.h"
24#include "iop/highlights/blur.h"
25#include <string.h>
26
27static __thread _hl_gauss_slot_t _hl_gauss_cache[HL_GAUSS_SLOTS] = { { 0 } };
28static __thread int _hl_gauss_rr = 0;
29
30dt_gaussian_t *_hl_gauss_get(const int width, const int height, const int channels, const float sigma)
31{
32 for(int i = 0; i < HL_GAUSS_SLOTS; i++)
34 && _hl_gauss_cache[i].channels == channels && _hl_gauss_cache[i].sigma == sigma)
36
38 if(slot->gaussian) dt_gaussian_free(slot->gaussian);
39 float vmax[4] = { 1e9f, 1e9f, 1e9f, 1e9f };
40 float vmin[4] = { -1e9f, -1e9f, -1e9f, -1e9f };
41 slot->gaussian = dt_gaussian_init(width, height, channels, vmax, vmin, sigma, 0);
42 slot->width = width;
43 slot->height = height;
44 slot->channels = channels;
45 slot->sigma = sigma;
46 return slot->gaussian;
47}
48
57
58// and main pipes can run _region_guided_filter concurrently; each accumulates on its own thread.
59
60// ============================ OpenCL ============================
61
62#ifdef HAVE_OPENCL
63// host spends BLOCKED on the device (reads, finishes) vs pure enqueue counts, plus the
64// host-side sparse Cholesky work. Accumulated per thread, reset at the middle's entry,
65// printed with the "gpu middle" line.
66#endif // HAVE_OPENCL
67
68#ifdef HAVE_OPENCL
69dt_gaussian_cl_t *_region_blur_handle(const int devid, const int region_w, const int region_h, const float sigma)
70{
71 const float vmax[4] = { 1e9f, 1e9f, 1e9f, 1e9f };
72 const float vmin[4] = { -1e9f, -1e9f, -1e9f, -1e9f };
73 return dt_gaussian_init_cl(devid, region_w, region_h, 4, vmax, vmin, sigma, 0);
74}
75
76cl_int _region_blur_cl(const int devid, cl_mem in, cl_mem out, const int region_w, const int region_h,
77 const float sigma)
78{
79 dt_gaussian_cl_t *gaussian = _region_blur_handle(devid, region_w, region_h, sigma);
81 const cl_int cl_err = dt_gaussian_blur_cl(gaussian, in, out);
83 return cl_err;
84}
85
86#endif // HAVE_OPENCL
int width
Definition bilateral.h:1
int height
Definition bilateral.h:1
static __thread _hl_gauss_slot_t _hl_gauss_cache[HL_GAUSS_SLOTS]
Definition blur.c:27
dt_gaussian_t * _hl_gauss_get(const int width, const int height, const int channels, const float sigma)
Definition blur.c:30
static __thread int _hl_gauss_rr
Definition blur.c:28
void _hl_gauss_cache_flush(void)
Definition blur.c:49
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:76
dt_gaussian_cl_t * _region_blur_handle(const int devid, const int region_w, const int region_h, const float sigma)
Definition blur.c:69
const dt_colormatrix_t dt_aligned_pixel_t out
static float gaussian(float x, float std)
Definition filmic.c:397
void dt_gaussian_free(dt_gaussian_t *g)
Definition gaussian.c:330
void dt_gaussian_free_cl(dt_gaussian_cl_t *g)
Definition gaussian.c:353
cl_int dt_gaussian_blur_cl(dt_gaussian_cl_t *g, cl_mem dev_in, cl_mem dev_out)
Definition gaussian.c:441
dt_gaussian_cl_t * dt_gaussian_init_cl(const int devid, const int width, const int height, const int channels, const float *max, const float *min, const float sigma, const int order)
Definition gaussian.c:364
dt_gaussian_t * dt_gaussian_init(const int width, const int height, const int channels, const float *max, const float *min, const float sigma, const int order)
Definition gaussian.c:122
#define DT_OPENCL_DEFAULT_ERROR
Definition opencl.h:57
const float sigma
#define HL_GAUSS_SLOTS