61 float r = rgb[0], g = rgb[1],
b = rgb[2];
63 float u = -0.09991f * r - 0.33609f * g + 0.436f *
b;
64 float v = 0.615f * r - 0.55861f * g - 0.05639f *
b;
67 u =
clamp_f(u * (0.5f / 0.615f) + 0.5f, 0.0f, 1.0f);
68 v =
clamp_f(
v * (0.5f / 0.615f) + 0.5f, 0.0f, 1.0f);
85 uint other = newval * 31 / 32;
86 other = (other * other) >> 8;
87 other = (other * other) >> 8;
102 float alpha =
clamp_f(
ratiof(360.0f, 2160.0f, height), 0.0f, 1.0f);
103 float gamma =
interpf(0.9f, 0.3f, alpha);
104 for (
int x = 0; x < 256; x++) {
105 wtable[
x] =
uchar(
pow((
float(x) + 1.0f) / 256.0f, gamma) * 255.0f);
114 const int w = ibuf->
x;
126 const int muls[3] = {
int(coeffs[0] * 65535),
int(coeffs[1] * 65535),
int(coeffs[2] * 65535)};
130 if (ibuf->float_buffer.data) {
132 const float *src = ibuf->float_buffer.data;
133 for (int y = 0; y < ibuf->y; y++) {
134 for (const int x : x_range) {
135 const float *rgb = src + 4 * (ibuf->x * y + x);
136 float v = IMB_colormanagement_get_luminance(rgb);
139 int iv = clamp_i(int(v * h), 0, h - 1);
141 p += 4 * (w * iv + x);
142 scope_put_pixel(wtable, p);
148 const uchar *src = ibuf->byte_buffer.data;
149 for (int y = 0; y < ibuf->y; y++) {
150 for (const int x : x_range) {
151 const uchar *rgb = src + 4 * (ibuf->x * y + x);
153 int rgb0 = rgb[0] + 1;
154 int rgb1 = rgb[1] + 1;
155 int rgb2 = rgb[2] + 1;
156 int luma = (rgb0 * muls[0] + rgb1 * muls[1] + rgb2 * muls[2]) >> 16;
157 int luma_y = clamp_i(luma, 0, 255);
158 uchar *p = tgt + 4 * (w * luma_y + x);
159 scope_put_pixel(wtable, p);
177 int sw = ibuf->
x / 3;
184 if (ibuf->float_buffer.data) {
186 const float *src = ibuf->float_buffer.data;
187 for (int y = 0; y < ibuf->y; y++) {
188 for (const int x : x_range) {
189 const float *rgb = src + 4 * (ibuf->x * y + x);
190 for (int c = 0; c < 3; c++) {
193 int iv = clamp_i(int(v * h), 0, h - 1);
195 p += 4 * (w * iv + c * sw + x / 3);
196 scope_put_pixel_single(wtable, p, c);
203 const uchar *src = ibuf->byte_buffer.data;
204 for (int y = 0; y < ibuf->y; y++) {
205 for (const int x : x_range) {
206 const uchar *rgb = src + 4 * (ibuf->x * y + x);
207 for (int c = 0; c < 3; c++) {
209 p += 4 * (w * rgb[c] + c * sw + x / 3);
210 scope_put_pixel_single(wtable, p, c);
228 if (ibuf->float_buffer.data) {
230 const float limit = perc / 100.0f;
231 const float *p = ibuf->float_buffer.data + y_range.first() * ibuf->x * 4;
232 uchar *o = res->byte_buffer.data + y_range.first() * ibuf->x * 4;
233 for (const int y : y_range) {
234 for (int x = 0; x < ibuf->x; x++) {
236 memcpy(pix, p, sizeof(pix));
237 if (pix[0] >= limit || pix[1] >= limit || pix[2] >= limit) {
238 if (((x + y) & 0x08) != 0) {
239 pix[0] = 1.0f - pix[0];
240 pix[1] = 1.0f - pix[1];
241 pix[2] = 1.0f - pix[2];
244 rgba_float_to_uchar(o, pix);
252 const uint limit = 255.0f * perc / 100.0f;
253 const uchar *p = ibuf->byte_buffer.data + y_range.first() * ibuf->x * 4;
254 uchar *o = res->byte_buffer.data + y_range.first() * ibuf->x * 4;
255 for (const int y : y_range) {
256 for (int x = 0; x < ibuf->x; x++) {
258 memcpy(pix, p, sizeof(pix));
260 if (pix[0] >= limit || pix[1] >= limit || pix[2] >= limit) {
261 if (((x + y) & 0x08) != 0) {
262 pix[0] = 255 - pix[0];
263 pix[1] = 255 - pix[1];
264 pix[2] = 255 - pix[2];
267 memcpy(o, pix, sizeof(pix));
279 int bin =
int(((f - ScopeHistogram::FLOAT_VAL_MIN) /
280 (ScopeHistogram::FLOAT_VAL_MAX - ScopeHistogram::FLOAT_VAL_MIN)) *
281 ScopeHistogram::BINS_FLOAT);
282 return clamp_i(bin, 0, ScopeHistogram::BINS_FLOAT - 1);
285void ScopeHistogram::calc_from_ibuf(
const ImBuf *ibuf)
292 const int hist_size = is_float ? BINS_FLOAT : BINS_BYTE;
300 Array<uint3> res = init;
303 for (const int y : y_range) {
304 const float *src = ibuf->float_buffer.data + y * ibuf->x * 4;
305 for (int x = 0; x < ibuf->x; x++) {
306 res[get_bin_float(src[0])].x++;
307 res[get_bin_float(src[1])].y++;
308 res[get_bin_float(src[2])].z++;
315 for (const int y : y_range) {
316 const uchar *src = ibuf->byte_buffer.data + y * ibuf->x * 4;
317 for (int x = 0; x < ibuf->x; x++) {
330 for (
int i = 0; i < a.size(); i++) {
331 res[i] = a[i] +
b[i];
336 max_value =
uint3(0);
337 for (
const uint3 &
v : data) {
347 const int size = 512;
348 const float size_mul = size - 1.0f;
360 for (
int y = 0; y < ibuf->
y; y++) {
361 for (
int x = 0; x < ibuf->
x; x++) {
362 memcpy(rgb, src,
sizeof(
float[3]));
367 uchar *p = dst + 4 * (size *
int(uv.y) +
int(uv.x));
377 for (
int y = 0; y < ibuf->
y; y++) {
378 for (
int x = 0; x < ibuf->
x; x++) {
379 rgb[0] =
float(src[0]) * (1.0f / 255.0f);
380 rgb[1] =
float(src[1]) * (1.0f / 255.0f);
381 rgb[2] =
float(src[2]) * (1.0f / 255.0f);
385 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])
Contains defines and structs used throughout the imbuf module.
@ IB_uninitialized_pixels
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
local_group_size(16, 16) .push_constant(Type b
pow(value.r - subtrahend, 2.0)") .do_static_compilation(true)
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
struct ImBuf * IMB_allocImBuf(unsigned int, unsigned int, unsigned char, unsigned int)
void IMB_freeImBuf(ImBuf *)
ImBuf * make_zebra_view_from_ibuf(const ImBuf *ibuf, float perc)
static void scope_put_pixel(const uchar *table, uchar *pos)
ImBuf * make_waveform_view_from_ibuf(const ImBuf *ibuf)
static void scope_put_pixel_single(const uchar *table, uchar *pos, int col)
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)
static blender::float2 rgb_to_uv_normalized(const float rgb[3])
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
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
ImBuf * sep_waveform_ibuf