Blender  V3.3
COM_ColorCurveOperation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
5 
6 #include "BKE_colortools.h"
7 
8 namespace blender::compositor {
9 
11 {
17 
18  input_fac_program_ = nullptr;
19  input_image_program_ = nullptr;
20  input_black_program_ = nullptr;
21  input_white_program_ = nullptr;
22 
23  this->set_canvas_input_index(1);
24 }
26 {
28  input_fac_program_ = this->get_input_socket_reader(0);
29  input_image_program_ = this->get_input_socket_reader(1);
30  input_black_program_ = this->get_input_socket_reader(2);
31  input_white_program_ = this->get_input_socket_reader(3);
32 
34 }
35 
37  float x,
38  float y,
40 {
42 
43  float fac[4];
44  float image[4];
45 
46  /* local versions of cumap->black, cumap->white, cumap->bwmul */
47  float black[4];
48  float white[4];
49  float bwmul[3];
50 
51  input_black_program_->read_sampled(black, x, y, sampler);
52  input_white_program_->read_sampled(white, x, y, sampler);
53 
54  /* get our own local bwmul value,
55  * since we can't be threadsafe and use cumap->bwmul & friends */
56  BKE_curvemapping_set_black_white_ex(black, white, bwmul);
57 
58  input_fac_program_->read_sampled(fac, x, y, sampler);
59  input_image_program_->read_sampled(image, x, y, sampler);
60 
61  if (*fac >= 1.0f) {
63  }
64  else if (*fac <= 0.0f) {
66  }
67  else {
68  float col[4];
69  BKE_curvemapping_evaluate_premulRGBF_ex(cumap, col, image, black, bwmul);
70  interp_v3_v3v3(output, image, col, *fac);
71  }
72  output[3] = image[3];
73 }
74 
76 {
78  input_fac_program_ = nullptr;
79  input_image_program_ = nullptr;
80  input_black_program_ = nullptr;
81  input_white_program_ = nullptr;
82 }
83 
85  const rcti &area,
87 {
89  float bwmul[3];
90  for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
91  /* Local versions of `cumap->black` and `cumap->white`. */
92  const float *black = it.in(2);
93  const float *white = it.in(3);
94  /* Get a local `bwmul` value, it's not threadsafe using `cumap->bwmul` and others. */
95  BKE_curvemapping_set_black_white_ex(black, white, bwmul);
96 
97  const float fac = *it.in(0);
98  const float *image = it.in(1);
99  if (fac >= 1.0f) {
100  BKE_curvemapping_evaluate_premulRGBF_ex(cumap, it.out, image, black, bwmul);
101  }
102  else if (fac <= 0.0f) {
103  copy_v3_v3(it.out, image);
104  }
105  else {
106  float col[4];
107  BKE_curvemapping_evaluate_premulRGBF_ex(cumap, col, image, black, bwmul);
108  interp_v3_v3v3(it.out, image, col, fac);
109  }
110  it.out[3] = image[3];
111  }
112 }
113 
114 /* Constant level curve mapping. */
115 
117 {
121 
122  input_fac_program_ = nullptr;
123  input_image_program_ = nullptr;
124 
125  this->set_canvas_input_index(1);
126 }
128 {
130  input_fac_program_ = this->get_input_socket_reader(0);
131  input_image_program_ = this->get_input_socket_reader(1);
132 
134 
136 }
137 
139  float x,
140  float y,
142 {
143  float fac[4];
144  float image[4];
145 
146  input_fac_program_->read_sampled(fac, x, y, sampler);
147  input_image_program_->read_sampled(image, x, y, sampler);
148 
149  if (*fac >= 1.0f) {
151  }
152  else if (*fac <= 0.0f) {
154  }
155  else {
156  float col[4];
158  interp_v3_v3v3(output, image, col, *fac);
159  }
160  output[3] = image[3];
161 }
162 
164 {
166  input_fac_program_ = nullptr;
167  input_image_program_ = nullptr;
168 }
169 
171  const rcti &area,
173 {
174  CurveMapping *cumap = curve_mapping_;
175  for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
176  const float fac = *it.in(0);
177  const float *image = it.in(1);
178  if (fac >= 1.0f) {
180  }
181  else if (fac <= 0.0f) {
182  copy_v3_v3(it.out, image);
183  }
184  else {
185  float col[4];
187  interp_v3_v3v3(it.out, image, col, fac);
188  }
189  it.out[3] = image[3];
190  }
191 }
192 
193 } // namespace blender::compositor
void BKE_curvemapping_evaluate_premulRGBF_ex(const struct CurveMapping *cumap, float vecout[3], const float vecin[3], const float black[3], const float bwmul[3])
void BKE_curvemapping_evaluate_premulRGBF(const struct CurveMapping *cumap, float vecout[3], const float vecin[3])
void BKE_curvemapping_premultiply(struct CurveMapping *cumap, bool restore)
Definition: colortools.c:782
void BKE_curvemapping_set_black_white(struct CurveMapping *cumap, const float black[3], const float white[3])
Definition: colortools.c:152
void BKE_curvemapping_set_black_white_ex(const float black[3], const float white[3], float r_bwmul[3])
Definition: colortools.c:140
MINLINE void copy_v3_v3(float r[3], const float a[3])
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
Definition: math_vector.c:29
_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
void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
a MemoryBuffer contains access to the data of a chunk
void add_output_socket(DataType datatype)
SocketReader * get_input_socket_reader(unsigned int index)
void read_sampled(float result[4], float x, float y, PixelSampler sampler)
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
depth_tx sampler(1, ImageType::FLOAT_2D, "combined_tx") .sampler(2
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img image(1, GPU_R32F, Qualifier::WRITE, ImageType::FLOAT_2D_ARRAY, "out_weight_img") .image(3
uint col
ccl_global KernelShaderEvalInput ccl_global float * output
static void area(int d1, int d2, int e1, int e2, float weights[2])
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
static bNodeSocketTemplate inputs[]