Blender  V2.93
COM_CropOperation.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2011, Blender Foundation.
17  */
18 
19 #include "COM_CropOperation.h"
20 #include "BLI_math.h"
21 
22 namespace blender::compositor {
23 
25 {
28  this->m_inputOperation = nullptr;
29  this->m_settings = nullptr;
30 }
31 
33 {
34  SocketReader *inputReference = this->getInputSocketReader(0);
35  float width = inputReference->getWidth();
36  float height = inputReference->getHeight();
37  NodeTwoXYs local_settings = *this->m_settings;
38 
39  if (width > 0.0f && height > 0.0f) {
40  if (this->m_relative) {
41  local_settings.x1 = width * local_settings.fac_x1;
42  local_settings.x2 = width * local_settings.fac_x2;
43  local_settings.y1 = height * local_settings.fac_y1;
44  local_settings.y2 = height * local_settings.fac_y2;
45  }
46  if (width <= local_settings.x1 + 1) {
47  local_settings.x1 = width - 1;
48  }
49  if (height <= local_settings.y1 + 1) {
50  local_settings.y1 = height - 1;
51  }
52  if (width <= local_settings.x2 + 1) {
53  local_settings.x2 = width - 1;
54  }
55  if (height <= local_settings.y2 + 1) {
56  local_settings.y2 = height - 1;
57  }
58 
59  this->m_xmax = MAX2(local_settings.x1, local_settings.x2) + 1;
60  this->m_xmin = MIN2(local_settings.x1, local_settings.x2);
61  this->m_ymax = MAX2(local_settings.y1, local_settings.y2) + 1;
62  this->m_ymin = MIN2(local_settings.y1, local_settings.y2);
63  }
64  else {
65  this->m_xmax = 0;
66  this->m_xmin = 0;
67  this->m_ymax = 0;
68  this->m_ymin = 0;
69  }
70 }
71 
73 {
74  this->m_inputOperation = this->getInputSocketReader(0);
75  updateArea();
76 }
77 
79 {
80  this->m_inputOperation = nullptr;
81 }
82 
84 {
85  /* pass */
86 }
87 
88 void CropOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
89 {
90  if ((x < this->m_xmax && x >= this->m_xmin) && (y < this->m_ymax && y >= this->m_ymin)) {
91  this->m_inputOperation->readSampled(output, x, y, sampler);
92  }
93  else {
94  zero_v4(output);
95  }
96 }
97 
99 {
100  /* pass */
101 }
102 
104  ReadBufferOperation *readOperation,
105  rcti *output)
106 {
107  rcti newInput;
108 
109  newInput.xmax = input->xmax + this->m_xmin;
110  newInput.xmin = input->xmin + this->m_xmin;
111  newInput.ymax = input->ymax + this->m_ymin;
112  newInput.ymin = input->ymin + this->m_ymin;
113 
114  return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
115 }
116 
117 void CropImageOperation::determineResolution(unsigned int resolution[2],
118  unsigned int preferredResolution[2])
119 {
120  NodeOperation::determineResolution(resolution, preferredResolution);
121  updateArea();
122  resolution[0] = this->m_xmax - this->m_xmin;
123  resolution[1] = this->m_ymax - this->m_ymin;
124 }
125 
127  float x,
128  float y,
129  PixelSampler sampler)
130 {
131  if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
132  this->m_inputOperation->readSampled(output, (x + this->m_xmin), (y + this->m_ymin), sampler);
133  }
134  else {
135  zero_v4(output);
136  }
137 }
138 
139 } // namespace blender::compositor
MINLINE void zero_v4(float r[4])
#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 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
_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
#define output
void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) override
determine the resolution of this node
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) override
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
NodeOperation contains calculation logic.
void readSampled(float result[4], float x, float y, PixelSampler sampler)
void addInputSocket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
void addOutputSocket(DataType datatype)
virtual void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
determine the resolution of this node
SocketReader * getInputSocketReader(unsigned int inputSocketindex)
virtual bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
@ None
The bottom left of the input image is the bottom left of the working area of the node,...
int ymin
Definition: DNA_vec_types.h:80
int ymax
Definition: DNA_vec_types.h:80
int xmin
Definition: DNA_vec_types.h:79
int xmax
Definition: DNA_vec_types.h:79