Blender  V3.3
COM_CropOperation.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_CropOperation.h"
5 
6 namespace blender::compositor {
7 
9 {
12  input_operation_ = nullptr;
13  settings_ = nullptr;
14 }
15 
17 {
18  SocketReader *input_reference = this->get_input_socket_reader(0);
19  float width = input_reference->get_width();
20  float height = input_reference->get_height();
21  NodeTwoXYs local_settings = *settings_;
22 
23  if (width > 0.0f && height > 0.0f) {
24  if (relative_) {
25  local_settings.x1 = width * local_settings.fac_x1;
26  local_settings.x2 = width * local_settings.fac_x2;
27  local_settings.y1 = height * local_settings.fac_y1;
28  local_settings.y2 = height * local_settings.fac_y2;
29  }
30  if (width < local_settings.x1) {
31  local_settings.x1 = width;
32  }
33  if (height < local_settings.y1) {
34  local_settings.y1 = height;
35  }
36  if (width < local_settings.x2) {
37  local_settings.x2 = width;
38  }
39  if (height < local_settings.y2) {
40  local_settings.y2 = height;
41  }
42 
43  xmax_ = MAX2(local_settings.x1, local_settings.x2);
44  xmin_ = MIN2(local_settings.x1, local_settings.x2);
45  ymax_ = MAX2(local_settings.y1, local_settings.y2);
46  ymin_ = MIN2(local_settings.y1, local_settings.y2);
47  }
48  else {
49  xmax_ = 0;
50  xmin_ = 0;
51  ymax_ = 0;
52  ymin_ = 0;
53  }
54 }
55 
57 {
59  update_area();
60 }
61 
63 {
64  input_operation_ = nullptr;
65 }
66 
68 {
69  /* pass */
70 }
71 
73 {
74  if ((x < xmax_ && x >= xmin_) && (y < ymax_ && y >= ymin_)) {
76  }
77  else {
78  zero_v4(output);
79  }
80 }
81 
83  const rcti &area,
85 {
86  for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
87  if ((it.x < xmax_ && it.x >= xmin_) && (it.y < ymax_ && it.y >= ymin_)) {
88  copy_v4_v4(it.out, it.in(0));
89  }
90  else {
91  zero_v4(it.out);
92  }
93  }
94 }
95 
97 {
98  /* pass */
99 }
100 
102  ReadBufferOperation *read_operation,
103  rcti *output)
104 {
105  rcti new_input;
106 
107  new_input.xmax = input->xmax + xmin_;
108  new_input.xmin = input->xmin + xmin_;
109  new_input.ymax = input->ymax + ymin_;
110  new_input.ymin = input->ymin + ymin_;
111 
112  return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output);
113 }
114 
116  const rcti &output_area,
117  rcti &r_input_area)
118 {
119  BLI_assert(input_idx == 0);
120  UNUSED_VARS_NDEBUG(input_idx);
121  r_input_area.xmax = output_area.xmax + xmin_;
122  r_input_area.xmin = output_area.xmin + xmin_;
123  r_input_area.ymax = output_area.ymax + ymin_;
124  r_input_area.ymin = output_area.ymin + ymin_;
125 }
126 
127 void CropImageOperation::determine_canvas(const rcti &preferred_area, rcti &r_area)
128 {
129  NodeOperation::determine_canvas(preferred_area, r_area);
130  update_area();
131  r_area.xmax = r_area.xmin + (xmax_ - xmin_);
132  r_area.ymax = r_area.ymin + (ymax_ - ymin_);
133 }
134 
136  float x,
137  float y,
139 {
140  if (x >= 0 && x < get_width() && y >= 0 && y < get_height()) {
142  }
143  else {
144  zero_v4(output);
145  }
146 }
147 
149  const rcti &area,
151 {
152  const MemoryBuffer *input = inputs[0];
153  const int width = get_width();
154  const int height = get_height();
155  for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
156  if (it.x >= 0 && it.x < width && it.y >= 0 && it.y < height) {
157  input->read_elem_checked(it.x + xmin_, it.y + ymin_, it.out);
158  }
159  else {
160  zero_v4(it.out);
161  }
162  }
163 }
164 
165 } // namespace blender::compositor
#define BLI_assert(a)
Definition: BLI_assert.h:46
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE void zero_v4(float r[4])
#define UNUSED_VARS_NDEBUG(...)
#define MAX2(a, b)
#define MIN2(a, b)
_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 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.
bool determine_depending_area_of_interest(rcti *input, ReadBufferOperation *read_operation, rcti *output) override
void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
void determine_canvas(const rcti &preferred_area, rcti &r_area) override
void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
a MemoryBuffer contains access to the data of a chunk
NodeOperation contains calculation logic.
void add_output_socket(DataType datatype)
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)
depth_tx sampler(1, ImageType::FLOAT_2D, "combined_tx") .sampler(2
ccl_global KernelShaderEvalInput ccl_global float * output
ccl_global KernelShaderEvalInput * input
static void area(int d1, int d2, int e1, int e2, float weights[2])
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
static bNodeSocketTemplate inputs[]
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