Blender V5.0
sequencer_scopes.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006-2008 Peter Schlaile < peter [at] schlaile [dot] de >.
2 * SPDX-FileCopyrightText: 2025 Blender Authors
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later */
5
9
10#include "BLI_math_vector.hh"
11#include "BLI_task.hh"
12
14#include "IMB_imbuf.hh"
15
16#include "sequencer_scopes.hh"
17
18namespace blender::ed::vse {
19
24
26{
27 histogram.data.reinitialize(0);
28 last_ibuf = nullptr;
30}
31
33 const ColorSpace *src_colorspace,
35{
37 &pixels.data()->x, pixels.size(), 1, 4, src_colorspace, false);
38 IMB_colormanagement_processor_apply(processor, &pixels.data()->x, pixels.size(), 1, 4, false);
39}
40
42 const ColorSpace *src_colorspace,
44 const float *src,
45 int64_t stride)
46{
48 for (int64_t i : result.index_range()) {
50 src += stride;
51 }
52 rgba_float_to_display_space(processor, src_colorspace, result);
53 return result;
54}
55
57 const ColorSpace *src_colorspace,
59 const uchar *src,
60 int64_t stride)
61{
63 for (int64_t i : result.index_range()) {
65 src += stride;
66 }
67 rgba_float_to_display_space(processor, src_colorspace, result);
68 return result;
69}
70
72 const ColorManagedViewSettings &view_settings,
73 const ColorManagedDisplaySettings &display_settings)
74{
76 ibuf, &view_settings, &display_settings);
77
78 const bool is_float = ibuf->float_buffer.data != nullptr;
79 const int hist_size = is_float ? BINS_HDR : BINS_01;
80
81 /* Calculate histogram of input image with parallel reduction:
82 * process in chunks, and merge their histograms. */
83 Array<uint3> counts(hist_size, uint3(0));
86 16 * 1024,
87 counts,
88 [&](const IndexRange range, const Array<uint3> &init) {
89 Array<uint3> res = init;
90
91 if (is_float) {
92 const float *src = ibuf->float_buffer.data + range.first() * 4;
93 if (!cm_processor) {
94 /* Float image, no color space conversions needed. */
95 for ([[maybe_unused]] const int64_t index : range) {
96 float4 pixel;
97 premul_to_straight_v4_v4(pixel, src);
98 res[float_to_bin(pixel.x)].x++;
99 res[float_to_bin(pixel.y)].y++;
100 res[float_to_bin(pixel.z)].z++;
101 src += 4;
102 }
103 }
104 else {
105 /* Float image, with color space conversions. */
107 cm_processor, ibuf->float_buffer.colorspace, range.size(), src, 4);
108 for (const float4 &pixel : pixels) {
109 res[float_to_bin(pixel.x)].x++;
110 res[float_to_bin(pixel.y)].y++;
111 res[float_to_bin(pixel.z)].z++;
112 }
113 }
114 }
115 else {
116 /* Byte images just use 256 histogram bins, directly indexed by value. */
117 const uchar *src = ibuf->byte_buffer.data + range.first() * 4;
118 if (!cm_processor) {
119 /* Byte image, no color space conversions needed. */
120 for ([[maybe_unused]] const int64_t index : range) {
121 res[src[0]].x++;
122 res[src[1]].y++;
123 res[src[2]].z++;
124 src += 4;
125 }
126 }
127 else {
128 /* Byte image, with color space conversions. */
130 cm_processor, ibuf->byte_buffer.colorspace, range.size(), src, 4);
131 for (const float4 &pixel : pixels) {
132 uchar pixel_b[4];
133 rgba_float_to_uchar(pixel_b, pixel);
134 res[pixel_b[0]].x++;
135 res[pixel_b[1]].y++;
136 res[pixel_b[2]].z++;
137 }
138 }
139 }
140 return res;
141 },
142 /* Merge histograms computed per-thread. */
143 [&](const Array<uint3> &a, const Array<uint3> &b) {
144 BLI_assert(a.size() == b.size());
145 Array<uint3> res(a.size());
146 for (int i = 0; i < a.size(); i++) {
147 res[i] = a[i] + b[i];
148 }
149 return res;
150 });
151
152 if (cm_processor) {
154 }
155
156 max_value = uint3(0);
157 max_bin = uint3(0);
158 for (int64_t i : data.index_range()) {
159 const uint3 &val = data[i];
161 if (val.x != 0) {
162 max_bin.x = i;
163 }
164 if (val.y != 0) {
165 max_bin.y = i;
166 }
167 if (val.z != 0) {
168 max_bin.z = i;
169 }
170 }
171}
172
173} // namespace blender::ed::vse
blender::ocio::ColorSpace ColorSpace
Definition BLF_api.hh:38
#define BLI_assert(a)
Definition BLI_assert.h:46
MINLINE void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
MINLINE void premul_to_straight_v4_v4(float straight[4], const float premul[4])
ATTR_WARN_UNUSED_RESULT const size_t num
unsigned char uchar
void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, const ColorSpace *colorspace, bool predivide)
void IMB_colormanagement_processor_apply(ColormanageProcessor *cm_processor, float *buffer, int width, int height, int channels, bool predivide)
ColormanageProcessor * IMB_colormanagement_display_processor_for_imbuf(const ImBuf *ibuf, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, const ColorManagedDisplaySpace display_space=DISPLAY_SPACE_DRAW)
void IMB_colormanagement_processor_free(ColormanageProcessor *cm_processor)
size_t IMB_get_pixel_count(const ImBuf *ibuf)
Get the length of the data of the given image buffer in pixels.
long long int int64_t
int64_t size() const
Definition BLI_array.hh:256
constexpr int64_t first() const
constexpr int64_t size() const
constexpr int64_t size() const
Definition BLI_span.hh:493
constexpr T * data() const
Definition BLI_span.hh:539
static void rgba_float_to_display_space(ColormanageProcessor *processor, const ColorSpace *src_colorspace, MutableSpan< float4 > pixels)
static Array< float4 > pixels_to_display_space(ColormanageProcessor *processor, const ColorSpace *src_colorspace, int64_t num, const float *src, int64_t stride)
T max(const T &a, const T &b)
Value parallel_reduce(IndexRange range, int64_t grain_size, const Value &identity, const Function &function, const Reduction &reduction)
Definition BLI_task.hh:151
VecBase< uint32_t, 3 > uint3
VecBase< float, 4 > float4
static void init(bNodeTree *, bNode *node)
const ColorSpace * colorspace
const ColorSpace * colorspace
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
void calc_from_ibuf(const ImBuf *ibuf, const ColorManagedViewSettings &view_settings, const ColorManagedDisplaySettings &display_settings)
i
Definition text_draw.cc:230