VSE: Scopes improvements #116798

Merged
Aras Pranckevicius merged 13 commits from aras_p/blender:vse-scopes into main 2024-01-05 22:03:13 +01:00
4 changed files with 44 additions and 28 deletions
Showing only changes of commit d52353c550 - Show all commits

View File

@ -592,16 +592,17 @@ static void draw_vectorscope_graticule(SeqQuadsBatch &quads, const rctf &area)
const float h = BLI_rctf_size_y(&area);
const float centerx = BLI_rctf_cent_x(&area);
const float centery = BLI_rctf_cent_y(&area);
const float radius = ((w < h) ? w : h) * 0.5f * (0.5f / 0.615f);
const float rad_base = ((w < h) ? w : h) * 0.5f;
/* vectorscope image is scaled over YUV range, +/- (0.436, 0.615) */
const float rad_x = rad_base * (0.5f / 0.436f);
const float rad_y = rad_base * (0.5f / 0.615f);
/* center cross */
uchar col_grid[4] = {128, 128, 128, 96};
quads.add_line(centerx - radius * 0.1f, centery, centerx + radius * 0.1f, centery, col_grid);
quads.add_line(centerx, centery - radius * 0.1f, centerx, centery + radius * 0.1f, col_grid);
quads.add_line(centerx - rad_base * 0.1f, centery, centerx + rad_base * 0.1f, centery, col_grid);
quads.add_line(centerx, centery - rad_base * 0.1f, centerx, centery + rad_base * 0.1f, col_grid);
/* fully saturated vs "safe" (0.75) colored areas */
quads.draw();
GPU_blend(GPU_BLEND_ADDITIVE);
const float3 primaries[6] = {
{1, 0, 0},
{1, 1, 0},
@ -611,31 +612,33 @@ static void draw_vectorscope_graticule(SeqQuadsBatch &quads, const rctf &area)
{1, 0, 1},
};
float2 center{centerx, centery};
float2 rad_scale{rad_x * 2, rad_y * 2};
for (int i = 0; i < 6; i++) {
float3 prim0 = primaries[i];
float3 prim1 = primaries[(i + 1) % 6];
float3 safe0 = prim0 * 0.75f;
aras_p marked this conversation as resolved
Review

Use BLI_snprintf()

Use `BLI_snprintf()`
float3 safe1 = prim1 * 0.75f;
float2 uv0 = center + rgb_to_uv(prim0) * (radius * 2);
float2 uv1 = center + rgb_to_uv(prim1) * (radius * 2);
float2 uv2 = center + rgb_to_uv(safe0) * (radius * 2);
float2 uv3 = center + rgb_to_uv(safe1) * (radius * 2);
uchar col0[4] = {uchar(prim0.x * 255), uchar(prim0.y * 255), uchar(prim0.z * 255), 128};
uchar col1[4] = {uchar(prim1.x * 255), uchar(prim1.y * 255), uchar(prim1.z * 255), 128};
uchar col2[4] = {uchar(safe0.x * 255), uchar(safe0.y * 255), uchar(safe0.z * 255), 128};
uchar col3[4] = {uchar(safe1.x * 255), uchar(safe1.y * 255), uchar(safe1.z * 255), 128};
float2 uv0 = center + rgb_to_uv(prim0) * rad_scale;
float2 uv1 = center + rgb_to_uv(prim1) * rad_scale;
float2 uv2 = center + rgb_to_uv(safe0) * rad_scale;
float2 uv3 = center + rgb_to_uv(safe1) * rad_scale;
uchar col0[4] = {uchar(prim0.x * 255), uchar(prim0.y * 255), uchar(prim0.z * 255), 64};
uchar col1[4] = {uchar(prim1.x * 255), uchar(prim1.y * 255), uchar(prim1.z * 255), 64};
uchar col2[4] = {uchar(safe0.x * 255), uchar(safe0.y * 255), uchar(safe0.z * 255), 64};
uchar col3[4] = {uchar(safe1.x * 255), uchar(safe1.y * 255), uchar(safe1.z * 255), 64};
quads.add_quad(uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y, uv3.x, uv3.y, col0, col1, col2, col3);
col0[3] = col1[3] = col2[3] = col3[3] = 192;
quads.add_line(uv0.x, uv0.y, uv1.x, uv1.y, col0, col1);
quads.add_line(uv2.x, uv2.y, uv3.x, uv3.y, col2, col3);
}
quads.draw();
GPU_blend(GPU_BLEND_ALPHA);
/* skin tone line */
uchar col_tone[4] = {255, 102, 0, 128};
const float tone_line_len = radius * 0.895f; /* makes it end at outer edge of saturation ring */
const float tone_line_len = 0.895f; /* makes it end at outer edge of saturation ring */
quads.add_line(centerx,
centery,
centerx + cosf(skin_rad) * tone_line_len,
centery + sinf(skin_rad) * tone_line_len,
centerx + cosf(skin_rad) * rad_x * tone_line_len,
centery + sinf(skin_rad) * rad_y * tone_line_len,
col_tone);
}

View File

@ -150,7 +150,8 @@ void SeqQuadsBatch::add_wire_quad(float x1, float y1, float x2, float y2, const
lines_num += 4;
}
void SeqQuadsBatch::add_line(float x1, float y1, float x2, float y2, const uchar color[4])
void SeqQuadsBatch::add_line(
float x1, float y1, float x2, float y2, const uchar color1[4], const uchar color2[4])
{
if (lines_num + 1 > MAX_LINES) {
draw();
@ -160,8 +161,8 @@ void SeqQuadsBatch::add_line(float x1, float y1, float x2, float y2, const uchar
BLI_assert(verts_lines != nullptr);
}
ColorVertex v0 = {blender::float2(x1, y1), color};
ColorVertex v1 = {blender::float2(x2, y2), color};
ColorVertex v0 = {blender::float2(x1, y1), color1};
ColorVertex v1 = {blender::float2(x2, y2), color2};
*verts_lines++ = v0;
*verts_lines++ = v1;

View File

@ -63,8 +63,14 @@ class SeqQuadsBatch {
const uchar color4[4]);
/** Add four lines of an axis-aligned quad edges. */
void add_wire_quad(float x1, float y1, float x2, float y2, const uchar color[4]);
/** Add a line. */
void add_line(float x1, float y1, float x2, float y2, const uchar color[4]);
/** Add a line with single color. */
void add_line(float x1, float y1, float x2, float y2, const uchar color[4])
{
add_line(x1, y1, x2, y2, color, color);
}
/** Add a line with two endpoint colors. */
void add_line(
float x1, float y1, float x2, float y2, const uchar color1[4], const uchar color2[4]);
private:
static constexpr int MAX_QUADS = 1024;

View File

@ -56,12 +56,18 @@ void SeqScopes::cleanup()
static blender::float2 rgb_to_uv_normalized(const float rgb[3])
{
float3 yuv;
rgb_to_yuv(rgb[0], rgb[1], rgb[2], &yuv.x, &yuv.y, &yuv.z, BLI_YUV_ITU_BT709);
/* Exact same math as rgb_to_yuv BT709 case. Duplicated here
* since this function is called a lot, and non-inline function
* call plus colorspace switch in there overhead does add up. */
float r = rgb[0], g = rgb[1], b = rgb[2];
/* We don't need y. */
float u = -0.09991f * r - 0.33609f * g + 0.436f * b;
float v = 0.615f * r - 0.55861f * g - 0.05639f * b;
/* Normalize: UV range is +/- 0.615 */
float2 uv = yuv.yz() * (0.5f / 0.615f) + 0.5f;
return math::clamp(uv, 0.0f, 1.0f);
/* Normalize: (U, V) range is +/- (0.436, 0.615) */
u = clamp_f(u * (0.5f / 0.436f) + 0.5f, 0.0f, 1.0f);
v = clamp_f(v * (0.5f / 0.615f) + 0.5f, 0.0f, 1.0f);
return float2(u, v);
}
static void scope_put_pixel(const uchar *table, uchar *pos)