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) 2017-2021 darktable developers.
4
5 darktable 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 darktable 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#if defined(__SSE__)
22#ifdef __PPC64__
23#ifdef NO_WARN_X86_INTRINSICS
24#include <xmmintrin.h>
25#else
26#define NO_WARN_X86_INTRINSICS 1
27#include <xmmintrin.h>
28#undef NO_WARN_X86_INTRINSICS
29#endif // NO_WARN_X86_INTRINSICS
30#else
31#include <xmmintrin.h>
32#endif // __PPC64__
33#endif
34
35#include "common/darktable.h"
36#include "common/opencl.h"
37
38struct dt_iop_roi_t;
39
40// buffer to store single-channel image along with its dimensions
41typedef struct gray_image
42{
43 float *data;
46
47
48// allocate space for 1-component image of size width x height
49// FIXME: the code consuming gray_image doesn't check if we actually allocated the buffer
50static inline gray_image new_gray_image(int width, int height)
51{
52 return (gray_image){ dt_alloc_align(sizeof(float) * width * height), width, height };
53}
54
55
56// free space for 1-component image
57static inline void free_gray_image(gray_image *img_p)
58{
59 dt_free_align(img_p->data);
60 img_p->data = NULL;
61}
62
63
64// copy 1-component image img1 to img2
65static inline void copy_gray_image(gray_image img1, gray_image img2)
66{
67 memcpy(img2.data, img1.data, sizeof(float) * img1.width * img1.height);
68}
69
70
71// minimum of two integers
72static inline int min_i(int a, int b)
73{
74 return a < b ? a : b;
75}
76
77
78// maximum of two integers
79static inline int max_i(int a, int b)
80{
81 return a > b ? a : b;
82}
83
84void guided_filter(const float *guide, const float *in, float *out, int width, int height, int ch, int w,
85 float sqrt_eps, float guide_weight, float min, float max);
86
87#ifdef HAVE_OPENCL
88
89typedef struct dt_guided_filter_cl_global_t
90{
91 int kernel_guided_filter_split_rgb;
92 int kernel_guided_filter_box_mean_x;
93 int kernel_guided_filter_box_mean_y;
94 int kernel_guided_filter_guided_filter_covariances;
95 int kernel_guided_filter_guided_filter_variances;
96 int kernel_guided_filter_update_covariance;
97 int kernel_guided_filter_solve;
98 int kernel_guided_filter_generate_result;
99} dt_guided_filter_cl_global_t;
100
101
102dt_guided_filter_cl_global_t *dt_guided_filter_init_cl_global();
103
104void dt_guided_filter_free_cl_global(dt_guided_filter_cl_global_t *g);
105
106void guided_filter_cl(int devid, cl_mem guide, cl_mem in, cl_mem out, int width, int height, int ch, int w,
107 float sqrt_eps, float guide_weight, float min, float max);
108
109#endif
110// clang-format off
111// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
112// vim: shiftwidth=2 expandtab tabstop=2 cindent
113// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
114// clang-format on
int width
Definition bilateral.h:1
int height
Definition bilateral.h:1
#define dt_free_align(A)
Definition darktable.h:334
static gray_image new_gray_image(int width, int height)
Definition guided_filter.h:50
static void copy_gray_image(gray_image img1, gray_image img2)
Definition guided_filter.h:65
static int max_i(int a, int b)
Definition guided_filter.h:79
static int min_i(int a, int b)
Definition guided_filter.h:72
void 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:309
static void free_gray_image(gray_image *img_p)
Definition guided_filter.h:57
Definition imageop.h:32
Definition guided_filter.h:42
float * data
Definition guided_filter.h:43
int width
Definition guided_filter.h:44
int height
Definition guided_filter.h:44
#define dt_alloc_align(B)
Definition tests/cache.c:22