History

libavfilter/transform: fix mirroring.

mirror() borrowed from dwt.c, this could be moved to libavutil and made public API, Ill submit a patch for this Fixes Ticket1278

Michael Niedermayer committed 14 years ago

Commit 5a90e551 parent 104c9141 file · +16 −2Browse files

Unified · Split

libavfilter/transform.c+16−2
@@ -25,6 +25,7 @@ · 24 unmodified lines
2525 */
2626
2727 #include "libavutil/common.h"
28+#include "libavutil/avassert.h"
2829
2930 #include "transform.h"
3031
@@ -135,6 +136,16 @@ void avfilter_mul_matrix(const float *m1, float scalar, float *result) · 104 unmodified lines
135136 result[i] = m1[i] * scalar;
136137 }
137138
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+
138149 void avfilter_transform(const uint8_t *src, uint8_t *dst,
139150 int src_stride, int dst_stride,
140151 int width, int height, const float *matrix,
@@ -173,8 +184,11 @@ void avfilter_transform(const uint8_t *src, uint8_t *dst, · 32 unmodified lines
173184 def = src[(int)y_s * src_stride + (int)x_s];
174185 break;
175186 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);
178192 def = src[(int)y_s * src_stride + (int)x_s];
179193 }
180194

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t