Blender V4.3
denoising.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#ifndef __DENOISING_H__
6#define __DENOISING_H__
7
8/* TODO(sergey): Make it explicit and clear when something is a denoiser, its pipeline or
9 * parameters. Currently it is an annoying mixture of terms used interchangeably. */
10
11#include "device/device.h"
12#include "integrator/denoiser.h"
13
14#include "util/string.h"
15#include "util/unique_ptr.h"
16#include "util/vector.h"
17
18#include <OpenImageIO/imageio.h>
19
20OIIO_NAMESPACE_USING
21
23
24/* Denoiser pipeline */
25
27 public:
28 DenoiserPipeline(DeviceInfo &denoiser_device_info, const DenoiseParams &params);
30
31 bool run();
32
33 /* Error message after running, in case of failure. */
34 string error;
35
36 /* Sequential list of frame filepaths to denoise. */
38 /* Sequential list of frame filepaths to write result to. Empty entries
39 * are skipped, so only a subset of the sequence can be denoised while
40 * taking into account all input frames. */
42
43 protected:
44 friend class DenoiseTask;
45
50 std::unique_ptr<Denoiser> denoiser;
51};
52
53/* Denoise Image Layer */
54
56 string name;
57 /* All channels belonging to this DenoiseImageLayer. */
59 /* Layer to image channel mapping. */
61
62 /* Sample amount that was used for rendering this layer. */
64
65 /* Device input channel will be copied from image channel input_to_image_channel[i]. */
67
68 /* Write i-th channel of the processing output to output_to_image_channel[i]-th channel of the
69 * file. */
71
72 /* output_to_image_channel of the previous frame, if used. */
74
75 /* Detect whether this layer contains a full set of channels and set up the offsets accordingly.
76 */
78
79 /* Map the channels of a secondary frame to the channels that are required for processing,
80 * fill neighbor_input_to_image_channel if all are present or return false if a channel are
81 * missing. */
82 bool match_channels(const std::vector<string> &channelnames,
83 const std::vector<string> &neighbor_channelnames);
84};
85
86/* Denoise Image Data */
87
89 public:
92
93 /* Dimensions */
95
96 /* Samples */
98
99 /* Pixel buffer with interleaved channels. */
101
102 /* Image file handles */
103 ImageSpec in_spec;
104 unique_ptr<ImageInput> in_previous;
105
106 /* Render layers */
108
109 void free();
110
111 /* Open the input image, parse its channels, open the output image and allocate the output
112 * buffer. */
113 bool load(const string &in_filepath, string &error);
114
115 /* Load neighboring frames. */
116 bool load_previous(const string &in_filepath, string &error);
117
118 /* Load subset of pixels from file buffer into input buffer, as needed for denoising
119 * on the device. Channels are reshuffled following the provided mapping. */
120 void read_pixels(const DenoiseImageLayer &layer,
121 const BufferParams &params,
122 float *input_pixels);
123 bool read_previous_pixels(const DenoiseImageLayer &layer,
124 const BufferParams &params,
125 float *input_pixels);
126
127 bool save_output(const string &out_filepath, string &error);
128
129 protected:
130 /* Parse input file channels, separate them into DenoiseImageLayers,
131 * detect DenoiseImageLayers with full channel sets,
132 * fill layers and set up the output channels and passthrough map. */
133 bool parse_channels(const ImageSpec &in_spec, string &error);
134
135 void close_input();
136};
137
138/* Denoise Task */
139
141 public:
143 ~DenoiseTask();
144
145 /* Task stages */
146 bool load();
147 bool exec();
148 bool save();
149 void free();
150
151 string error;
152
153 protected:
154 /* Denoiser parameters and device */
157
158 /* Frame number to be denoised */
159 int frame;
160
161 /* Image file data */
164
166
167 /* Task handling */
168 bool load_input_pixels(int layer);
169};
170
172
173#endif /* __DENOISING_H__ */
void read_pixels(const DenoiseImageLayer &layer, const BufferParams &params, float *input_pixels)
bool parse_channels(const ImageSpec &in_spec, string &error)
void close_input()
array< float > pixels
Definition denoising.h:100
vector< DenoiseImageLayer > layers
Definition denoising.h:107
bool read_previous_pixels(const DenoiseImageLayer &layer, const BufferParams &params, float *input_pixels)
int num_channels
Definition denoising.h:94
bool load(const string &in_filepath, string &error)
unique_ptr< ImageInput > in_previous
Definition denoising.h:104
bool load_previous(const string &in_filepath, string &error)
bool save_output(const string &out_filepath, string &error)
ImageSpec in_spec
Definition denoising.h:103
DenoiserPipeline * denoiser
Definition denoising.h:155
RenderBuffers buffers
Definition denoising.h:165
string error
Definition denoising.h:151
DenoiseTask(Device *device, DenoiserPipeline *denoiser, int frame)
Device * device
Definition denoising.h:156
bool load_input_pixels(int layer)
int current_layer
Definition denoising.h:163
DenoiseImage image
Definition denoising.h:162
std::unique_ptr< Denoiser > denoiser
Definition denoising.h:50
Device * cpu_device
Definition denoising.h:49
DenoiserPipeline(DeviceInfo &denoiser_device_info, const DenoiseParams &params)
Device * device
Definition denoising.h:48
vector< string > input
Definition denoising.h:37
Profiler profiler
Definition denoising.h:47
vector< string > output
Definition denoising.h:41
#define CCL_NAMESPACE_END
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static void error(const char *str)
vector< int > previous_output_to_image_channel
Definition denoising.h:73
vector< int > input_to_image_channel
Definition denoising.h:66
bool match_channels(const std::vector< string > &channelnames, const std::vector< string > &neighbor_channelnames)
bool detect_denoising_channels()
Definition denoising.cpp:97
vector< int > output_to_image_channel
Definition denoising.h:70
vector< string > channels
Definition denoising.h:58
vector< int > layer_to_image_channel
Definition denoising.h:60