]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/transform.c
lavfi: fix erroneous use of AV_PERM_PRESERVE in ff_inplace_start_frame.
[ffmpeg] / libavfilter / transform.c
index 8afc5fea6aa0e4267581ff7c5253b02ab92ac9d2..b3f85ddd8cdd396f97f202552bf08ca9c51041a3 100644 (file)
@@ -25,6 +25,7 @@
  */
 
 #include "libavutil/common.h"
+#include "libavutil/avassert.h"
 
 #include "transform.h"
 
@@ -135,6 +136,16 @@ void avfilter_mul_matrix(const float *m1, float scalar, float *result)
         result[i] = m1[i] * scalar;
 }
 
+static inline int mirror(int v, int m)
+{
+    while ((unsigned)v > (unsigned)m) {
+        v = -v;
+        if (v < 0)
+            v += 2 * m;
+    }
+    return v;
+}
+
 void avfilter_transform(const uint8_t *src, uint8_t *dst,
                         int src_stride, int dst_stride,
                         int width, int height, const float *matrix,
@@ -173,8 +184,11 @@ void avfilter_transform(const uint8_t *src, uint8_t *dst,
                     def = src[(int)y_s * src_stride + (int)x_s];
                     break;
                 case FILL_MIRROR:
-                    y_s = (y_s < 0) ? -y_s : (y_s >= height) ? (height + height - y_s) : y_s;
-                    x_s = (x_s < 0) ? -x_s : (x_s >= width) ? (width + width - x_s) : x_s;
+                    x_s = mirror(x_s,  width-1);
+                    y_s = mirror(y_s, height-1);
+
+                    av_assert2(x_s >= 0 && y_s >= 0);
+                    av_assert2(x_s < width && y_s < height);
                     def = src[(int)y_s * src_stride + (int)x_s];
             }