Blender  V3.3
COM_BrightnessOperation.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 namespace blender::compositor {
7 
9 {
14  input_program_ = nullptr;
15  use_premultiply_ = false;
16  flags_.can_be_constant = true;
17 }
18 
19 void BrightnessOperation::set_use_premultiply(bool use_premultiply)
20 {
21  use_premultiply_ = use_premultiply;
22 }
23 
25 {
26  input_program_ = this->get_input_socket_reader(0);
27  input_brightness_program_ = this->get_input_socket_reader(1);
28  input_contrast_program_ = this->get_input_socket_reader(2);
29 }
30 
32  float x,
33  float y,
35 {
36  float input_value[4];
37  float a, b;
38  float input_brightness[4];
39  float input_contrast[4];
40  input_program_->read_sampled(input_value, x, y, sampler);
41  input_brightness_program_->read_sampled(input_brightness, x, y, sampler);
42  input_contrast_program_->read_sampled(input_contrast, x, y, sampler);
43  float brightness = input_brightness[0];
44  float contrast = input_contrast[0];
45  brightness /= 100.0f;
46  float delta = contrast / 200.0f;
47  /*
48  * The algorithm is by Werner D. Streidt
49  * (http://visca.com/ffactory/archives/5-99/msg00021.html)
50  * Extracted of OpenCV demhist.c
51  */
52  if (contrast > 0) {
53  a = 1.0f - delta * 2.0f;
54  a = 1.0f / max_ff(a, FLT_EPSILON);
55  b = a * (brightness - delta);
56  }
57  else {
58  delta *= -1;
59  a = max_ff(1.0f - delta * 2.0f, 0.0f);
60  b = a * brightness + delta;
61  }
62  if (use_premultiply_) {
63  premul_to_straight_v4(input_value);
64  }
65  output[0] = a * input_value[0] + b;
66  output[1] = a * input_value[1] + b;
67  output[2] = a * input_value[2] + b;
68  output[3] = input_value[3];
69  if (use_premultiply_) {
71  }
72 }
73 
75  const rcti &area,
77 {
78  float tmp_color[4];
79  for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
80  const float *in_color = it.in(0);
81  const float brightness = *it.in(1) / 100.0f;
82  const float contrast = *it.in(2);
83  float delta = contrast / 200.0f;
84  /*
85  * The algorithm is by Werner D. Streidt
86  * (http://visca.com/ffactory/archives/5-99/msg00021.html)
87  * Extracted of OpenCV demhist.c
88  */
89  float a, b;
90  if (contrast > 0) {
91  a = 1.0f - delta * 2.0f;
92  a = 1.0f / max_ff(a, FLT_EPSILON);
93  b = a * (brightness - delta);
94  }
95  else {
96  delta *= -1;
97  a = max_ff(1.0f - delta * 2.0f, 0.0f);
98  b = a * brightness + delta;
99  }
100  const float *color;
101  if (use_premultiply_) {
102  premul_to_straight_v4_v4(tmp_color, in_color);
103  color = tmp_color;
104  }
105  else {
106  color = in_color;
107  }
108  it.out[0] = a * color[0] + b;
109  it.out[1] = a * color[1] + b;
110  it.out[2] = a * color[2] + b;
111  it.out[3] = color[3];
112  if (use_premultiply_) {
113  straight_to_premul_v4(it.out);
114  }
115  }
116 }
117 
119 {
120  input_program_ = nullptr;
121  input_brightness_program_ = nullptr;
122  input_contrast_program_ = nullptr;
123 }
124 
125 } // namespace blender::compositor
MINLINE float max_ff(float a, float b)
MINLINE void premul_to_straight_v4(float color[4])
MINLINE void straight_to_premul_v4(float color[4])
MINLINE void premul_to_straight_v4_v4(float straight[4], const float premul[4])
_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
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
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
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)
depth_tx sampler(1, ImageType::FLOAT_2D, "combined_tx") .sampler(2
ccl_global KernelShaderEvalInput ccl_global float * output
static unsigned a[3]
Definition: RandGen.cpp:78
static void area(int d1, int d2, int e1, int e2, float weights[2])
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static bNodeSocketTemplate inputs[]