Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
dwt.h
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2017 Edgardo Hoszowski.
4 Copyright (C) 2020 Pascal Obry.
5 Copyright (C) 2020 Ralf Brown.
6 Copyright (C) 2022 Martin Bařinka.
7 Copyright (C) 2026 Aurélien PIERRE.
8
9 darktable is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 darktable is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with darktable. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#ifndef DT_DEVELOP_DWT_H
24#define DT_DEVELOP_DWT_H
25
26/* structure returned by dt_dwt_init() to be used when calling dwt_decompose() */
40
41/* function prototype for the layer_func on dwt_decompose() call */
42typedef int(_dwt_layer_func)(float *layer, dwt_params_t *const p, const int scale);
43
44/* returns a structure used when calling dwt_decompose(), free it with dt_dwt_free()
45 * image: image to be decomposed and output image
46 * width, height, ch: dimensions of the image
47 * scales: number of scales to decompose, if > dwt_get_max_scale() the this last will be used
48 * return_layer: 0 returns the recomposed image, 1..scales returns a detail scale, scales+1 returns the residual
49 * image
50 * merge_from_scale: detail scales will be merged together before calling layer_func
51 * user_data: user-supplied data to be passed to layer_func on each call
52 * preview_scale: image scale (zoom factor)
53 * use_sse: use SSE instructions
54 */
55dwt_params_t *dt_dwt_init(float *image, const int width, const int height, const int ch, const int scales,
56 const int return_layer, const int merge_from_scale, void *user_data,
57 const float preview_scale, const int use_sse);
58
59/* free resources used by dwt_decompose() */
61
62/* returns the maximum number of scales that dwt_decompose() will accept for the current image size */
64
65/* returns the first visible detail scale at the current zoom level */
67
68/* decomposes an image into several wavelet scales
69 * p: returned by dt_dwt_init()
70 * layer_func: this function is called for the original image and then once for each scale, including the residual
71 * image
72 */
74
75/* decomposes an image into 'bands' wavelet scales, then recomposes a denoised image from just that portion
76 * of each scale whose absolute magnitude exceeds the threshold in noise[band]
77 * img: input image, overwritten with the denoised image
78 * width, height: image dimensions
79 * bands: number of wavelet scales to generate
80 * noise: array of thresholds, on per band
81 */
82int dwt_denoise(float *const img, const int width, const int height, const int bands, const float *const noise);
83
84// to make the DWT algorithm (and others which operate on a column of spaced-out pixels for each pixel of a
85// row) as cache-friendly as possible, we want to interleave the actual processing of rows such that the next
86// iteration processes the row 'stride' pixels below the current one, which will already be in L2 cache (if
87// not L1) from having been accessed on this iteration so if stride is 16, we want to process rows 0, 16, 32,
88// ..., then 1, 17, 33, ..., 2, 18, 34, ..., etc.
89/*
90 * given a row identifier (0 .. height-1), an image height, and a stride,
91 * return the physical row number of the image on which to operate
92 */
93static inline int dwt_interleave_rows(const int rowid, const int height, const int stride)
94{
95 if (height <= stride)
96 return rowid;
97 const int per_pass = ((height + stride - 1) / stride);
98 const int long_passes = height % stride;
99 // adjust for the fact that we have some passes with one fewer iteration when height is not a multiple of stride
100 if (long_passes == 0 || rowid < long_passes * per_pass)
101 return (rowid / per_pass) + stride * (rowid % per_pass);
102 const int rowid2 = rowid - long_passes * per_pass;
103 return long_passes + (rowid2 / (per_pass-1)) + stride * (rowid2 % (per_pass-1));
104}
105
106
107
108#ifdef HAVE_OPENCL
109typedef struct dt_dwt_cl_global_t
110{
111 int kernel_dwt_add_img_to_layer;
112 int kernel_dwt_subtract_layer;
113 int kernel_dwt_hat_transform_col;
114 int kernel_dwt_hat_transform_row;
115 int kernel_dwt_init_buffer;
116} dt_dwt_cl_global_t;
117
118typedef struct dwt_params_cl_t
119{
120 dt_dwt_cl_global_t *global;
121 int devid;
122 cl_mem image;
123 int width;
124 int height;
125 int ch;
126 int scales;
127 int return_layer;
128 int merge_from_scale;
129 void *user_data;
130 float preview_scale;
131} dwt_params_cl_t;
132
133typedef cl_int(_dwt_layer_func_cl)(cl_mem layer, dwt_params_cl_t *const p, const int scale);
134
135dt_dwt_cl_global_t *dt_dwt_init_cl_global(void);
136void dt_dwt_free_cl_global(dt_dwt_cl_global_t *g);
137
138dwt_params_cl_t *dt_dwt_init_cl(const int devid, cl_mem image, const int width, const int height, const int scales,
139 const int return_layer, const int merge_from_scale, void *user_data,
140 const float preview_scale);
141void dt_dwt_free_cl(dwt_params_cl_t *p);
142
143int dwt_get_max_scale_cl(dwt_params_cl_t *p);
144
145int dt_dwt_first_scale_visible_cl(dwt_params_cl_t *p);
146
147cl_int dwt_decompose_cl(dwt_params_cl_t *p, _dwt_layer_func_cl layer_func);
148
149#endif
150
151#endif
152// clang-format off
153// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
154// vim: shiftwidth=2 expandtab tabstop=2 cindent
155// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
156// clang-format on
int width
Definition bilateral.h:1
int height
Definition bilateral.h:1
static const dt_aligned_pixel_simd_t const dt_adaptation_t const float p
Definition chromatic_adaptation.h:315
const float g
Definition colorspaces_inline_conversions.h:925
int dwt_denoise(float *const img, const int width, const int height, const int bands, const float *const noise)
Definition dwt.c:536
int() _dwt_layer_func(float *layer, dwt_params_t *const p, const int scale)
Definition dwt.h:42
int dwt_decompose(dwt_params_t *p, _dwt_layer_func layer_func)
Definition dwt.c:385
int dwt_get_max_scale(dwt_params_t *p)
Definition dwt.c:91
void dt_dwt_free(dwt_params_t *p)
Definition dwt.c:64
static int dwt_interleave_rows(const int rowid, const int height, const int stride)
Definition dwt.h:93
dwt_params_t * dt_dwt_init(float *image, const int width, const int height, const int ch, const int scales, const int return_layer, const int merge_from_scale, void *user_data, const float preview_scale, const int use_sse)
Definition dwt.c:43
int dt_dwt_first_scale_visible(dwt_params_t *p)
Definition dwt.c:114
ch
Definition derive_filmic_v6_gamut_mapping.py:35
Definition dwt.h:28
int use_sse
Definition dwt.h:38
void * user_data
Definition dwt.h:36
float preview_scale
Definition dwt.h:37
int return_layer
Definition dwt.h:34
int width
Definition dwt.h:31
int scales
Definition dwt.h:33
int height
Definition dwt.h:32
int ch
Definition dwt.h:30
float * image
Definition dwt.h:29
int merge_from_scale
Definition dwt.h:35