62 float r = rgb[0], g = rgb[1],
b = rgb[2];
64 float u = -0.09991f * r - 0.33609f * g + 0.436f *
b;
65 float v = 0.615f * r - 0.55861f * g - 0.05639f *
b;
86 uint other = newval * 31 / 32;
87 other = (other * other) >> 8;
88 other = (other * other) >> 8;
103 float alpha =
clamp_f(
ratiof(360.0f, 2160.0f, height), 0.0f, 1.0f);
104 float gamma =
interpf(0.9f, 0.3f, alpha);
105 for (
int x = 0;
x < 256;
x++) {
106 wtable[
x] =
uchar(
pow((
float(
x) + 1.0f) / 256.0f, gamma) * 255.0f);
115 const int w = ibuf->
x;
127 const int muls[3] = {int(coeffs[0] * 65535), int(coeffs[1] * 65535), int(coeffs[2] * 65535)};
131 if (ibuf->float_buffer.data) {
133 const float *src = ibuf->float_buffer.data;
134 for (int y = 0; y < ibuf->y; y++) {
135 for (const int x : x_range) {
136 const float *rgb = src + 4 * (ibuf->x * y + x);
137 float v = IMB_colormanagement_get_luminance(rgb);
140 int iv = clamp_i(int(v * h), 0, h - 1);
142 p += 4 * (w * iv + x);
143 scope_put_pixel(wtable, p);
149 const uchar *src = ibuf->byte_buffer.data;
150 for (int y = 0; y < ibuf->y; y++) {
151 for (const int x : x_range) {
152 const uchar *rgb = src + 4 * (ibuf->x * y + x);
154 int rgb0 = rgb[0] + 1;
155 int rgb1 = rgb[1] + 1;
156 int rgb2 = rgb[2] + 1;
157 int luma = (rgb0 * muls[0] + rgb1 * muls[1] + rgb2 * muls[2]) >> 16;
158 int luma_y = clamp_i(luma, 0, 255);
159 uchar *p = tgt + 4 * (w * luma_y + x);
160 scope_put_pixel(wtable, p);
178 int sw = ibuf->
x / 3;
185 if (ibuf->float_buffer.data) {
187 const float *src = ibuf->float_buffer.data;
188 for (int y = 0; y < ibuf->y; y++) {
189 for (const int x : x_range) {
190 const float *rgb = src + 4 * (ibuf->x * y + x);
191 for (int c = 0; c < 3; c++) {
194 int iv = clamp_i(int(v * h), 0, h - 1);
196 p += 4 * (w * iv + c * sw + x / 3);
197 scope_put_pixel_single(wtable, p, c);
204 const uchar *src = ibuf->byte_buffer.data;
205 for (int y = 0; y < ibuf->y; y++) {
206 for (const int x : x_range) {
207 const uchar *rgb = src + 4 * (ibuf->x * y + x);
208 for (int c = 0; c < 3; c++) {
210 p += 4 * (w * rgb[c] + c * sw + x / 3);
211 scope_put_pixel_single(wtable, p, c);
229 if (ibuf->float_buffer.data) {
231 const float limit = perc / 100.0f;
232 const float *p = ibuf->float_buffer.data + y_range.first() * ibuf->x * 4;
233 uchar *o = res->byte_buffer.data + y_range.first() * ibuf->x * 4;
234 for (const int y : y_range) {
235 for (int x = 0; x < ibuf->x; x++) {
237 memcpy(pix, p, sizeof(pix));
238 if (pix[0] >= limit || pix[1] >= limit || pix[2] >= limit) {
239 if (((x + y) & 0x08) != 0) {
240 pix[0] = 1.0f - pix[0];
241 pix[1] = 1.0f - pix[1];
242 pix[2] = 1.0f - pix[2];
245 rgba_float_to_uchar(o, pix);
253 const uint limit = 255.0f * perc / 100.0f;
254 const uchar *p = ibuf->byte_buffer.data + y_range.first() * ibuf->x * 4;
255 uchar *o = res->byte_buffer.data + y_range.first() * ibuf->x * 4;
256 for (const int y : y_range) {
257 for (int x = 0; x < ibuf->x; x++) {
259 memcpy(pix, p, sizeof(pix));
261 if (pix[0] >= limit || pix[1] >= limit || pix[2] >= limit) {
262 if (((x + y) & 0x08) != 0) {
263 pix[0] = 255 - pix[0];
264 pix[1] = 255 - pix[1];
265 pix[2] = 255 - pix[2];
268 memcpy(o, pix, sizeof(pix));
301 Array<uint3> res = init;
304 for (const int y : y_range) {
305 const float *src = ibuf->float_buffer.data + y * ibuf->x * 4;
306 for (int x = 0; x < ibuf->x; x++) {
307 res[get_bin_float(src[0])].x++;
308 res[get_bin_float(src[1])].y++;
309 res[get_bin_float(src[2])].z++;
316 for (const int y : y_range) {
317 const uchar *src = ibuf->byte_buffer.data + y * ibuf->x * 4;
318 for (int x = 0; x < ibuf->x; x++) {
331 for (
int i = 0;
i < a.
size();
i++) {
332 res[
i] = a[
i] +
b[
i];
337 max_value =
uint3(0);
348 const int size = 512;
349 const float size_mul =
size - 1.0f;
361 for (
int y = 0;
y < ibuf->
y;
y++) {
362 for (
int x = 0;
x < ibuf->
x;
x++) {
363 memcpy(rgb, src,
sizeof(
float[3]));
368 uchar *p = dst + 4 * (
size * int(uv.y) + int(uv.x));
378 for (
int y = 0;
y < ibuf->
y;
y++) {
379 for (
int x = 0;
x < ibuf->
x;
x++) {
380 rgb[0] = float(src[0]) * (1.0f / 255.0f);
381 rgb[1] = float(src[1]) * (1.0f / 255.0f);
382 rgb[2] = float(src[2]) * (1.0f / 255.0f);
386 uchar *p = dst + 4 * (
size * int(uv.y) + int(uv.x));
MINLINE float clamp_f(float value, float min, float max)
MINLINE float interpf(float target, float origin, float t)
MINLINE int clamp_i(int value, int min, int max)
MINLINE float ratiof(float min, float max, float pos)
MINLINE void clamp_v3(float vec[3], float min, float max)
#define SCOPED_TIMER(name)
BLI_INLINE void IMB_colormanagement_get_luminance_coefficients(float r_rgb[3])
void IMB_freeImBuf(ImBuf *ibuf)
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
@ IB_uninitialized_pixels
BMesh const char void * data
ATTR_WARN_UNUSED_RESULT const BMVert * v
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
ImBuf * make_waveform_view_from_ibuf(const ImBuf *ibuf)
ImBuf * make_vectorscope_view_from_ibuf(const ImBuf *ibuf)
static void init_wave_table(int height, uchar wtable[256])
ImBuf * make_sep_waveform_view_from_ibuf(const ImBuf *ibuf)
ImBuf * make_zebra_view_from_ibuf(const ImBuf *ibuf, float perc)
static void scope_put_pixel(const uchar *table, uchar *pos)
static blender::float2 rgb_to_uv_normalized(const float rgb[3])
static void scope_put_pixel_single(const uchar *table, uchar *pos, int col)
T midpoint(const T &a, const T &b)
T max(const T &a, const T &b)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Value parallel_reduce(IndexRange range, int64_t grain_size, const Value &identity, const Function &function, const Reduction &reduction)
VecBase< uint32_t, 3 > uint3
VecBase< float, 2 > float2
static void init(bNodeTree *, bNode *node)
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
static constexpr int BINS_BYTE
static constexpr float FLOAT_VAL_MAX
static constexpr float FLOAT_VAL_MIN
void calc_from_ibuf(const ImBuf *ibuf)
static constexpr int BINS_FLOAT
static constexpr float VECSCOPE_V_SCALE
const ImBuf * reference_ibuf
static constexpr float VECSCOPE_U_SCALE
ImBuf * sep_waveform_ibuf