summaryrefslogtreecommitdiffstats
path: root/video/sws_utils.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-10-20 01:57:47 +0200
committerwm4 <wm4@nowhere>2019-10-20 02:17:31 +0200
commit51e141f7ba8a9207a752d295da59b01286e02c23 (patch)
tree60431bc29d227a65b97228924bc8e8950f39c91e /video/sws_utils.c
parent07aa29ed8e11797310bbc8d569cc58e29bb794e3 (diff)
downloadmpv-51e141f7ba8a9207a752d295da59b01286e02c23.tar.bz2
mpv-51e141f7ba8a9207a752d295da59b01286e02c23.tar.xz
sws_utils: hack in zimg redirection support
Awful shit. I probably wouldn't accept this code from someone else, just so you know. The idea is that a sws_utils user can automatically use zimg without large code changes. Basically, laziness. Since zimg support is still very new, and I don't want that anything breaks just because zimg was enabled at build time, an option needs to be set to enable it. (I have especially especially obscure stuff in mind, which is all what libswscale is used in mpv.) This _still_ doesn't cause zimg to be used anywhere, because the sws_utils user has to opt-in by setting allow_zimg. This is because some users depend on certain libswscale features.
Diffstat (limited to 'video/sws_utils.c')
-rw-r--r--video/sws_utils.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/video/sws_utils.c b/video/sws_utils.c
index 79017699c4..48fbef7582 100644
--- a/video/sws_utils.c
+++ b/video/sws_utils.c
@@ -36,6 +36,10 @@
#include "common/msg.h"
#include "osdep/endian.h"
+#if HAVE_ZIMG
+#include "zimg.h"
+#endif
+
//global sws_flags from the command line
struct sws_opts {
int scaler;
@@ -45,6 +49,7 @@ struct sws_opts {
int chr_hshift;
float chr_sharpen;
float lum_sharpen;
+ int zimg;
};
#define OPT_BASE_STRUCT struct sws_opts
@@ -68,6 +73,7 @@ const struct m_sub_options sws_conf = {
OPT_INT("chs", chr_hshift, 0),
OPT_FLOATRANGE("ls", lum_sharpen, 0, -100.0, 100.0),
OPT_FLOATRANGE("cs", chr_sharpen, 0, -100.0, 100.0),
+ OPT_FLAG("allow-zimg", zimg, 0),
{0}
},
.size = sizeof(struct sws_opts),
@@ -98,7 +104,13 @@ void mp_sws_set_from_cmdline(struct mp_sws_context *ctx, struct mpv_global *g)
ctx->flags = SWS_PRINT_INFO;
ctx->flags |= opts->scaler;
+ ctx->opts_allow_zimg = opts->zimg;
+
talloc_free(opts);
+
+#if HAVE_ZIMG
+ mp_zimg_set_from_cmdline(ctx->zimg, g);
+#endif
}
bool mp_sws_supported_format(int imgfmt)
@@ -126,7 +138,8 @@ static bool cache_valid(struct mp_sws_context *ctx)
ctx->flags == old->flags &&
ctx->brightness == old->brightness &&
ctx->contrast == old->contrast &&
- ctx->saturation == old->saturation;
+ ctx->saturation == old->saturation &&
+ ctx->allow_zimg == old->allow_zimg;
}
static void free_mp_sws(void *p)
@@ -150,8 +163,15 @@ struct mp_sws_context *mp_sws_alloc(void *talloc_ctx)
.force_reload = true,
.params = {SWS_PARAM_DEFAULT, SWS_PARAM_DEFAULT},
.cached = talloc_zero(ctx, struct mp_sws_context),
+ .opts_allow_zimg = true,
};
talloc_set_destructor(ctx, free_mp_sws);
+
+#if HAVE_ZIMG
+ ctx->zimg = mp_zimg_alloc();
+ talloc_steal(ctx, ctx->zimg);
+#endif
+
return ctx;
}
@@ -170,6 +190,23 @@ int mp_sws_reinit(struct mp_sws_context *ctx)
return 0;
sws_freeContext(ctx->sws);
+ ctx->sws = NULL;
+ ctx->zimg_ok = false;
+
+#if HAVE_ZIMG
+ if (ctx->allow_zimg && ctx->opts_allow_zimg) {
+ ctx->zimg->log = ctx->log;
+ ctx->zimg->src = *src;
+ ctx->zimg->dst = *dst;
+ if (mp_zimg_config(ctx->zimg)) {
+ ctx->zimg_ok = true;
+ MP_VERBOSE(ctx, "using zimg\n");
+ goto success;
+ }
+ MP_VERBOSE(ctx, "falling back to swscale\n");
+ }
+#endif
+
ctx->sws = sws_alloc_context();
if (!ctx->sws)
return -1;
@@ -246,6 +283,7 @@ int mp_sws_reinit(struct mp_sws_context *ctx)
if (sws_init_context(ctx->sws, ctx->src_filter, ctx->dst_filter) < 0)
return -1;
+success:
ctx->force_reload = false;
*ctx->cached = *ctx;
return 1;
@@ -266,6 +304,11 @@ int mp_sws_scale(struct mp_sws_context *ctx, struct mp_image *dst,
return r;
}
+#if HAVE_ZIMG
+ if (ctx->zimg_ok)
+ return mp_zimg_convert(ctx->zimg, dst, src) ? 0 : -1;
+#endif
+
sws_scale(ctx->sws, (const uint8_t *const *) src->planes, src->stride,
0, src->h, dst->planes, dst->stride);
return 0;