Blender  V3.3
COM_PreviewOperation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
4 #include "COM_PreviewOperation.h"
5 
6 #include "BKE_node.h"
7 #include "IMB_colormanagement.h"
8 
9 namespace blender::compositor {
10 
12  const ColorManagedDisplaySettings *display_settings,
13  const unsigned int default_width,
14  const unsigned int default_height)
15 
16 {
18  preview_ = nullptr;
19  output_buffer_ = nullptr;
20  input_ = nullptr;
21  divider_ = 1.0f;
22  view_settings_ = view_settings;
23  display_settings_ = display_settings;
24  default_width_ = default_width;
25  default_height_ = default_height;
28 }
29 
31 {
32  /* Size (0, 0) ensures the preview rect is not allocated in advance,
33  * this is set later in init_execution once the resolution is determined.
34  */
35  preview_ = BKE_node_preview_verify(previews, key, 0, 0, true);
36 }
37 
39 {
41 
42  if (this->get_width() == (unsigned int)preview_->xsize &&
43  this->get_height() == (unsigned int)preview_->ysize) {
45  }
46 
47  if (output_buffer_ == nullptr) {
48  output_buffer_ = (unsigned char *)MEM_callocN(
49  sizeof(unsigned char) * 4 * get_width() * get_height(), "PreviewOperation");
50  if (preview_->rect) {
52  }
56  }
57 }
58 
60 {
61  output_buffer_ = nullptr;
62  input_ = nullptr;
63 }
64 
65 void PreviewOperation::execute_region(rcti *rect, unsigned int /*tile_number*/)
66 {
67  int offset;
68  float color[4];
69  struct ColormanageProcessor *cm_processor;
70 
72 
73  for (int y = rect->ymin; y < rect->ymax; y++) {
74  offset = (y * get_width() + rect->xmin) * 4;
75  for (int x = rect->xmin; x < rect->xmax; x++) {
76  float rx = floor(x / divider_);
77  float ry = floor(y / divider_);
78 
79  color[0] = 0.0f;
80  color[1] = 0.0f;
81  color[2] = 0.0f;
82  color[3] = 1.0f;
86  offset += 4;
87  }
88  }
89 
91 }
93  ReadBufferOperation *read_operation,
94  rcti *output)
95 {
96  rcti new_input;
97 
98  new_input.xmin = input->xmin / divider_;
99  new_input.xmax = input->xmax / divider_;
100  new_input.ymin = input->ymin / divider_;
101  new_input.ymax = input->ymax / divider_;
102 
103  return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output);
104 }
105 void PreviewOperation::determine_canvas(const rcti &UNUSED(preferred_area), rcti &r_area)
106 {
107  /* Use default preview resolution as preferred ensuring it has size so that
108  * generated inputs (which don't have resolution on their own) are displayed */
110  rcti local_preferred;
111  BLI_rcti_init(&local_preferred, 0, default_width_, 0, default_height_);
112  NodeOperation::determine_canvas(local_preferred, r_area);
113 
114  /* If resolution is 0 there are two possible scenarios:
115  * - Either node is not connected at all
116  * - Or it is connected to an input which has no resolution.
117  *
118  * In the former case we rely on the execution system to not evaluate this node.
119  *
120  * The latter case would only happen if an input doesn't set any resolution ignoring output
121  * preferred resolution. In such case preview size will be 0 too.
122  */
123  int width = BLI_rcti_size_x(&r_area);
124  int height = BLI_rcti_size_y(&r_area);
125  divider_ = 0.0f;
126  if (width > 0 && height > 0) {
127  if (width > height) {
129  }
130  else {
132  }
133  }
134  width = width * divider_;
135  height = height * divider_;
136 
137  BLI_rcti_init(&r_area, r_area.xmin, r_area.xmin + width, r_area.ymin, r_area.ymin + height);
138 }
139 
141 {
143 }
144 
145 void PreviewOperation::get_area_of_interest(const int input_idx,
146  const rcti &output_area,
147  rcti &r_input_area)
148 {
149  BLI_assert(input_idx == 0);
150  UNUSED_VARS_NDEBUG(input_idx);
151 
152  r_input_area.xmin = output_area.xmin / divider_;
153  r_input_area.xmax = output_area.xmax / divider_;
154  r_input_area.ymin = output_area.ymin / divider_;
155  r_input_area.ymax = output_area.ymax / divider_;
156 }
157 
159  const rcti &area,
161 {
162  MemoryBuffer *input = inputs[0];
165 
166  rcti buffer_area;
167  BLI_rcti_init(&buffer_area, 0, this->get_width(), 0, this->get_height());
170 
171  for (BuffersIterator<uchar> it = it_builder.build(); !it.is_end(); ++it) {
172  const float rx = it.x / divider_;
173  const float ry = it.y / divider_;
174 
175  float color[4];
176  input->read_elem_checked(rx, ry, color);
178  rgba_float_to_uchar(it.out, color);
179  }
180 
182 }
183 
184 } // namespace blender::compositor
typedef float(TangentPoint)[2]
bNodePreview * BKE_node_preview_verify(struct bNodeInstanceHash *previews, bNodeInstanceKey key, int xsize, int ysize, bool create)
Definition: node.cc:2721
#define BLI_assert(a)
Definition: BLI_assert.h:46
void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
Definition: math_color.c:396
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition: BLI_rect.h:190
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition: rct.c:417
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition: BLI_rect.h:186
#define UNUSED_VARS_NDEBUG(...)
#define UNUSED(x)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
void IMB_colormanagement_processor_free(struct ColormanageProcessor *cm_processor)
void IMB_colormanagement_processor_apply_v4(struct ColormanageProcessor *cm_processor, float pixel[4])
struct ColormanageProcessor * IMB_colormanagement_display_processor_new(const struct ColorManagedViewSettings *view_settings, const struct ColorManagedDisplaySettings *display_settings)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
BuffersIteratorBuilder::Iterator build()
a MemoryBuffer contains access to the data of a chunk
SocketReader * get_input_socket_reader(unsigned int index)
virtual bool determine_depending_area_of_interest(rcti *input, ReadBufferOperation *read_operation, rcti *output)
void read_sampled(float result[4], float x, float y, PixelSampler sampler)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
virtual void determine_canvas(const rcti &preferred_area, rcti &r_area)
void verify_preview(bNodeInstanceHash *previews, bNodeInstanceKey key)
bool determine_depending_area_of_interest(rcti *input, ReadBufferOperation *read_operation, rcti *output) override
bNodePreview * preview_
holds reference to the SDNA bNode, where this nodes will render the preview image for
void execute_region(rcti *rect, unsigned int tile_number) override
when a chunk is executed by a CPUDevice, this method is called
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 update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
eCompositorPriority
Possible priority settings.
Definition: COM_Enums.h:32
ccl_global KernelShaderEvalInput ccl_global float * output
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
ccl_global KernelShaderEvalInput * input
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
static void area(int d1, int d2, int e1, int e2, float weights[2])
constexpr float COM_PREVIEW_SIZE
Definition: COM_defines.h:108
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
constexpr int COM_data_type_num_channels(const DataType datatype)
Definition: COM_defines.h:42
T floor(const T &a)
static bNodeSocketTemplate inputs[]
unsigned char * rect
int ymin
Definition: DNA_vec_types.h:64
int ymax
Definition: DNA_vec_types.h:64
int xmin
Definition: DNA_vec_types.h:63
int xmax
Definition: DNA_vec_types.h:63