1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

avfilter/vsrc_gradients: fix several issues with !rgba output

This commit is contained in:
Paul B Mahol 2023-05-06 17:47:36 +02:00
parent 722ff74055
commit 0c91327210

View File

@ -111,13 +111,13 @@ static uint64_t lerp_color16(uint8_t c0[4], uint8_t c1[4], float x)
{
const float y = 1.f - x;
return (llrintf((c0[0] * y + c1[0] * x) * 256)) << 0 |
(llrintf((c0[1] * y + c1[1] * x) * 256)) << 16 |
(llrintf((c0[2] * y + c1[2] * x) * 256)) << 32 |
(llrintf((c0[3] * y + c1[3] * x) * 256)) << 48;
return ((uint64_t)llrintf((c0[0] * y + c1[0] * x) * 256)) << 0 |
((uint64_t)llrintf((c0[1] * y + c1[1] * x) * 256)) << 16 |
((uint64_t)llrintf((c0[2] * y + c1[2] * x) * 256)) << 32 |
((uint64_t)llrintf((c0[3] * y + c1[3] * x) * 256)) << 48;
}
static uint32_t lerp_colors(uint8_t arr[3][4], int nb_colors, int nb_wrap_colors, float step)
static uint32_t lerp_colors(uint8_t arr[8][4], int nb_colors, int nb_wrap_colors, float step)
{
float scl;
int i, j;
@ -140,7 +140,7 @@ static uint32_t lerp_colors(uint8_t arr[3][4], int nb_colors, int nb_wrap_colors
return lerp_color(arr[i], arr[j], scl - i);
}
static uint64_t lerp_colors16(uint8_t arr[3][4], int nb_colors, int nb_wrap_colors, float step)
static uint64_t lerp_colors16(uint8_t arr[8][4], int nb_colors, int nb_wrap_colors, float step)
{
float scl;
int i, j;
@ -163,7 +163,7 @@ static uint64_t lerp_colors16(uint8_t arr[3][4], int nb_colors, int nb_wrap_colo
return lerp_color16(arr[i], arr[j], scl - i);
}
static void lerp_colors32(float arr[3][4], int nb_colors,
static void lerp_colors32(float arr[8][4], int nb_colors,
int nb_wrap_colors, float step,
float *r, float *g, float *b, float *a)
{
@ -187,12 +187,12 @@ static void lerp_colors32(float arr[3][4], int nb_colors,
scl = step * (nb_wrap_colors - 1);
i = floorf(scl);
x = scl - i;
j = i + 1;
if (i >= nb_colors - 1) {
i = nb_colors - 1;
j = 0;
}
x = scl - i;
*r = lerpf(arr[i][0], arr[j][0], x);
*g = lerpf(arr[i][1], arr[j][1], x);
@ -253,11 +253,12 @@ static int draw_gradients_slice(AVFilterContext *ctx, void *arg, int job, int nb
const int end = (height * (job+1)) / nb_jobs;
const int linesize = frame->linesize[0] / 4;
uint32_t *dst = (uint32_t *)frame->data[0] + start * linesize;
const int type = s->type;
for (int y = start; y < end; y++) {
for (int x = 0; x < width; x++) {
float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, s->type);
dst[x] = lerp_colors(s->color_rgba, s->nb_colors, s->nb_colors + (s->type >= 2), factor);
float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, type);
dst[x] = lerp_colors(s->color_rgba, s->nb_colors, s->nb_colors + (type >= 2), factor);
}
dst += linesize;
@ -276,11 +277,12 @@ static int draw_gradients_slice16(AVFilterContext *ctx, void *arg, int job, int
const int end = (height * (job+1)) / nb_jobs;
const int linesize = frame->linesize[0] / 8;
uint64_t *dst = (uint64_t *)frame->data[0] + start * linesize;
const int type = s->type;
for (int y = start; y < end; y++) {
for (int x = 0; x < width; x++) {
float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, s->type);
dst[x] = lerp_colors16(s->color_rgba, s->nb_colors, s->nb_colors + s->type >= 2, factor);
float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, type);
dst[x] = lerp_colors16(s->color_rgba, s->nb_colors, s->nb_colors + (type >= 2), factor);
}
dst += linesize;
@ -302,14 +304,15 @@ static int draw_gradients_slice32_planar(AVFilterContext *ctx, void *arg, int jo
const int linesize_r = frame->linesize[2] / 4;
const int linesize_a = frame->linesize[3] / 4;
float *dst_g = (float *)frame->data[0] + start * linesize_g;
float *dst_b = (float *)frame->data[0] + start * linesize_b;
float *dst_r = (float *)frame->data[0] + start * linesize_r;
float *dst_a = (float *)frame->data[0] + start * linesize_a;
float *dst_b = (float *)frame->data[1] + start * linesize_b;
float *dst_r = (float *)frame->data[2] + start * linesize_r;
float *dst_a = (float *)frame->data[3] + start * linesize_a;
const int type = s->type;
for (int y = start; y < end; y++) {
for (int x = 0; x < width; x++) {
float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, s->type);
lerp_colors32(s->color_rgbaf, s->nb_colors, s->nb_colors + s->type >= 2 ,factor,
float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, type);
lerp_colors32(s->color_rgbaf, s->nb_colors, s->nb_colors + (type >= 2), factor,
&dst_r[x], &dst_g[x], &dst_b[x], &dst_a[x]);
}