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#pragma once
32
33#include "common/darktable.h"
34
35#if defined(__SSE__)
36#ifdef __PPC64__
37#ifdef NO_WARN_X86_INTRINSICS
38#include <xmmintrin.h>
39#else
40#define NO_WARN_X86_INTRINSICS 1
41#include <xmmintrin.h>
42#undef NO_WARN_X86_INTRINSICS
43#endif // NO_WARN_X86_INTRINSICS
44#else
45#include <xmmintrin.h>
46#endif // __PPC64__
47#endif
48
49#include "common/darktable.h"
50#include "common/opencl.h"
51
52struct dt_iop_roi_t;
53
54// buffer to store single-channel image along with its dimensions
55typedef struct gray_image
56{
57 float *data;
60
61
62// allocate space for 1-component image of size width x height
63// FIXME: the code consuming gray_image doesn't check if we actually allocated the buffer
64static inline int new_gray_image(gray_image *img, int width, int height)
65{
67 if(!img->data) return 1;
68 img->width = width;
69 img->height = height;
70 return 0;
71}
72
73
74// free space for 1-component image
75static inline void free_gray_image(gray_image *img_p)
76{
78 img_p->data = NULL;
79}
80
81
82// copy 1-component image img1 to img2
83static inline void copy_gray_image(gray_image img1, gray_image img2)
84{
85 memcpy(img2.data, img1.data, sizeof(float) * img1.width * img1.height);
86}
87
88
89// minimum of two integers
90static inline int min_i(int a, int b)
91{
92 return a < b ? a : b;
93}
94
95
96// maximum of two integers
97static inline int max_i(int a, int b)
98{
99 return a > b ? a : b;
100}
101
102int guided_filter(const float *guide, const float *in, float *out, int width, int height, int ch, int w,
103 float sqrt_eps, float guide_weight, float min, float max);
104
105#ifdef HAVE_OPENCL
106
107typedef struct dt_guided_filter_cl_global_t
108{
109 int kernel_guided_filter_split_rgb;
110 int kernel_guided_filter_box_mean_x;
111 int kernel_guided_filter_box_mean_y;
112 int kernel_guided_filter_guided_filter_covariances;
113 int kernel_guided_filter_guided_filter_variances;
114 int kernel_guided_filter_update_covariance;
115 int kernel_guided_filter_solve;
116 int kernel_guided_filter_generate_result;
117} dt_guided_filter_cl_global_t;
118
119
120dt_guided_filter_cl_global_t *dt_guided_filter_init_cl_global();
121
122void dt_guided_filter_free_cl_global(dt_guided_filter_cl_global_t *g);
123
124int guided_filter_cl(int devid, cl_mem guide, cl_mem in, cl_mem out, int width, int height, int ch, int w,
125 float sqrt_eps, float guide_weight, float min, float max);
126
127#endif
128// clang-format off
129// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
130// vim: shiftwidth=2 expandtab tabstop=2 cindent
131// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
132// clang-format on
int width
Definition bilateral.h:1
int height
Definition bilateral.h:1
const float g
Definition colorspaces_inline_conversions.h:925
static const float const float const float min
Definition colorspaces_inline_conversions.h:667
const float max
Definition colorspaces_inline_conversions.h:721
const float b
Definition colorspaces_inline_conversions.h:1326
const float a
Definition colorspaces_inline_conversions.h:1292
static const dt_colormatrix_t dt_aligned_pixel_t out
Definition colorspaces_inline_conversions.h:184
#define dt_pixelpipe_cache_alloc_align_float_cache(pixels, id)
Definition darktable.h:371
#define dt_pixelpipe_cache_free_align(mem)
Definition darktable.h:377
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)
Definition guided_filter.c:360
static void copy_gray_image(gray_image img1, gray_image img2)
Definition guided_filter.h:83
static int max_i(int a, int b)
Definition guided_filter.h:97
static int new_gray_image(gray_image *img, int width, int height)
Definition guided_filter.h:64
static int min_i(int a, int b)
Definition guided_filter.h:90
static void free_gray_image(gray_image *img_p)
Definition guided_filter.h:75
Definition imageop.h:67
Definition guided_filter.h:56
float * data
Definition guided_filter.h:57
int width
Definition guided_filter.h:58
int height
Definition guided_filter.h:58