From d61ced37ae39b4a2dcd49e783f3c292a8d97b14a Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 9 May 2020 17:56:21 +0200 Subject: sws_utils: allow setting zimg options directly One could wonder, why not just use the zimg wrapper directly? --- video/sws_utils.c | 2 ++ video/sws_utils.h | 4 ++++ video/zimg.c | 18 ++++++++++-------- video/zimg.h | 2 ++ 4 files changed, 18 insertions(+), 8 deletions(-) (limited to 'video') diff --git a/video/sws_utils.c b/video/sws_utils.c index 1cce8ae4cd..faa61670b1 100644 --- a/video/sws_utils.c +++ b/video/sws_utils.c @@ -244,6 +244,8 @@ int mp_sws_reinit(struct mp_sws_context *ctx) ctx->zimg->log = ctx->log; ctx->zimg->src = *src; ctx->zimg->dst = *dst; + if (ctx->zimg_opts) + ctx->zimg->opts = *ctx->zimg_opts; if (mp_zimg_config(ctx->zimg)) { ctx->zimg_ok = true; MP_VERBOSE(ctx, "Using zimg.\n"); diff --git a/video/sws_utils.h b/video/sws_utils.h index 2c7af5eac0..9e7f24e0a7 100644 --- a/video/sws_utils.h +++ b/video/sws_utils.h @@ -44,6 +44,10 @@ struct mp_sws_context { // This is unfortunately a hack: bypass command line choice enum mp_sws_scaler force_scaler; + // If zimg is used. Need to manually invalidate cache (set force_reload). + // Conflicts with enabling command line opts. + struct zimg_opts *zimg_opts; + // Changing these requires setting force_reload=true. // By default, they are NULL. // Freeing the mp_sws_context will deallocate these if set. diff --git a/video/zimg.c b/video/zimg.c index 22f1a1a1b1..ae3602d297 100644 --- a/video/zimg.c +++ b/video/zimg.c @@ -43,6 +43,15 @@ static const struct m_opt_choice_alternatives mp_zimg_scalers[] = { {0} }; +const struct zimg_opts zimg_opts_defaults = { + .scaler = ZIMG_RESIZE_LANCZOS, + .scaler_params = {NAN, NAN}, + .scaler_chroma_params = {NAN, NAN}, + .scaler_chroma = ZIMG_RESIZE_BILINEAR, + .dither = ZIMG_DITHER_RANDOM, + .fast = 1, +}; + #define OPT_PARAM(var) OPT_DOUBLE(var), .flags = M_OPT_DEFAULT_NAN #define OPT_BASE_STRUCT struct zimg_opts @@ -63,14 +72,7 @@ const struct m_sub_options zimg_conf = { {0} }, .size = sizeof(struct zimg_opts), - .defaults = &(const struct zimg_opts){ - .scaler = ZIMG_RESIZE_LANCZOS, - .scaler_params = {NAN, NAN}, - .scaler_chroma_params = {NAN, NAN}, - .scaler_chroma = ZIMG_RESIZE_BILINEAR, - .dither = ZIMG_DITHER_RANDOM, - .fast = 1, - }, + .defaults = &zimg_opts_defaults, }; struct mp_zimg_repack { diff --git a/video/zimg.h b/video/zimg.h index ef2aeaa112..4c1a25ca7d 100644 --- a/video/zimg.h +++ b/video/zimg.h @@ -22,6 +22,8 @@ struct zimg_opts { int fast; }; +extern const struct zimg_opts zimg_opts_defaults; + struct mp_zimg_context { // Can be set for verbose error printing. struct mp_log *log; -- cgit v1.2.3