Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
guided_filter.h
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2009-2011 johannes hanika.
4 Copyright (C) 2012 Richard Wonka.
5 Copyright (C) 2016 Roman Lebedev.
6 Copyright (C) 2016 Tobias Ellinghaus.
7 Copyright (C) 2017-2019 Heiko Bauke.
8 Copyright (C) 2017 Peter Budai.
9 Copyright (C) 2020 Hubert Kowalski.
10 Copyright (C) 2020-2021 Pascal Obry.
11 Copyright (C) 2020-2021 Ralf Brown.
12 Copyright (C) 2020 Robert Bridge.
13 Copyright (C) 2022 Martin Bařinka.
14 Copyright (C) 2024 Alynx Zhou.
15 Copyright (C) 2025-2026 Aurélien PIERRE.
16
17 darktable is free software: you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation, either version 3 of the License, or
20 (at your option) any later version.
21
22 darktable is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
26
27 You should have received a copy of the GNU General Public License
28 along with darktable. If not, see <http://www.gnu.org/licenses/>.
29*/
30
31#ifndef DT_PIXEL_GUIDED_FILTER_H
32#define DT_PIXEL_GUIDED_FILTER_H
33
34#include "system/macros.h"
35#include "common/opencl.h"
37
38#include <string.h>
39
40struct dt_iop_roi_t;
41
42// buffer to store single-channel image along with its dimensions
43typedef struct gray_image
44{
45 float *data;
48
49
50// allocate space for 1-component image of size width x height
51// FIXME: the code consuming gray_image doesn't check if we actually allocated the buffer
52static inline int new_gray_image(gray_image *img, int width, int height)
53{
55 if(IS_NULL_PTR(img->data)) return 1;
56 img->width = width;
57 img->height = height;
58 return 0;
59}
60
61
62// free space for 1-component image
63static inline void free_gray_image(gray_image *img_p)
64{
66 img_p->data = NULL;
67}
68
69
70// copy 1-component image img1 to img2
71static inline void copy_gray_image(gray_image img1, gray_image img2)
72{
73 memcpy(img2.data, img1.data, sizeof(float) * img1.width * img1.height);
74}
75
76
77// minimum of two integers
78static inline int min_i(int a, int b)
79{
80 return a < b ? a : b;
81}
82
83
84// maximum of two integers
85static inline int max_i(int a, int b)
86{
87 return a > b ? a : b;
88}
89
90int guided_filter(const float *guide, const float *in, float *out, int width, int height, int ch, int w,
91 float sqrt_eps, float guide_weight, float min, float max);
92
93#ifdef HAVE_OPENCL
94
106
107
109
111
112int guided_filter_cl(int devid, cl_mem guide, cl_mem in, cl_mem out, int width, int height, int ch, int w,
113 float sqrt_eps, float guide_weight, float min, float max);
114
115#endif
116
117#endif // DT_PIXEL_GUIDED_FILTER_H
118
119// clang-format off
120// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
121// vim: shiftwidth=2 expandtab tabstop=2 cindent
122// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
123// clang-format on
static const float const float const float min
const float max
const dt_colormatrix_t dt_aligned_pixel_t out
void dt_guided_filter_init_cl_global(void)
int guided_filter(const float *guide, const float *in, float *out, int width, int height, int ch, int w, float sqrt_eps, float guide_weight, float min, float max)
void dt_guided_filter_free_cl_global(void)
static void copy_gray_image(gray_image img1, gray_image img2)
static int max_i(int a, int b)
static int new_gray_image(gray_image *img, int width, int height)
static int min_i(int a, int b)
static void free_gray_image(gray_image *img_p)
int guided_filter_cl(int devid, cl_mem guide, cl_mem in, cl_mem out, int width, int height, int ch, int w, float sqrt_eps, float guide_weight, float min, float max)
float *const restrict const size_t const size_t ch
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition macros.h:96
uint32_t width
Definition mipmap_cache.c:0
uint32_t height
Definition mipmap_cache.c:1
#define dt_pixelpipe_cache_alloc_align_float_cache(pixels, id)
#define dt_pixelpipe_cache_free_align(mem)
Region of interest passed through the pixelpipe.
Definition format.h:49
float * data