Blender V4.3
COM_PixelateOperation.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 <algorithm>
8
9namespace blender::compositor {
10
21
22void PixelateOperation::get_area_of_interest(const int /*input_idx*/,
23 const rcti &output_area,
24 rcti &r_input_area)
25{
26 r_input_area.xmin = output_area.xmin;
27 r_input_area.ymin = output_area.ymin;
28
29 r_input_area.xmax = output_area.xmax + pixel_size_ - 1;
30 r_input_area.ymax = output_area.ymax + pixel_size_ - 1;
31}
32
34 const rcti &area,
36{
37 MemoryBuffer *image = inputs[0];
38
39 if (image->is_a_single_elem()) {
40 copy_v4_v4(output->get_elem(0, 0), image->get_elem(0, 0));
41 return;
42 }
43
44 const int width = image->get_width();
45 const int height = image->get_height();
46
47 for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
48 const int x_start = (it.x / pixel_size_) * pixel_size_;
49 const int y_start = (it.y / pixel_size_) * pixel_size_;
50
51 const int x_end = std::min(x_start + pixel_size_, width);
52 const int y_end = std::min(y_start + pixel_size_, height);
53
54 float4 color_accum(0, 0, 0, 0);
55
56 for (int y = y_start; y < y_end; ++y) {
57 for (int x = x_start; x < x_end; ++x) {
58 float4 color;
59 image->read_elem(x, y, color);
60
61 color_accum += color;
62 }
63 }
64
65 const int scale = (x_end - x_start) * (y_end - y_start);
66
67 copy_v4_v4(it.out, color_accum / float(scale));
68 }
69}
70
71} // namespace blender::compositor
MINLINE void copy_v4_v4(float r[4], const float a[4])
a MemoryBuffer contains access to the data
void add_output_socket(DataType datatype)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
void set_canvas_input_index(unsigned int index)
set the index of the input socket that will determine the canvas of this operation
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
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.
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
int ymin
int ymax
int xmin
int xmax