History

avfilter: pass link YUV colorspace to ff_draw_init2

This makes all ff_draw_* based filters aware of YUV colorspaces and ranges. Needed for YUVJ removal. Also fixes a bug where e.g. vf_pad would generate a limited range background even after conversion to full-scale grayscale. The FATE changes were a consequence of the aforementioned bugfix - the gray scale files are output as full range (due to conversion by libswscale, which hard-codes gray = full), and appropriately tagged as such, but before this change the padded version incorrectly used a limited range (16) black background for these formats.

Niklas Haas committed 2 years ago

Commit ce812371 parent 8264f3614 files · +32 −25Browse files

Showing the changes to libavfilter (13 of 14 files). Show all

Unified · Split

13 files
  1. libavfilter/qrencode.c +5 −3
  2. libavfilter/src_avsynctest.c +1 −1
  3. libavfilter/vf_datascope.c +1 −1
  4. libavfilter/vf_drawtext.c +1 −1
  5. libavfilter/vf_pad.c +1 −1
  6. libavfilter/vf_rotate.c +1 −1
  7. libavfilter/vf_shear.c +1 −1
  8. libavfilter/vf_stack.c +2 −1
  9. libavfilter/vf_subtitles.c +2 −1
  10. libavfilter/vf_tile.c +1 −1
  11. libavfilter/vf_tinterlace.c +1 −1
  12. libavfilter/vf_tpad.c +1 −1
  13. libavfilter/vsrc_testsrc.c +6 −3
libavfilter/qrencode.c+5−3
@@ -638,7 +638,7 @@ static int qrencodesrc_config_props(AVFilterLink *outlink) · 637 unmodified lines
638638 ff_draw_color(&qr->draw, &qr->draw_foreground_color, (const uint8_t *)&qr->foreground_color);
639639 ff_draw_color(&qr->draw, &qr->draw_background_color, (const uint8_t *)&qr->background_color);
640640
641− ff_draw_init(&qr->draw0, outlink->format, FF_DRAW_PROCESS_ALPHA);
641+ ff_draw_init2(&qr->draw0, outlink->format, outlink->colorspace, outlink->color_range, FF_DRAW_PROCESS_ALPHA);
642642 ff_draw_color(&qr->draw0, &qr->draw0_background_color, (const uint8_t *)&qr->background_color);
643643
644644 outlink->w = qr->rendered_padded_qrcode_width;
@@ -730,7 +730,8 @@ static int qrencode_config_input(AVFilterLink *inlink) · 85 unmodified lines
730730
731731 qr->is_source = 0;
732732
733− ff_draw_init(&qr->draw, inlink->format, FF_DRAW_PROCESS_ALPHA);
733+ ff_draw_init2(&qr->draw, inlink->format, inlink->colorspace, inlink->color_range,
734+ FF_DRAW_PROCESS_ALPHA);
734735
735736 V(W) = V(main_w) = inlink->w;
736737 V(H) = V(main_h) = inlink->h;
@@ -759,7 +760,8 @@ static int qrencode_config_input(AVFilterLink *inlink) · 22 unmodified lines
759760 PARSE_EXPR(rendered_qrcode_width);
760761 PARSE_EXPR(rendered_padded_qrcode_width);
761762
762− ff_draw_init(&qr->draw, inlink->format, FF_DRAW_PROCESS_ALPHA);
763+ ff_draw_init2(&qr->draw, inlink->format, inlink->colorspace, inlink->color_range,
764+ FF_DRAW_PROCESS_ALPHA);
763765 ff_draw_color(&qr->draw, &qr->draw_foreground_color, (const uint8_t *)&qr->foreground_color);
764766 ff_draw_color(&qr->draw, &qr->draw_background_color, (const uint8_t *)&qr->background_color);
765767
libavfilter/src_avsynctest.c+1−1
@@ -160,7 +160,7 @@ static av_cold int config_props(AVFilterLink *outlink) · 159 unmodified lines
160160 s->dir = 1;
161161 s->prev_intpart = INT64_MIN;
162162
163− ff_draw_init(&s->draw, outlink->format, 0);
163+ ff_draw_init2(&s->draw, outlink->format, outlink->colorspace, outlink->color_range, 0);
164164
165165 ff_draw_color(&s->draw, &s->fg, s->rgba[0]);
166166 ff_draw_color(&s->draw, &s->bg, s->rgba[1]);
libavfilter/vf_datascope.c+1−1
@@ -383,7 +383,7 @@ static int config_input(AVFilterLink *inlink) · 382 unmodified lines
383383 uint8_t alpha = s->opacity * 255;
384384
385385 s->nb_planes = av_pix_fmt_count_planes(inlink->format);
386− ff_draw_init(&s->draw, inlink->format, 0);
386+ ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0);
387387 ff_draw_color(&s->draw, &s->white, (uint8_t[]){ 255, 255, 255, 255} );
388388 ff_draw_color(&s->draw, &s->black, (uint8_t[]){ 0, 0, 0, alpha} );
389389 ff_draw_color(&s->draw, &s->yellow, (uint8_t[]){ 255, 255, 0, 255} );
libavfilter/vf_drawtext.c+1−1
@@ -1152,7 +1152,7 @@ static int config_input(AVFilterLink *inlink) · 1151 unmodified lines
11521152 char *expr;
11531153 int ret;
11541154
1155− ff_draw_init(&s->dc, inlink->format, FF_DRAW_PROCESS_ALPHA);
1155+ ff_draw_init2(&s->dc, inlink->format, inlink->colorspace, inlink->color_range, FF_DRAW_PROCESS_ALPHA);
11561156 ff_draw_color(&s->dc, &s->fontcolor, s->fontcolor.rgba);
11571157 ff_draw_color(&s->dc, &s->shadowcolor, s->shadowcolor.rgba);
11581158 ff_draw_color(&s->dc, &s->bordercolor, s->bordercolor.rgba);
libavfilter/vf_pad.c+1−1
@@ -111,7 +111,7 @@ static int config_input(AVFilterLink *inlink) · 110 unmodified lines
111111 double var_values[VARS_NB], res;
112112 char *expr;
113113
114− ff_draw_init(&s->draw, inlink->format, 0);
114+ ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0);
115115 ff_draw_color(&s->draw, &s->color, s->rgba_color);
116116
117117 var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;
libavfilter/vf_rotate.c+1−1
@@ -288,7 +288,7 @@ static int config_props(AVFilterLink *outlink) · 287 unmodified lines
288288 double res;
289289 char *expr;
290290
291− ff_draw_init(&rot->draw, inlink->format, 0);
291+ ff_draw_init2(&rot->draw, inlink->format, inlink->colorspace, inlink->color_range, 0);
292292 ff_draw_color(&rot->draw, &rot->color, rot->fillcolor);
293293
294294 rot->hsub = pixdesc->log2_chroma_w;
libavfilter/vf_shear.c+1−1
@@ -260,7 +260,7 @@ static int config_output(AVFilterLink *outlink) · 259 unmodified lines
260260 s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(ctx->inputs[0]->h, desc->log2_chroma_h);
261261 s->planeheight[0] = s->planeheight[3] = ctx->inputs[0]->h;
262262
263− ff_draw_init(&s->draw, outlink->format, 0);
263+ ff_draw_init2(&s->draw, outlink->format, outlink->colorspace, outlink->color_range, 0);
264264 ff_draw_color(&s->draw, &s->color, s->fillcolor);
265265
266266 s->filter_slice[0] = s->depth <= 8 ? filter_slice_nn8 : filter_slice_nn16;
libavfilter/vf_stack.c+2−1
@@ -304,7 +304,8 @@ static int config_output(AVFilterLink *outlink) · 303 unmodified lines
304304 int inw, inh, size;
305305
306306 if (s->fillcolor_enable) {
307− ff_draw_init(&s->draw, ctx->inputs[0]->format, 0);
307+ const AVFilterLink *inlink = ctx->inputs[0];
308+ ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0);
308309 ff_draw_color(&s->draw, &s->color, s->fillcolor);
309310 }
310311
libavfilter/vf_subtitles.c+2−1
@@ -148,7 +148,8 @@ static int config_input(AVFilterLink *inlink) · 147 unmodified lines
148148 {
149149 AssContext *ass = inlink->dst->priv;
150150
151− ff_draw_init(&ass->draw, inlink->format, ass->alpha ? FF_DRAW_PROCESS_ALPHA : 0);
151+ ff_draw_init2(&ass->draw, inlink->format, inlink->colorspace, inlink->color_range,
152+ ass->alpha ? FF_DRAW_PROCESS_ALPHA : 0);
152153
153154 ass_set_frame_size (ass->renderer, inlink->w, inlink->h);
154155 if (ass->original_w && ass->original_h) {
libavfilter/vf_tile.c+1−1
@@ -139,7 +139,7 @@ static int config_props(AVFilterLink *outlink) · 138 unmodified lines
139139 outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
140140 outlink->frame_rate = av_mul_q(inlink->frame_rate,
141141 av_make_q(1, tile->nb_frames - tile->overlap));
142− ff_draw_init(&tile->draw, inlink->format, 0);
142+ ff_draw_init2(&tile->draw, inlink->format, inlink->colorspace, inlink->color_range, 0);
143143 ff_draw_color(&tile->draw, &tile->blank, tile->rgba_color);
144144
145145 return 0;
libavfilter/vf_tinterlace.c+1−1
@@ -225,7 +225,7 @@ static int config_out_props(AVFilterLink *outlink) · 224 unmodified lines
225225
226226 if (tinterlace->mode == MODE_PAD) {
227227 uint8_t black[4] = { 0, 0, 0, 16 };
228− ff_draw_init(&tinterlace->draw, outlink->format, 0);
228+ ff_draw_init2(&tinterlace->draw, outlink->format, outlink->colorspace, outlink->color_range, 0);
229229 ff_draw_color(&tinterlace->draw, &tinterlace->color, black);
230230 /* limited range */
231231 if (!ff_fmt_is_in(outlink->format, full_scale_yuvj_pix_fmts)) {
libavfilter/vf_tpad.c+1−1
@@ -203,7 +203,7 @@ static int config_input(AVFilterLink *inlink) · 202 unmodified lines
203203 TPadContext *s = ctx->priv;
204204
205205 if (needs_drawing(s)) {
206− ff_draw_init(&s->draw, inlink->format, 0);
206+ ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0);
207207 ff_draw_color(&s->draw, &s->color, s->rgba_color);
208208 }
209209
libavfilter/vsrc_testsrc.c+6−3
@@ -263,7 +263,8 @@ static int color_config_props(AVFilterLink *inlink) · 262 unmodified lines
263263 TestSourceContext *test = ctx->priv;
264264 int ret;
265265
266− ff_draw_init(&test->draw, inlink->format, 0);
266+ ff_draw_init2(&test->draw, inlink->format, inlink->colorspace,
267+ inlink->color_range, 0);
267268 ff_draw_color(&test->draw, &test->color, test->color_rgba);
268269
269270 test->w = ff_draw_round_to_sub(&test->draw, 0, -1, test->w);
@@ -944,7 +945,8 @@ static int test2_config_props(AVFilterLink *inlink) · 674 unmodified lines
944945 AVFilterContext *ctx = inlink->src;
945946 TestSourceContext *s = ctx->priv;
946947
947− av_assert0(ff_draw_init(&s->draw, inlink->format, 0) >= 0);
948+ av_assert0(ff_draw_init2(&s->draw, inlink->format, inlink->colorspace,
949+ inlink->color_range, 0) >= 0);
948950 s->w = ff_draw_round_to_sub(&s->draw, 0, -1, s->w);
949951 s->h = ff_draw_round_to_sub(&s->draw, 1, -1, s->h);
950952 if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
@@ -1964,7 +1966,8 @@ static int colorchart_config_props(AVFilterLink *inlink) · 1013 unmodified lines
19641966 AVFilterContext *ctx = inlink->src;
19651967 TestSourceContext *s = ctx->priv;
19661968
1967− av_assert0(ff_draw_init(&s->draw, inlink->format, 0) >= 0);
1969+ av_assert0(ff_draw_init2(&s->draw, inlink->format, inlink->colorspace,
1970+ inlink->color_range, 0) >= 0);
19681971 if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
19691972 return AVERROR(EINVAL);
19701973 return config_props(inlink);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t