Blender V4.3
COM_MapRangeOperation.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2012 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7namespace blender::compositor {
8
20
21/* The code below assumes all data is inside range +- this, and that input buffer is single channel
22 */
23#define BLENDER_ZMAX 10000.0f
24
26 const rcti &area,
28{
29 for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
30 const float source_min = *it.in(1);
31 const float source_max = *it.in(2);
32 if (fabsf(source_max - source_min) < 1e-6f) {
33 it.out[0] = 0.0f;
34 continue;
35 }
36
37 float value = *it.in(0);
38 const float dest_min = *it.in(3);
39 const float dest_max = *it.in(4);
40 if (value >= -BLENDER_ZMAX && value <= BLENDER_ZMAX) {
41 value = (value - source_min) / (source_max - source_min);
42 value = dest_min + value * (dest_max - dest_min);
43 }
44 else if (value > BLENDER_ZMAX) {
45 value = dest_max;
46 }
47 else {
48 value = dest_min;
49 }
50
51 if (use_clamp_) {
52 if (dest_max > dest_min) {
53 CLAMP(value, dest_min, dest_max);
54 }
55 else {
56 CLAMP(value, dest_max, dest_min);
57 }
58 }
59
60 it.out[0] = value;
61 }
62}
63
64} // namespace blender::compositor
#define CLAMP(a, b, c)
#define BLENDER_ZMAX
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)
#define fabsf(x)
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator