summaryrefslogtreecommitdiffstats
path: root/video/zimg.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-10-20 01:54:45 +0200
committerwm4 <wm4@nowhere>2019-10-20 02:17:31 +0200
commit07aa29ed8e11797310bbc8d569cc58e29bb794e3 (patch)
tree12f04a4c2f70fdc40bf8cf7060635bccfff06935 /video/zimg.h
parentfd539a542f04e88a8c5b245cc3c3b80b03c2a4b7 (diff)
downloadmpv-07aa29ed8e11797310bbc8d569cc58e29bb794e3.tar.bz2
mpv-07aa29ed8e11797310bbc8d569cc58e29bb794e3.tar.xz
video: add zimg wrapper
This provides a very similar API to sws_utils.h, which can be used to convert and scale from one mp_image to another. This commit adds only the code, but does not use it anywhere. The code is quite preliminary and barely tested. It supports only a few pixel formats, and will return failure for many others. (Unlike libswscale, which tries to support anything that FFmpeg knows.) zimg itself accepts only planar formats. Supporting other formats requires manual packing/unpacking. (Compared to libswscale, the zimg API is generally lower level, but allows for more flexibility.) Only BGR0 output was actually tested. It appears to work.
Diffstat (limited to 'video/zimg.h')
-rw-r--r--video/zimg.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/video/zimg.h b/video/zimg.h
new file mode 100644
index 0000000000..0d9c139f9a
--- /dev/null
+++ b/video/zimg.h
@@ -0,0 +1,63 @@
+#pragma once
+
+#include <stdbool.h>
+
+#include <zimg.h>
+
+#include "mp_image.h"
+
+#define ZIMG_ALIGN 64
+
+struct mpv_global;
+
+bool mp_zimg_supports_in_format(int imgfmt);
+bool mp_zimg_supports_out_format(int imgfmt);
+
+struct mp_zimg_context {
+ // Can be set for verbose error printing.
+ struct mp_log *log;
+
+ // User configuration. Note: changing these requires calling mp_zimg_config()
+ // to update the filter graph. The first mp_zimg_convert() call (or if the
+ // image format changes) will do this automatically.
+ zimg_resample_filter_e scaler;
+ double scaler_params[2];
+ zimg_resample_filter_e scaler_chroma;
+ double scaler_chroma_params[2];
+ zimg_dither_type_e dither;
+ bool fast; // reduce quality for better performance
+
+ // Input/output parameters. Note: if these mismatch with the
+ // mp_zimg_convert() parameters, mp_zimg_config() will be called
+ // automatically.
+ struct mp_image_params src, dst;
+
+ // Cached zimg state (if any). Private, do not touch.
+ zimg_filter_graph *zimg_graph;
+ void *zimg_tmp;
+ struct mp_zimg_repack *zimg_src;
+ struct mp_zimg_repack *zimg_dst;
+};
+
+// Allocate a zimg context. Always succeeds. Returns a talloc pointer (use
+// talloc_free() to release it).
+struct mp_zimg_context *mp_zimg_alloc(void);
+
+// Try to build the conversion chain using the parameters currently set in ctx.
+// If this succeeds, mp_zimg_convert() will always succeed (probably), as long
+// as the input has the same parameters.
+// Returns false on error.
+bool mp_zimg_config(struct mp_zimg_context *ctx);
+
+// Similar to mp_zimg_config(), but assume none of the user parameters changed,
+// except possibly .src and .dst. This essentially checks whether src/dst
+// changed, and if so, calls mp_zimg_config().
+bool mp_zimg_config_image_params(struct mp_zimg_context *ctx);
+
+// Convert/scale src to dst. On failure, the data in dst is not touched.
+bool mp_zimg_convert(struct mp_zimg_context *ctx, struct mp_image *dst,
+ struct mp_image *src);
+
+// Set the global zimg command line parameters on this context. Use this if you
+// want the user to be able to change the scaler etc.
+void mp_zimg_set_from_cmdline(struct mp_zimg_context *ctx, struct mpv_global *g);