mirror() borrowed from dwt.c, this could be moved to libavutil and made public API, Ill submit a patch for this Fixes Ticket1278
Unified · Split
| @@ -25,6 +25,7 @@ · 24 unmodified lines | ||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | #include "libavutil/common.h" |
| 28 | +#include "libavutil/avassert.h" | |
| 28 | 29 | |
| 29 | 30 | #include "transform.h" |
| 30 | 31 | |
| @@ -135,6 +136,16 @@ void avfilter_mul_matrix(const float *m1, float scalar, float *result) · 104 unmodified lines | ||
| 135 | 136 | result[i] = m1[i] * scalar; |
| 136 | 137 | } |
| 137 | 138 | |
| 139 | +static inline int mirror(int v, int m) | |
| 140 | +{ | |
| 141 | + while ((unsigned)v > (unsigned)m) { | |
| 142 | + v = -v; | |
| 143 | + if (v < 0) | |
| 144 | + v += 2 * m; | |
| 145 | + } | |
| 146 | + return v; | |
| 147 | +} | |
| 148 | + | |
| 138 | 149 | void avfilter_transform(const uint8_t *src, uint8_t *dst, |
| 139 | 150 | int src_stride, int dst_stride, |
| 140 | 151 | int width, int height, const float *matrix, |
| @@ -173,8 +184,11 @@ void avfilter_transform(const uint8_t *src, uint8_t *dst, · 32 unmodified lines | ||
| 173 | 184 | def = src[(int)y_s * src_stride + (int)x_s]; |
| 174 | 185 | break; |
| 175 | 186 | case FILL_MIRROR: |
| 176 | − y_s = (y_s < 0) ? -y_s : (y_s >= height) ? (height + height - y_s) : y_s; | |
| 177 | − x_s = (x_s < 0) ? -x_s : (x_s >= width) ? (width + width - x_s) : x_s; | |
| 187 | + x_s = mirror(x_s, width-1); | |
| 188 | + y_s = mirror(y_s, height-1); | |
| 189 | + | |
| 190 | + av_assert2(x_s >= 0 && y_s >= 0); | |
| 191 | + av_assert2(x_s < width && y_s < height); | |
| 178 | 192 | def = src[(int)y_s * src_stride + (int)x_s]; |
| 179 | 193 | } |
| 180 | 194 | |