Signed-off-by: Paul B Mahol
---
doc/filters.texi | 13
libavfilter/vf_remap.c | 167 +
2 files changed, 166 insertions(+), 14 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index 860d1eadca..3c5941d748 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -13675,6 +13675,19 @@ Xmap and Ymap input video streams must be of same
dimensions. Output video strea
will have Xmap/Ymap video stream dimensions.
Xmap and Ymap input video streams are 16bit depth, single channel.
+@table @option
+@item interpolation
+
+Select interpolation mode.
+
+@table @samp
+@item nearest
+Use values from the nearest neighbor interpolation.
+@item bilinear
+Interpolate values using the bilinear interpolation.
+@end table
+@end table
+
@section removegrain
The removegrain filter is a spatial denoiser for progressive video.
diff --git a/libavfilter/vf_remap.c b/libavfilter/vf_remap.c
index 48ec38af7c..9dfb9ce0be 100644
--- a/libavfilter/vf_remap.c
+++ b/libavfilter/vf_remap.c
@@ -47,6 +47,7 @@
typedef struct RemapContext {
const AVClass *class;
+int interpolation;
int nb_planes;
int nb_components;
int step;
@@ -59,6 +60,9 @@ typedef struct RemapContext {
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
static const AVOption remap_options[] = {
+{ "interpolation", "select interpolation mode", OFFSET(interpolation),
AV_OPT_TYPE_INT , {.i64=0}, 0, 1, FLAGS, "interp" },
+{ "nearest", "use values from the nearest defined points", 0,
AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "interp" },
+{ "bilinear", "use values from the linear interpolation", 0,
AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "interp" },
{ NULL }
};
@@ -121,6 +125,138 @@ fail:
return ret;
}
+static av_always_inline float lerpf(float s, float e, float t)
+{
+return s + (e - s) * t;
+}
+
+static av_always_inline int blerp(int c00, int c10,
+ int c01, int c11,
+ float tx, float ty)
+{
+return lerpf(lerpf(c00, c10, tx), lerpf(c01, c11, tx), ty);
+}
+
+#define DEFINE_INTERP_NEAREST_PLANAR(bits)
\
+static av_always_inline int interp_nearest_planar##bits(const uint##bits##_t
*src, \
+ int slinesize,
\
+ const uint16_t *xmap, int
xlinesize, \
+ const uint16_t *ymap, int
ylinesize, \
+ int w, int h, int x, int y)
\
+{
\
+if (ymap[x] < h && xmap[x] < w) {
\
+return src[ymap[x] * slinesize + xmap[x]];
\
+}
\
+return 0;
\
+}
+
+#define DEFINE_INTERP_NEAREST_PACKED(bits)
\
+static av_always_inline int interp_nearest_packed##bits(const uint##bits##_t
*src, \
+ int slinesize,
\
+ const uint16_t *xmap, int
xlinesize, \
+ const uint16_t *ymap, int
ylinesize, \
+ int w, int h, int x, int y,
\
+ int step, int c)
\
+{
\
+if (ymap[x] < h && xmap[x] < w) {
\
+return src[ymap[x] * slinesize + xmap[x] * step + c];
\
+}
\
+return 0;
\
+}
+
+#define DEFINE_INTERP_BILINEAR_PLANAR(bits)
\
+static av_always_inline int interp_bilinear_planar##bits(const uint##bits##_t
*src, \
+ int slinesize,
\
+ const uint16_t *xmap, int
xlinesize, \
+ const uint16_t *ymap, int
ylinesize, \
+ int w, int h, int x, int y)
\
+{
\
+int c00, c10, c01, c11;