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