Blender V5.3
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
34 const float *src,
35 int64_t stride)
36{
38 for (int64_t i : result.index_range()) {
40 src += stride;
41 }
42 processor.apply(&result.data()->x, result.size(), 1, 4, false);
43 return result;
44}
45
48 const uchar *src,
49 int64_t stride)
50{
52 for (int64_t i : result.index_range()) {
54 src += stride;
55 }
56 processor.apply(&result.data()->x, result.size(), 1, 4, false);
57 return result;
58}
59
61 const ColorManagedViewSettings &view_settings,
62 const ColorManagedDisplaySettings &display_settings)
63{
64 /* Use scope space so that the histogram matches the waveform/parade encoding,
65 * with proper HDR and wide gamut handling. */
66 std::optional<ColormanageProcessor> cm_processor =
68 ibuf, &view_settings, &display_settings, DISPLAY_SPACE_SCOPE);
69
70 /* Calculate histogram of input image with parallel reduction:
71 * process in chunks, and merge their histograms. */
72 Array<uint3> counts(NUM_BINS, uint3(0));
75 16 * 1024,
76 counts,
77 [&](const IndexRange range, const Array<uint3> &init) {
78 Array<uint3> res = init;
79
80 if (ibuf->float_data()) {
81 const float *src = ibuf->float_data() + range.first() * 4;
82 if (!cm_processor) {
83 for ([[maybe_unused]] const int64_t index : range) {
84 float4 pixel;
85 premul_to_straight_v4_v4(pixel, src);
86 res[float_to_bin(pixel.x)].x++;
87 res[float_to_bin(pixel.y)].y++;
88 res[float_to_bin(pixel.z)].z++;
89 src += 4;
90 }
91 }
92 else {
94 cm_processor.value(), range.size(), src, 4);
95 for (const float4 &pixel : pixels) {
96 res[float_to_bin(pixel.x)].x++;
97 res[float_to_bin(pixel.y)].y++;
98 res[float_to_bin(pixel.z)].z++;
99 }
100 }
101 }
102 else {
103 const uchar *src = ibuf->byte_data() + range.first() * 4;
104 if (!cm_processor) {
105 for ([[maybe_unused]] const int64_t index : range) {
106 float4 pixel;
107 rgba_uchar_to_float(pixel, src);
108 res[float_to_bin(pixel.x)].x++;
109 res[float_to_bin(pixel.y)].y++;
110 res[float_to_bin(pixel.z)].z++;
111 src += 4;
112 }
113 }
114 else {
116 cm_processor.value(), range.size(), src, 4);
117 for (const float4 &pixel : pixels) {
118 res[float_to_bin(pixel.x)].x++;
119 res[float_to_bin(pixel.y)].y++;
120 res[float_to_bin(pixel.z)].z++;
121 }
122 }
123 }
124 return res;
125 },
126 /* Merge histograms computed per-thread. */
127 [&](const Array<uint3> &a, const Array<uint3> &b) {
128 BLI_assert(a.size() == b.size());
129 Array<uint3> res(a.size());
130 for (int i = 0; i < a.size(); i++) {
131 res[i] = a[i] + b[i];
132 }
133 return res;
134 });
135
136 max_value = uint3(0);
137 for (int64_t i : data.index_range()) {
139 }
140}
141
142} // namespace blender::ed::vse
int64_t size() const
Definition BLI_array.hh:267
void apply(float *buffer, int width, int height, int channels, bool predivide) const
static std::optional< ColormanageProcessor > display_processor_for_imbuf(const ImBuf *ibuf, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, ColorManagedDisplaySpace display_space=DISPLAY_SPACE_DRAW)
constexpr int64_t first() const
constexpr int64_t size() const
constexpr IndexRange()=default
static Array< float4 > pixels_to_scope_space(const ColormanageProcessor &processor, 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:127
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
size_t IMB_get_pixel_count(const ImBuf *ibuf)
Get the length of the data of the given image buffer in pixels.
VecBase< uint32_t, 3 > uint3
VecBase< float, 4 > float4
unsigned char uchar
Definition BKE_text.h:58
ATTR_WARN_UNUSED_RESULT const size_t num
MINLINE void premul_to_straight_v4_v4(float straight[4], const float premul[4])
const uint8_t * byte_data() const
const float * float_data() const
void calc_from_ibuf(const ImBuf *ibuf, const ColorManagedViewSettings &view_settings, const ColorManagedDisplaySettings &display_settings)