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

Unified · Split

14 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
  14. tests/ref/fate/filter-pixfmts-pad +8 −8
libavfilter/qrencode.c+5−3
@@ -638,7 +638,7 @@ static int qrencodesrc_config_props(AVFilterLink *outlink) · 637 unmodified lines
638 ff_draw_color(&qr->draw, &qr->draw_foreground_color, (const uint8_t *)&qr->foreground_color);638 ff_draw_color(&qr->draw, &qr->draw_foreground_color, (const uint8_t *)&qr->foreground_color);
639 ff_draw_color(&qr->draw, &qr->draw_background_color, (const uint8_t *)&qr->background_color);639 ff_draw_color(&qr->draw, &qr->draw_background_color, (const uint8_t *)&qr->background_color);
640 640
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);
642 ff_draw_color(&qr->draw0, &qr->draw0_background_color, (const uint8_t *)&qr->background_color);642 ff_draw_color(&qr->draw0, &qr->draw0_background_color, (const uint8_t *)&qr->background_color);
643 643
644 outlink->w = qr->rendered_padded_qrcode_width;644 outlink->w = qr->rendered_padded_qrcode_width;
@@ -730,7 +730,8 @@ static int qrencode_config_input(AVFilterLink *inlink) · 85 unmodified lines
730 730
731 qr->is_source = 0;731 qr->is_source = 0;
732 732
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);
734 735
735 V(W) = V(main_w) = inlink->w;736 V(W) = V(main_w) = inlink->w;
736 V(H) = V(main_h) = inlink->h;737 V(H) = V(main_h) = inlink->h;
@@ -759,7 +760,8 @@ static int qrencode_config_input(AVFilterLink *inlink) · 22 unmodified lines
759 PARSE_EXPR(rendered_qrcode_width);760 PARSE_EXPR(rendered_qrcode_width);
760 PARSE_EXPR(rendered_padded_qrcode_width);761 PARSE_EXPR(rendered_padded_qrcode_width);
761 762
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);
763 ff_draw_color(&qr->draw, &qr->draw_foreground_color, (const uint8_t *)&qr->foreground_color);765 ff_draw_color(&qr->draw, &qr->draw_foreground_color, (const uint8_t *)&qr->foreground_color);
764 ff_draw_color(&qr->draw, &qr->draw_background_color, (const uint8_t *)&qr->background_color);766 ff_draw_color(&qr->draw, &qr->draw_background_color, (const uint8_t *)&qr->background_color);
765 767
libavfilter/src_avsynctest.c+1−1
@@ -160,7 +160,7 @@ static av_cold int config_props(AVFilterLink *outlink) · 159 unmodified lines
160 s->dir = 1;160 s->dir = 1;
161 s->prev_intpart = INT64_MIN;161 s->prev_intpart = INT64_MIN;
162 162
163 ff_draw_init(&s->draw, outlink->format, 0);163 ff_draw_init2(&s->draw, outlink->format, outlink->colorspace, outlink->color_range, 0);
164 164
165 ff_draw_color(&s->draw, &s->fg, s->rgba[0]);165 ff_draw_color(&s->draw, &s->fg, s->rgba[0]);
166 ff_draw_color(&s->draw, &s->bg, s->rgba[1]);166 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
383 uint8_t alpha = s->opacity * 255;383 uint8_t alpha = s->opacity * 255;
384 384
385 s->nb_planes = av_pix_fmt_count_planes(inlink->format);385 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);
387 ff_draw_color(&s->draw, &s->white, (uint8_t[]){ 255, 255, 255, 255} );387 ff_draw_color(&s->draw, &s->white, (uint8_t[]){ 255, 255, 255, 255} );
388 ff_draw_color(&s->draw, &s->black, (uint8_t[]){ 0, 0, 0, alpha} );388 ff_draw_color(&s->draw, &s->black, (uint8_t[]){ 0, 0, 0, alpha} );
389 ff_draw_color(&s->draw, &s->yellow, (uint8_t[]){ 255, 255, 0, 255} );389 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
1152 char *expr;1152 char *expr;
1153 int ret;1153 int ret;
1154 1154
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);
1156 ff_draw_color(&s->dc, &s->fontcolor, s->fontcolor.rgba);1156 ff_draw_color(&s->dc, &s->fontcolor, s->fontcolor.rgba);
1157 ff_draw_color(&s->dc, &s->shadowcolor, s->shadowcolor.rgba);1157 ff_draw_color(&s->dc, &s->shadowcolor, s->shadowcolor.rgba);
1158 ff_draw_color(&s->dc, &s->bordercolor, s->bordercolor.rgba);1158 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
111 double var_values[VARS_NB], res;111 double var_values[VARS_NB], res;
112 char *expr;112 char *expr;
113 113
114 ff_draw_init(&s->draw, inlink->format, 0);114 ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0);
115 ff_draw_color(&s->draw, &s->color, s->rgba_color);115 ff_draw_color(&s->draw, &s->color, s->rgba_color);
116 116
117 var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;117 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
288 double res;288 double res;
289 char *expr;289 char *expr;
290 290
291 ff_draw_init(&rot->draw, inlink->format, 0);291 ff_draw_init2(&rot->draw, inlink->format, inlink->colorspace, inlink->color_range, 0);
292 ff_draw_color(&rot->draw, &rot->color, rot->fillcolor);292 ff_draw_color(&rot->draw, &rot->color, rot->fillcolor);
293 293
294 rot->hsub = pixdesc->log2_chroma_w;294 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
260 s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(ctx->inputs[0]->h, desc->log2_chroma_h);260 s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(ctx->inputs[0]->h, desc->log2_chroma_h);
261 s->planeheight[0] = s->planeheight[3] = ctx->inputs[0]->h;261 s->planeheight[0] = s->planeheight[3] = ctx->inputs[0]->h;
262 262
263 ff_draw_init(&s->draw, outlink->format, 0);263 ff_draw_init2(&s->draw, outlink->format, outlink->colorspace, outlink->color_range, 0);
264 ff_draw_color(&s->draw, &s->color, s->fillcolor);264 ff_draw_color(&s->draw, &s->color, s->fillcolor);
265 265
266 s->filter_slice[0] = s->depth <= 8 ? filter_slice_nn8 : filter_slice_nn16;266 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
304 int inw, inh, size;304 int inw, inh, size;
305 305
306 if (s->fillcolor_enable) {306 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);
308 ff_draw_color(&s->draw, &s->color, s->fillcolor);309 ff_draw_color(&s->draw, &s->color, s->fillcolor);
309 }310 }
310 311
libavfilter/vf_subtitles.c+2−1
@@ -148,7 +148,8 @@ static int config_input(AVFilterLink *inlink) · 147 unmodified lines
148{148{
149 AssContext *ass = inlink->dst->priv;149 AssContext *ass = inlink->dst->priv;
150 150
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);
152 153
153 ass_set_frame_size (ass->renderer, inlink->w, inlink->h);154 ass_set_frame_size (ass->renderer, inlink->w, inlink->h);
154 if (ass->original_w && ass->original_h) {155 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
139 outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;139 outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
140 outlink->frame_rate = av_mul_q(inlink->frame_rate,140 outlink->frame_rate = av_mul_q(inlink->frame_rate,
141 av_make_q(1, tile->nb_frames - tile->overlap));141 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);
143 ff_draw_color(&tile->draw, &tile->blank, tile->rgba_color);143 ff_draw_color(&tile->draw, &tile->blank, tile->rgba_color);
144 144
145 return 0;145 return 0;
libavfilter/vf_tinterlace.c+1−1
@@ -225,7 +225,7 @@ static int config_out_props(AVFilterLink *outlink) · 224 unmodified lines
225 225
226 if (tinterlace->mode == MODE_PAD) {226 if (tinterlace->mode == MODE_PAD) {
227 uint8_t black[4] = { 0, 0, 0, 16 };227 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);
229 ff_draw_color(&tinterlace->draw, &tinterlace->color, black);229 ff_draw_color(&tinterlace->draw, &tinterlace->color, black);
230 /* limited range */230 /* limited range */
231 if (!ff_fmt_is_in(outlink->format, full_scale_yuvj_pix_fmts)) {231 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
203 TPadContext *s = ctx->priv;203 TPadContext *s = ctx->priv;
204 204
205 if (needs_drawing(s)) {205 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);
207 ff_draw_color(&s->draw, &s->color, s->rgba_color);207 ff_draw_color(&s->draw, &s->color, s->rgba_color);
208 }208 }
209 209
libavfilter/vsrc_testsrc.c+6−3
@@ -263,7 +263,8 @@ static int color_config_props(AVFilterLink *inlink) · 262 unmodified lines
263 TestSourceContext *test = ctx->priv;263 TestSourceContext *test = ctx->priv;
264 int ret;264 int ret;
265 265
266 ff_draw_init(&test->draw, inlink->format, 0);266 ff_draw_init2(&test->draw, inlink->format, inlink->colorspace,
267 inlink->color_range, 0);
267 ff_draw_color(&test->draw, &test->color, test->color_rgba);268 ff_draw_color(&test->draw, &test->color, test->color_rgba);
268 269
269 test->w = ff_draw_round_to_sub(&test->draw, 0, -1, test->w);270 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
944 AVFilterContext *ctx = inlink->src;945 AVFilterContext *ctx = inlink->src;
945 TestSourceContext *s = ctx->priv;946 TestSourceContext *s = ctx->priv;
946 947
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);
948 s->w = ff_draw_round_to_sub(&s->draw, 0, -1, s->w);950 s->w = ff_draw_round_to_sub(&s->draw, 0, -1, s->w);
949 s->h = ff_draw_round_to_sub(&s->draw, 1, -1, s->h);951 s->h = ff_draw_round_to_sub(&s->draw, 1, -1, s->h);
950 if (av_image_check_size(s->w, s->h, 0, ctx) < 0)952 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
1964 AVFilterContext *ctx = inlink->src;1966 AVFilterContext *ctx = inlink->src;
1965 TestSourceContext *s = ctx->priv;1967 TestSourceContext *s = ctx->priv;
1966 1968
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);
1968 if (av_image_check_size(s->w, s->h, 0, ctx) < 0)1971 if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
1969 return AVERROR(EINVAL);1972 return AVERROR(EINVAL);
1970 return config_props(inlink);1973 return config_props(inlink);
tests/ref/fate/filter-pixfmts-pad+8−8
@@ -17,12 +17,12 @@ gbrp12le 91fdad0d1edf7bfa2805e2041e8da3cd · 16 unmodified lines
17gbrp14le deb2c3af6b48faa52f6a1f6590a0cdf717gbrp14le deb2c3af6b48faa52f6a1f6590a0cdf7
18gbrp16le a6156d1a37e05ee621b2a343fb158bd618gbrp16le a6156d1a37e05ee621b2a343fb158bd6
19gbrp9le 9e827f438e081d334a6cae7e282698b019gbrp9le 9e827f438e081d334a6cae7e282698b0
20gray ddc663a0491df3959d9c5795dceaa72e20gray 2b9652a8b136316fada371d03ee252bc
21gray10le e6559c1c8c05ce89f44b465573db44e721gray10le 0efebad19b92c6d6d915971c17ab55c4
22gray12le b066dd276b1698ee77d0c7eb95ff78c522gray12le f03613250550d9dc253d46778f6d4bd6
23gray14le 6d6b293b5d50944c5aa422245987c78e23gray14le dbac6524c3793469c64fc0ee98d017fd
24gray16le 2734ce1793a2216c5be30816689cd2fe24gray16le 7b6db54ec8b4d9a8344443a3b3f50377
25gray9le f8f3dfe31ca5fcba828285bceefdab9a25gray9le 2d2bc7bd35c48fa61860162cf18a4dcf
26nv12 381574979cb04be10c9168540310afad26nv12 381574979cb04be10c9168540310afad
27nv16 d3a50501d2ea8535489fd5ec49e7866d27nv16 d3a50501d2ea8535489fd5ec49e7866d
28nv21 0fdeb2cdd56cf5a7147dc273456fa21728nv21 0fdeb2cdd56cf5a7147dc273456fa217
@@ -43,8 +43,8 @@ rgb48le ed08db9b1aa50d69b8c3d73db93e390e · 14 unmodified lines
43rgba b157c90191463d34fb3ce77b36c9638643rgba b157c90191463d34fb3ce77b36c96386
44vuya 44368c0a758ee68e24ce976e3b1b853544vuya 44368c0a758ee68e24ce976e3b1b8535
45vuyx bc7c4f693a22cd1ac95e33d47308647445vuyx bc7c4f693a22cd1ac95e33d473086474
46ya16le 8dbfcb586abf626da7d1aca887a581b946ya16le dfc900a8130a7c5e64201557cbaef50a
47ya8 495daaca2dcb4f7aeba7652768b41ced47ya8 5d25e9a7975805d3f0dac516a6132b6e
48yuv410p cb871dcc1e84a7ef1d21f9237b88cf6e48yuv410p cb871dcc1e84a7ef1d21f9237b88cf6e
49yuv411p aec2c1740de9a62db0d41f4dda9121b049yuv411p aec2c1740de9a62db0d41f4dda9121b0
50yuv420p 4398e408fc35436ce4b20468946f58b650yuv420p 4398e408fc35436ce4b20468946f58b6

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