Blender V4.3
COM_CropOperation.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 "COM_CropOperation.h"
8
9namespace blender::compositor {
10
18
20{
21 const NodeTwoXYs &node_two_xys = *settings_;
22 const SocketReader *input = this->get_input_socket_reader(0);
23 const int2 input_size = int2(input->get_width(), input->get_height());
24 if (relative_) {
25 /* The cropping bounds are relative to the image size. The factors are in the [0, 1] range,
26 * so it is guaranteed that they won't go over the input image size. */
27 xmin_ = input_size.x * node_two_xys.fac_x1;
28 ymin_ = input_size.y * node_two_xys.fac_y2;
29 xmax_ = input_size.x * node_two_xys.fac_x2;
30 ymax_ = input_size.y * node_two_xys.fac_y1;
31 }
32 else {
33 /* Make sure the bounds don't go over the input image size. */
34 xmin_ = min_ii(node_two_xys.x1, input_size.x);
35 ymin_ = min_ii(node_two_xys.y2, input_size.y);
36 xmax_ = min_ii(node_two_xys.x2, input_size.x);
37 ymax_ = min_ii(node_two_xys.y1, input_size.y);
38 }
39
40 /* Make sure upper bound is actually higher than the lower bound. */
45}
46
51
56
58 const rcti &area,
60{
61 for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
62 if ((it.x < xmax_ && it.x >= xmin_) && (it.y < ymax_ && it.y >= ymin_)) {
63 copy_v4_v4(it.out, it.in(0));
64 }
65 else {
66 zero_v4(it.out);
67 }
68 }
69}
70
75
77 const rcti &output_area,
78 rcti &r_input_area)
79{
80 BLI_assert(input_idx == 0);
81 UNUSED_VARS_NDEBUG(input_idx);
82 r_input_area.xmax = output_area.xmax + xmin_;
83 r_input_area.xmin = output_area.xmin + xmin_;
84 r_input_area.ymax = output_area.ymax + ymin_;
85 r_input_area.ymin = output_area.ymin + ymin_;
86}
87
88void CropImageOperation::determine_canvas(const rcti &preferred_area, rcti &r_area)
89{
90 NodeOperation::determine_canvas(preferred_area, r_area);
92 r_area.xmax = r_area.xmin + (xmax_ - xmin_);
93 r_area.ymax = r_area.ymin + (ymax_ - ymin_);
94}
95
97 const rcti &area,
99{
100 const MemoryBuffer *input = inputs[0];
101 const int width = get_width();
102 const int height = get_height();
103 for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
104 if (it.x >= 0 && it.x < width && it.y >= 0 && it.y < height) {
105 input->read_elem_checked(it.x + xmin_, it.y + ymin_, it.out);
106 }
107 else {
108 zero_v4(it.out);
109 }
110 }
111}
112
113} // namespace blender::compositor
#define BLI_assert(a)
Definition BLI_assert.h:50
MINLINE int min_ii(int a, int b)
MINLINE int max_ii(int a, int b)
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE void zero_v4(float r[4])
#define UNUSED_VARS_NDEBUG(...)
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.
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 update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
a MemoryBuffer contains access to the data
NodeOperation contains calculation logic.
void add_output_socket(DataType datatype)
SocketReader * get_input_socket_reader(unsigned int index)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
virtual void determine_canvas(const rcti &preferred_area, rcti &r_area)
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
VecBase< int32_t, 2 > int2
int ymin
int ymax
int xmin
int xmax