Skip to content

Commit 11b2004

Browse files
committed
vo_gpu{,_next}: fix overriding scaling parameters for inherited kernels
If `{d,c}scale` is not specified the scaling kernel is inherited from `scale`. This made all `{c,d}scale-*` options not work, as they were silently ignored. This commits inherits scale options, only if `{c,d}scale` options were not adjusted in the config.
1 parent df51d55 commit 11b2004

3 files changed

Lines changed: 50 additions & 10 deletions

File tree

video/out/gpu/video.c

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,22 +1772,51 @@ static bool scaler_conf_eq(struct scaler_config a, struct scaler_config b)
17721772
a.clamp == b.clamp;
17731773
}
17741774

1775+
void scaler_conf_merge(struct scaler_config *dst, const struct scaler_config *src,
1776+
enum scaler_unit unit)
1777+
{
1778+
if (dst->kernel.function != SCALER_INHERIT)
1779+
return;
1780+
mp_assert(src->kernel.function != SCALER_INHERIT);
1781+
dst->kernel.function = src->kernel.function;
1782+
1783+
const struct scaler_config *def = &gl_video_opts_def.scaler[unit];
1784+
for (int i = 0; i < MP_ARRAY_SIZE(dst->kernel.params); i++) {
1785+
if (isnan(dst->kernel.params[i]) || dst->kernel.params[i] == def->kernel.params[i])
1786+
dst->kernel.params[i] = src->kernel.params[i];
1787+
if (isnan(dst->window.params[i]) || dst->window.params[i] == def->window.params[i])
1788+
dst->window.params[i] = src->window.params[i];
1789+
}
1790+
if (dst->kernel.blur == def->kernel.blur)
1791+
dst->kernel.blur = src->kernel.blur;
1792+
if (dst->kernel.taper == def->kernel.taper)
1793+
dst->kernel.taper = src->kernel.taper;
1794+
if (dst->window.taper == def->window.taper)
1795+
dst->window.taper = src->window.taper;
1796+
if (dst->clamp == def->clamp)
1797+
dst->clamp = src->clamp;
1798+
if (dst->radius == def->radius)
1799+
dst->radius = src->radius;
1800+
if (dst->antiring == def->antiring)
1801+
dst->antiring = src->antiring;
1802+
if (dst->window.function == def->window.function)
1803+
dst->window.function = src->window.function;
1804+
}
1805+
17751806
static void reinit_scaler(struct gl_video *p, struct scaler *scaler,
17761807
const struct scaler_config *conf,
17771808
double scale_factor,
17781809
int sizes[])
17791810
{
17801811
mp_assert(conf);
1812+
mp_assert(conf->kernel.function != SCALER_INHERIT);
17811813
if (scaler_conf_eq(scaler->conf, *conf) &&
17821814
scaler->scale_factor == scale_factor &&
17831815
scaler->initialized)
17841816
return;
17851817

17861818
uninit_scaler(p, scaler);
17871819

1788-
if (conf->kernel.function == SCALER_INHERIT)
1789-
conf = &p->opts.scaler[SCALER_SCALE];
1790-
17911820
struct filter_kernel bare_window;
17921821
const struct filter_kernel *t_kernel = mp_find_filter_kernel(conf->kernel.function);
17931822
const struct filter_window *t_window = mp_find_filter_window(conf->window.function);
@@ -2369,9 +2398,12 @@ static void pass_read_video(struct gl_video *p)
23692398
continue;
23702399

23712400
const struct scaler_config *conf = &p->opts.scaler[scaler_id];
2372-
2373-
if (conf->kernel.function == SCALER_INHERIT)
2374-
conf = &p->opts.scaler[SCALER_SCALE];
2401+
struct scaler_config tmp;
2402+
if (conf->kernel.function == SCALER_INHERIT) {
2403+
tmp = *conf;
2404+
scaler_conf_merge(&tmp, &p->opts.scaler[SCALER_SCALE], scaler_id);
2405+
conf = &tmp;
2406+
}
23752407

23762408
struct scaler *scaler = &p->scaler[scaler_id];
23772409

@@ -2545,10 +2577,10 @@ static void pass_scale_main(struct gl_video *p)
25452577
p->texture_offset.t[0] = roundf(p->texture_offset.t[0]);
25462578
p->texture_offset.t[1] = roundf(p->texture_offset.t[1]);
25472579
}
2548-
if (downscaling &&
2549-
p->opts.scaler[SCALER_DSCALE].kernel.function != SCALER_INHERIT) {
2580+
if (downscaling) {
25502581
scaler_conf = p->opts.scaler[SCALER_DSCALE];
25512582
scaler = &p->scaler[SCALER_DSCALE];
2583+
scaler_conf_merge(&scaler_conf, &p->opts.scaler[SCALER_SCALE], SCALER_DSCALE);
25522584
}
25532585

25542586
// When requesting correct-downscaling and the clip is anamorphic, and

video/out/gpu/video.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ enum {
194194
RENDER_FRAME_DEF = RENDER_FRAME_SUBS | RENDER_FRAME_OSD | RENDER_SCREEN_COLOR,
195195
};
196196

197+
void scaler_conf_merge(struct scaler_config *dst, const struct scaler_config *src,
198+
enum scaler_unit unit);
199+
197200
struct gl_video *gl_video_init(struct ra *ra, struct mp_log *log,
198201
struct mpv_global *g);
199202
void gl_video_uninit(struct gl_video *p);

video/out/vo_gpu_next.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,8 +2199,13 @@ static const struct pl_filter_config *map_scaler(struct priv *p,
21992199

22002200
const struct gl_video_opts *opts = p->opts_cache->opts;
22012201
const struct scaler_config *cfg = &opts->scaler[unit];
2202-
if (cfg->kernel.function == SCALER_INHERIT)
2203-
cfg = &opts->scaler[SCALER_SCALE];
2202+
struct scaler_config tmp;
2203+
if (cfg->kernel.function == SCALER_INHERIT) {
2204+
tmp = *cfg;
2205+
scaler_conf_merge(&tmp, &opts->scaler[SCALER_SCALE], unit);
2206+
cfg = &tmp;
2207+
}
2208+
22042209
const char *kernel_name = m_opt_choice_str(cfg->kernel.functions,
22052210
cfg->kernel.function);
22062211

0 commit comments

Comments
 (0)