Blender V4.3
COM_BrightnessOperation.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 "BLI_math_color.h"
8
9namespace blender::compositor {
10
20
22{
23 use_premultiply_ = use_premultiply;
24}
25
27 const rcti &area,
29{
30 float tmp_color[4];
31 for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
32 const float *in_color = it.in(0);
33 const float brightness = *it.in(1) / 100.0f;
34 const float contrast = *it.in(2);
35 float delta = contrast / 200.0f;
36 /*
37 * The algorithm is by Werner D. Streidt
38 * (http://visca.com/ffactory/archives/5-99/msg00021.html)
39 * Extracted of OpenCV `demhist.c`.
40 */
41 float a, b;
42 if (contrast > 0) {
43 a = 1.0f - delta * 2.0f;
44 a = 1.0f / max_ff(a, FLT_EPSILON);
45 b = a * (brightness - delta);
46 }
47 else {
48 delta *= -1;
49 a = max_ff(1.0f - delta * 2.0f, 0.0f);
50 b = a * brightness + delta;
51 }
52 const float *color;
53 if (use_premultiply_) {
54 premul_to_straight_v4_v4(tmp_color, in_color);
55 color = tmp_color;
56 }
57 else {
58 color = in_color;
59 }
60 it.out[0] = a * color[0] + b;
61 it.out[1] = a * color[1] + b;
62 it.out[2] = a * color[2] + b;
63 it.out[3] = color[3];
64 if (use_premultiply_) {
66 }
67 }
68}
69
70} // namespace blender::compositor
MINLINE float max_ff(float a, float b)
MINLINE void straight_to_premul_v4(float color[4])
MINLINE void premul_to_straight_v4_v4(float straight[4], const float premul[4])
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
a MemoryBuffer contains access to the data
void add_output_socket(DataType datatype)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
local_group_size(16, 16) .push_constant(Type b
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator