Blender V4.3
COM_PreviewOperation.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7#include "BKE_node.hh"
9#include "IMB_imbuf.hh"
10
11namespace blender::compositor {
12
14 const ColorManagedDisplaySettings *display_settings,
15 const uint default_width,
16 const uint default_height)
17
18{
20 preview_ = nullptr;
21 output_image_ = nullptr;
22 divider_ = 1.0f;
23 view_settings_ = view_settings;
24 display_settings_ = display_settings;
25 default_width_ = default_width;
26 default_height_ = default_height;
29}
30
32{
33 /* Size (0, 0) ensures the preview rect is not allocated in advance,
34 * this is set later in init_execution once the resolution is determined.
35 */
36 preview_ = blender::bke::node_preview_verify(previews, key, 0, 0, true);
37}
38
40{
42
43 if (this->get_width() == uint(preview_->ibuf->x) &&
44 this->get_height() == uint(preview_->ibuf->y))
45 {
46 return;
47 }
48 const uint size[2] = {get_width(), get_height()};
50 if (output_image_->byte_buffer.data == nullptr) {
52 }
53}
54
59
60void PreviewOperation::determine_canvas(const rcti & /*preferred_area*/, rcti &r_area)
61{
62 /* Use default preview resolution as preferred ensuring it has size so that
63 * generated inputs (which don't have resolution on their own) are displayed */
65 rcti local_preferred;
66 BLI_rcti_init(&local_preferred, 0, default_width_, 0, default_height_);
67 NodeOperation::determine_canvas(local_preferred, r_area);
68
69 /* If resolution is 0 there are two possible scenarios:
70 * - Either node is not connected at all
71 * - Or it is connected to an input which has no resolution.
72 *
73 * In the former case we rely on the execution system to not evaluate this node.
74 *
75 * The latter case would only happen if an input doesn't set any resolution ignoring output
76 * preferred resolution. In such case preview size will be 0 too.
77 */
78 int width = BLI_rcti_size_x(&r_area);
79 int height = BLI_rcti_size_y(&r_area);
80 divider_ = 0.0f;
81 if (width > 0 && height > 0) {
82 if (width > height) {
83 divider_ = float(COM_PREVIEW_SIZE) / (width);
84 }
85 else {
86 divider_ = float(COM_PREVIEW_SIZE) / (height);
87 }
88 }
89 width = width * divider_;
90 height = height * divider_;
91
92 BLI_rcti_init(&r_area, r_area.xmin, r_area.xmin + width, r_area.ymin, r_area.ymin + height);
93}
94
99
101 const rcti &output_area,
102 rcti &r_input_area)
103{
104 BLI_assert(input_idx == 0);
105 UNUSED_VARS_NDEBUG(input_idx);
106
107 r_input_area.xmin = output_area.xmin / divider_;
108 r_input_area.xmax = output_area.xmax / divider_;
109 r_input_area.ymin = output_area.ymin / divider_;
110 r_input_area.ymax = output_area.ymax / divider_;
111}
112
114 const rcti &area,
116{
117 MemoryBuffer *input = inputs[0];
120
121 rcti buffer_area;
122 BLI_rcti_init(&buffer_area, 0, this->get_width(), 0, this->get_height());
124 buffer_area,
125 area,
127
128 for (BuffersIterator<uchar> it = it_builder.build(); !it.is_end(); ++it) {
129 const float rx = it.x / divider_;
130 const float ry = it.y / divider_;
131
132 float color[4];
133 input->read_elem_checked(rx, ry, color);
134 IMB_colormanagement_processor_apply_v4(cm_processor, color);
135 rgba_float_to_uchar(it.out, color);
136 }
137
139}
140
141} // namespace blender::compositor
#define BLI_assert(a)
Definition BLI_assert.h:50
void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.h:193
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition rct.c:418
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.h:189
unsigned int uint
#define UNUSED_VARS_NDEBUG(...)
ColormanageProcessor * IMB_colormanagement_display_processor_new(const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings)
void IMB_colormanagement_processor_free(ColormanageProcessor *cm_processor)
void IMB_colormanagement_processor_apply_v4(ColormanageProcessor *cm_processor, float pixel[4])
bool imb_addrectImBuf(ImBuf *ibuf, bool initialize_pixels=true)
void IMB_rect_size_set(ImBuf *ibuf, const uint size[2])
Definition rectop.cc:287
BuffersIteratorBuilder::Iterator build()
a MemoryBuffer contains access to the data
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
virtual void determine_canvas(const rcti &preferred_area, rcti &r_area)
bNodePreview * preview_
holds reference to the SDNA bNode, where this nodes will render the preview image for
void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override
Get input operation area being read by this operation on rendering given output area.
const ColorManagedDisplaySettings * display_settings_
eCompositorPriority get_render_priority() const override
get the render priority of this node.
const ColorManagedViewSettings * view_settings_
void determine_canvas(const rcti &preferred_area, rcti &r_area) override
PreviewOperation(const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, unsigned int default_width, unsigned int default_height)
void verify_preview(bke::bNodeInstanceHash *previews, bNodeInstanceKey key)
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
draw_view in_light_buf[] float
eCompositorPriority
Possible priority settings.
Definition COM_Enums.h:33
bNodePreview * node_preview_verify(bNodeInstanceHash *previews, bNodeInstanceKey key, int xsize, int ysize, bool create)
Definition node.cc:3273
constexpr float COM_PREVIEW_SIZE
Definition COM_defines.h:85
constexpr int COM_data_type_num_channels(const DataType datatype)
Definition COM_defines.h:35
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
ImBufByteBuffer byte_buffer
struct ImBuf * ibuf
int ymin
int ymax
int xmin
int xmax