summaryrefslogtreecommitdiffstats
path: root/video/zimg.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-10-31 16:45:28 +0100
committerwm4 <wm4@nowhere>2019-10-31 16:51:12 +0100
commita7230dfed0bf563fd9f4673c3020d1cf8461febf (patch)
treed34d333e6f627842aa55e4737a441710d700820d /video/zimg.c
parent2c43d2b75a88b8e0e8f0a715f993ffc1c8977d13 (diff)
downloadmpv-a7230dfed0bf563fd9f4673c3020d1cf8461febf.tar.bz2
mpv-a7230dfed0bf563fd9f4673c3020d1cf8461febf.tar.xz
sws_utils, zimg: destroy vo_x11 and vo_drm performance
Raise swscale and zimg default parameters. This restores screenshot quality settings (maybe) unset in the commit before. Also expose some more libswscale and zimg options. Since these options are also used for VOs like x11 and drm, this will make x11/drm/etc. much slower. For compensation, provide a profile that sets the old option values: sw-fast. I'm also enabling zimg here, just as an experiment. The core problem is that we have a single set of command line options which control the settings used for most swscale/zimg uses. This was done in the previous commit. It cannot differentiate between the VOs, which need to be realtime and may accept/require lower quality options, and things like screenshots or vo_image, which can be slower, but should not sacrifice quality by default. Should this have two sets of options or something similar to do the right thing depending on the code which calls libswscale? Maybe. Or should I just ignore the problem, make it someone else's problem (users who want to use software conversion VOs), provide a sub-optimal solution, and call it a day? Definitely, sounds good, pushing to master, goodbye.
Diffstat (limited to 'video/zimg.c')
-rw-r--r--video/zimg.c69
1 files changed, 40 insertions, 29 deletions
diff --git a/video/zimg.c b/video/zimg.c
index 7ea60531e1..b568a6bbec 100644
--- a/video/zimg.c
+++ b/video/zimg.c
@@ -27,27 +27,43 @@
static_assert(MP_IMAGE_BYTE_ALIGN >= ZIMG_ALIGN, "");
-struct zimg_opts {
- int scaler;
- int fast;
+static const struct m_opt_choice_alternatives mp_zimg_scalers[] = {
+ {"point", ZIMG_RESIZE_POINT},
+ {"bilinear", ZIMG_RESIZE_BILINEAR},
+ {"bicubic", ZIMG_RESIZE_BICUBIC},
+ {"spline16", ZIMG_RESIZE_SPLINE16},
+ {"spline36", ZIMG_RESIZE_SPLINE36},
+ {"lanczos", ZIMG_RESIZE_LANCZOS},
+ {0}
};
+#define OPT_PARAM(name, var, flags) \
+ OPT_DOUBLE(name, var, (flags) | M_OPT_DEFAULT_NAN)
+
#define OPT_BASE_STRUCT struct zimg_opts
const struct m_sub_options zimg_conf = {
.opts = (struct m_option[]) {
- OPT_CHOICE("scaler", scaler, 0,
- ({"point", ZIMG_RESIZE_POINT},
- {"bilinear", ZIMG_RESIZE_BILINEAR},
- {"bicubic", ZIMG_RESIZE_BICUBIC},
- {"spline16", ZIMG_RESIZE_SPLINE16},
- {"lanczos", ZIMG_RESIZE_LANCZOS})),
+ OPT_CHOICE_C("scaler", scaler, 0, mp_zimg_scalers),
+ OPT_PARAM("scaler-param-a", scaler_params[0], 0),
+ OPT_PARAM("scaler-param-b", scaler_params[1], 0),
+ OPT_CHOICE_C("scaler-chroma", scaler_chroma, 0, mp_zimg_scalers),
+ OPT_PARAM("scaler-chroma-param-a", scaler_chroma_params[0], 0),
+ OPT_PARAM("scaler-chroma-param-b", scaler_chroma_params[1], 0),
+ OPT_CHOICE("dither", dither, 0,
+ ({"no", ZIMG_DITHER_NONE},
+ {"ordered", ZIMG_DITHER_ORDERED},
+ {"random", ZIMG_DITHER_RANDOM},
+ {"error-diffusion", ZIMG_DITHER_ERROR_DIFFUSION})),
OPT_FLAG("fast", fast, 0),
{0}
},
.size = sizeof(struct zimg_opts),
.defaults = &(const struct zimg_opts){
- .scaler = ZIMG_RESIZE_BILINEAR,
- .fast = 1,
+ .scaler = ZIMG_RESIZE_LANCZOS,
+ .scaler_params = {NAN, NAN},
+ .scaler_chroma_params = {NAN, NAN},
+ .scaler_chroma = ZIMG_RESIZE_BILINEAR,
+ .dither = ZIMG_DITHER_RANDOM,
},
};
@@ -90,9 +106,7 @@ static void mp_zimg_update_from_cmdline(struct mp_zimg_context *ctx)
m_config_cache_update(ctx->opts_cache);
struct zimg_opts *opts = ctx->opts_cache->opts;
-
- ctx->scaler = opts->scaler;
- ctx->fast = opts->fast;
+ ctx->opts = *opts;
}
static zimg_chroma_location_e mp_to_z_chroma(enum mp_chroma_location cl)
@@ -183,13 +197,8 @@ struct mp_zimg_context *mp_zimg_alloc(void)
struct mp_zimg_context *ctx = talloc_ptrtype(NULL, ctx);
*ctx = (struct mp_zimg_context) {
.log = mp_null_log,
- .scaler = ZIMG_RESIZE_BILINEAR,
- .scaler_params = {NAN, NAN},
- .scaler_chroma = ZIMG_RESIZE_BILINEAR,
- .scaler_chroma_params = {NAN, NAN},
- .dither = ZIMG_DITHER_NONE,
- .fast = true,
};
+ ctx->opts = *(struct zimg_opts *)zimg_conf.defaults;
talloc_set_destructor(ctx, free_mp_zimg);
return ctx;
}
@@ -504,7 +513,7 @@ static bool setup_format(zimg_image_format *zfmt, struct mp_zimg_repack *r,
zfmt->color_primaries = mp_to_z_prim(fmt.color.primaries);
zfmt->chroma_location = mp_to_z_chroma(fmt.chroma_location);
- if (ctx && ctx->fast) {
+ if (ctx && ctx->opts.fast) {
// mpv's default for RGB output slows down zimg significantly.
if (zfmt->transfer_characteristics == ZIMG_TRANSFER_IEC_61966_2_1 &&
zfmt->color_family == ZIMG_COLOR_RGB)
@@ -547,6 +556,8 @@ static bool allocate_buffer(struct mp_zimg_context *ctx,
bool mp_zimg_config(struct mp_zimg_context *ctx)
{
+ struct zimg_opts *opts = &ctx->opts;
+
destroy_zimg(ctx);
if (ctx->opts_cache)
@@ -569,19 +580,19 @@ bool mp_zimg_config(struct mp_zimg_context *ctx)
zimg_graph_builder_params params;
zimg_graph_builder_params_default(&params, ZIMG_API_VERSION);
- params.resample_filter = ctx->scaler;
- params.filter_param_a = ctx->scaler_params[0];
- params.filter_param_b = ctx->scaler_params[1];
+ params.resample_filter = opts->scaler;
+ params.filter_param_a = opts->scaler_params[0];
+ params.filter_param_b = opts->scaler_params[1];
- params.resample_filter_uv = ctx->scaler_chroma;
- params.filter_param_a_uv = ctx->scaler_chroma_params[0];
- params.filter_param_b_uv = ctx->scaler_chroma_params[1];
+ params.resample_filter_uv = opts->scaler_chroma;
+ params.filter_param_a_uv = opts->scaler_chroma_params[0];
+ params.filter_param_b_uv = opts->scaler_chroma_params[1];
- params.dither_type = ctx->dither;
+ params.dither_type = opts->dither;
params.cpu_type = ZIMG_CPU_AUTO_64B;
- if (ctx->fast)
+ if (opts->fast)
params.allow_approximate_gamma = 1;
if (ctx->src.color.sig_peak > 0)