[FFmpeg-cvslog] Factorize avpriv_mirror() out
Michael Niedermayer
git at videolan.org
Mon Jan 5 16:03:37 CET 2015
ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sun Jan 4 04:15:01 2015 +0100| [0f931b29f7e969a3c6159cb7173226e806f26f39] | committer: Michael Niedermayer
Factorize avpriv_mirror() out
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0f931b29f7e969a3c6159cb7173226e806f26f39
---
libavcodec/dirac_dwt.c | 30 +++++++------------
libavcodec/snow_dwt.c | 70 +++++++++++++++++++-------------------------
libavfilter/transform.c | 14 ++-------
libavfilter/vf_owdenoise.c | 17 +++--------
libavfilter/vf_sab.c | 19 ++----------
libavutil/internal.h | 13 ++++++++
6 files changed, 62 insertions(+), 101 deletions(-)
diff --git a/libavcodec/dirac_dwt.c b/libavcodec/dirac_dwt.c
index 96d8bae..da2da75 100644
--- a/libavcodec/dirac_dwt.c
+++ b/libavcodec/dirac_dwt.c
@@ -26,16 +26,6 @@
#include "libavcodec/x86/dirac_dwt.h"
-static inline int mirror(int v, int m)
-{
- while ((unsigned)v > (unsigned)m) {
- v = -v;
- if (v < 0)
- v += 2 * m;
- }
- return v;
-}
-
static void vertical_compose53iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
int width)
{
@@ -307,8 +297,8 @@ static void spatial_compose_dirac53i_dy(DWTContext *d, int level, int width, int
int y= cs->y;
IDWTELEM *b[4] = { cs->b[0], cs->b[1] };
- b[2] = d->buffer + mirror(y+1, height-1)*stride;
- b[3] = d->buffer + mirror(y+2, height-1)*stride;
+ b[2] = d->buffer + avpriv_mirror(y+1, height-1)*stride;
+ b[3] = d->buffer + avpriv_mirror(y+2, height-1)*stride;
if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width);
if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width);
@@ -400,8 +390,8 @@ static void spatial_compose_daub97i_dy(DWTContext *d, int level, int width, int
IDWTELEM *b[6];
for (i = 0; i < 4; i++)
b[i] = cs->b[i];
- b[4] = d->buffer + mirror(y+3, height-1)*stride;
- b[5] = d->buffer + mirror(y+4, height-1)*stride;
+ b[4] = d->buffer + avpriv_mirror(y+3, height-1)*stride;
+ b[5] = d->buffer + avpriv_mirror(y+4, height-1)*stride;
if(y+3<(unsigned)height) vertical_compose_l1(b[3], b[4], b[5], width);
if(y+2<(unsigned)height) vertical_compose_h1(b[2], b[3], b[4], width);
@@ -419,17 +409,17 @@ static void spatial_compose_daub97i_dy(DWTContext *d, int level, int width, int
static void spatial_compose97i_init2(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
{
- cs->b[0] = buffer + mirror(-3-1, height-1)*stride;
- cs->b[1] = buffer + mirror(-3 , height-1)*stride;
- cs->b[2] = buffer + mirror(-3+1, height-1)*stride;
- cs->b[3] = buffer + mirror(-3+2, height-1)*stride;
+ cs->b[0] = buffer + avpriv_mirror(-3-1, height-1)*stride;
+ cs->b[1] = buffer + avpriv_mirror(-3 , height-1)*stride;
+ cs->b[2] = buffer + avpriv_mirror(-3+1, height-1)*stride;
+ cs->b[3] = buffer + avpriv_mirror(-3+2, height-1)*stride;
cs->y = -3;
}
static void spatial_compose53i_init2(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
{
- cs->b[0] = buffer + mirror(-1-1, height-1)*stride;
- cs->b[1] = buffer + mirror(-1 , height-1)*stride;
+ cs->b[0] = buffer + avpriv_mirror(-1-1, height-1)*stride;
+ cs->b[1] = buffer + avpriv_mirror(-1 , height-1)*stride;
cs->y = -1;
}
diff --git a/libavcodec/snow_dwt.c b/libavcodec/snow_dwt.c
index 986a6b9..ecba0ea 100644
--- a/libavcodec/snow_dwt.c
+++ b/libavcodec/snow_dwt.c
@@ -112,16 +112,6 @@ void ff_slice_buffer_destroy(slice_buffer *buf)
av_freep(&buf->line);
}
-static inline int mirror(int v, int m)
-{
- while ((unsigned)v > (unsigned)m) {
- v = -v;
- if (v < 0)
- v += 2 * m;
- }
- return v;
-}
-
static av_always_inline void lift(DWTELEM *dst, DWTELEM *src, DWTELEM *ref,
int dst_step, int src_step, int ref_step,
int width, int mul, int add, int shift,
@@ -223,12 +213,12 @@ static void spatial_decompose53i(DWTELEM *buffer, DWTELEM *temp,
int width, int height, int stride)
{
int y;
- DWTELEM *b0 = buffer + mirror(-2 - 1, height - 1) * stride;
- DWTELEM *b1 = buffer + mirror(-2, height - 1) * stride;
+ DWTELEM *b0 = buffer + avpriv_mirror(-2 - 1, height - 1) * stride;
+ DWTELEM *b1 = buffer + avpriv_mirror(-2, height - 1) * stride;
for (y = -2; y < height; y += 2) {
- DWTELEM *b2 = buffer + mirror(y + 1, height - 1) * stride;
- DWTELEM *b3 = buffer + mirror(y + 2, height - 1) * stride;
+ DWTELEM *b2 = buffer + avpriv_mirror(y + 1, height - 1) * stride;
+ DWTELEM *b3 = buffer + avpriv_mirror(y + 2, height - 1) * stride;
if (y + 1 < (unsigned)height)
horizontal_decompose53i(b2, temp, width);
@@ -296,14 +286,14 @@ static void spatial_decompose97i(DWTELEM *buffer, DWTELEM *temp,
int width, int height, int stride)
{
int y;
- DWTELEM *b0 = buffer + mirror(-4 - 1, height - 1) * stride;
- DWTELEM *b1 = buffer + mirror(-4, height - 1) * stride;
- DWTELEM *b2 = buffer + mirror(-4 + 1, height - 1) * stride;
- DWTELEM *b3 = buffer + mirror(-4 + 2, height - 1) * stride;
+ DWTELEM *b0 = buffer + avpriv_mirror(-4 - 1, height - 1) * stride;
+ DWTELEM *b1 = buffer + avpriv_mirror(-4, height - 1) * stride;
+ DWTELEM *b2 = buffer + avpriv_mirror(-4 + 1, height - 1) * stride;
+ DWTELEM *b3 = buffer + avpriv_mirror(-4 + 2, height - 1) * stride;
for (y = -4; y < height; y += 2) {
- DWTELEM *b4 = buffer + mirror(y + 3, height - 1) * stride;
- DWTELEM *b5 = buffer + mirror(y + 4, height - 1) * stride;
+ DWTELEM *b4 = buffer + avpriv_mirror(y + 3, height - 1) * stride;
+ DWTELEM *b5 = buffer + avpriv_mirror(y + 4, height - 1) * stride;
if (y + 3 < (unsigned)height)
horizontal_decompose97i(b4, temp, width);
@@ -394,16 +384,16 @@ static void spatial_compose53i_buffered_init(DWTCompose *cs, slice_buffer *sb,
int height, int stride_line)
{
cs->b0 = slice_buffer_get_line(sb,
- mirror(-1 - 1, height - 1) * stride_line);
- cs->b1 = slice_buffer_get_line(sb, mirror(-1, height - 1) * stride_line);
+ avpriv_mirror(-1 - 1, height - 1) * stride_line);
+ cs->b1 = slice_buffer_get_line(sb, avpriv_mirror(-1, height - 1) * stride_line);
cs->y = -1;
}
static void spatial_compose53i_init(DWTCompose *cs, IDWTELEM *buffer,
int height, int stride)
{
- cs->b0 = buffer + mirror(-1 - 1, height - 1) * stride;
- cs->b1 = buffer + mirror(-1, height - 1) * stride;
+ cs->b0 = buffer + avpriv_mirror(-1 - 1, height - 1) * stride;
+ cs->b1 = buffer + avpriv_mirror(-1, height - 1) * stride;
cs->y = -1;
}
@@ -417,10 +407,10 @@ static void spatial_compose53i_dy_buffered(DWTCompose *cs, slice_buffer *sb,
IDWTELEM *b0 = cs->b0;
IDWTELEM *b1 = cs->b1;
IDWTELEM *b2 = slice_buffer_get_line(sb,
- mirror(y + 1, height - 1) *
+ avpriv_mirror(y + 1, height - 1) *
stride_line);
IDWTELEM *b3 = slice_buffer_get_line(sb,
- mirror(y + 2, height - 1) *
+ avpriv_mirror(y + 2, height - 1) *
stride_line);
if (y + 1 < (unsigned)height && y < (unsigned)height) {
@@ -454,8 +444,8 @@ static void spatial_compose53i_dy(DWTCompose *cs, IDWTELEM *buffer,
int y = cs->y;
IDWTELEM *b0 = cs->b0;
IDWTELEM *b1 = cs->b1;
- IDWTELEM *b2 = buffer + mirror(y + 1, height - 1) * stride;
- IDWTELEM *b3 = buffer + mirror(y + 2, height - 1) * stride;
+ IDWTELEM *b2 = buffer + avpriv_mirror(y + 1, height - 1) * stride;
+ IDWTELEM *b3 = buffer + avpriv_mirror(y + 2, height - 1) * stride;
if (y + 1 < (unsigned)height)
vertical_compose53iL0(b1, b2, b3, width);
@@ -553,20 +543,20 @@ void ff_snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
static void spatial_compose97i_buffered_init(DWTCompose *cs, slice_buffer *sb,
int height, int stride_line)
{
- cs->b0 = slice_buffer_get_line(sb, mirror(-3 - 1, height - 1) * stride_line);
- cs->b1 = slice_buffer_get_line(sb, mirror(-3, height - 1) * stride_line);
- cs->b2 = slice_buffer_get_line(sb, mirror(-3 + 1, height - 1) * stride_line);
- cs->b3 = slice_buffer_get_line(sb, mirror(-3 + 2, height - 1) * stride_line);
+ cs->b0 = slice_buffer_get_line(sb, avpriv_mirror(-3 - 1, height - 1) * stride_line);
+ cs->b1 = slice_buffer_get_line(sb, avpriv_mirror(-3, height - 1) * stride_line);
+ cs->b2 = slice_buffer_get_line(sb, avpriv_mirror(-3 + 1, height - 1) * stride_line);
+ cs->b3 = slice_buffer_get_line(sb, avpriv_mirror(-3 + 2, height - 1) * stride_line);
cs->y = -3;
}
static void spatial_compose97i_init(DWTCompose *cs, IDWTELEM *buffer, int height,
int stride)
{
- cs->b0 = buffer + mirror(-3 - 1, height - 1) * stride;
- cs->b1 = buffer + mirror(-3, height - 1) * stride;
- cs->b2 = buffer + mirror(-3 + 1, height - 1) * stride;
- cs->b3 = buffer + mirror(-3 + 2, height - 1) * stride;
+ cs->b0 = buffer + avpriv_mirror(-3 - 1, height - 1) * stride;
+ cs->b1 = buffer + avpriv_mirror(-3, height - 1) * stride;
+ cs->b2 = buffer + avpriv_mirror(-3 + 1, height - 1) * stride;
+ cs->b3 = buffer + avpriv_mirror(-3 + 2, height - 1) * stride;
cs->y = -3;
}
@@ -582,10 +572,10 @@ static void spatial_compose97i_dy_buffered(SnowDWTContext *dsp, DWTCompose *cs,
IDWTELEM *b2 = cs->b2;
IDWTELEM *b3 = cs->b3;
IDWTELEM *b4 = slice_buffer_get_line(sb,
- mirror(y + 3, height - 1) *
+ avpriv_mirror(y + 3, height - 1) *
stride_line);
IDWTELEM *b5 = slice_buffer_get_line(sb,
- mirror(y + 4, height - 1) *
+ avpriv_mirror(y + 4, height - 1) *
stride_line);
if (y > 0 && y + 4 < height) {
@@ -622,8 +612,8 @@ static void spatial_compose97i_dy(DWTCompose *cs, IDWTELEM *buffer,
IDWTELEM *b1 = cs->b1;
IDWTELEM *b2 = cs->b2;
IDWTELEM *b3 = cs->b3;
- IDWTELEM *b4 = buffer + mirror(y + 3, height - 1) * stride;
- IDWTELEM *b5 = buffer + mirror(y + 4, height - 1) * stride;
+ IDWTELEM *b4 = buffer + avpriv_mirror(y + 3, height - 1) * stride;
+ IDWTELEM *b5 = buffer + avpriv_mirror(y + 4, height - 1) * stride;
if (y + 3 < (unsigned)height)
vertical_compose97iL1(b3, b4, b5, width);
diff --git a/libavfilter/transform.c b/libavfilter/transform.c
index 3fc547e..f92fc4d 100644
--- a/libavfilter/transform.c
+++ b/libavfilter/transform.c
@@ -136,16 +136,6 @@ 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;
-}
-
int avfilter_transform(const uint8_t *src, uint8_t *dst,
int src_stride, int dst_stride,
int width, int height, const float *matrix,
@@ -186,8 +176,8 @@ int avfilter_transform(const uint8_t *src, uint8_t *dst,
def = src[(int)y_s * src_stride + (int)x_s];
break;
case FILL_MIRROR:
- x_s = mirror(x_s, width-1);
- y_s = mirror(y_s, height-1);
+ x_s = avpriv_mirror(x_s, width-1);
+ y_s = avpriv_mirror(y_s, height-1);
av_assert2(x_s >= 0 && y_s >= 0);
av_assert2(x_s < width && y_s < height);
diff --git a/libavfilter/vf_owdenoise.c b/libavfilter/vf_owdenoise.c
index 5b47f76..29322b1 100644
--- a/libavfilter/vf_owdenoise.c
+++ b/libavfilter/vf_owdenoise.c
@@ -98,15 +98,6 @@ static const double icoeff[2][5] = {
}
};
-static inline int mirror(int x, int w)
-{
- while ((unsigned)x > (unsigned)w) {
- x = -x;
- if (x < 0)
- x += 2 * w;
- }
- return x;
-}
static inline void decompose(float *dst_l, float *dst_h, const float *src,
int linesize, int w)
@@ -116,8 +107,8 @@ static inline void decompose(float *dst_l, float *dst_h, const float *src,
double sum_l = src[x * linesize] * coeff[0][0];
double sum_h = src[x * linesize] * coeff[1][0];
for (i = 1; i <= 4; i++) {
- const double s = src[mirror(x - i, w - 1) * linesize]
- + src[mirror(x + i, w - 1) * linesize];
+ const double s = src[avpriv_mirror(x - i, w - 1) * linesize]
+ + src[avpriv_mirror(x + i, w - 1) * linesize];
sum_l += coeff[0][i] * s;
sum_h += coeff[1][i] * s;
@@ -135,8 +126,8 @@ static inline void compose(float *dst, const float *src_l, const float *src_h,
double sum_l = src_l[x * linesize] * icoeff[0][0];
double sum_h = src_h[x * linesize] * icoeff[1][0];
for (i = 1; i <= 4; i++) {
- const int x0 = mirror(x - i, w - 1) * linesize;
- const int x1 = mirror(x + i, w - 1) * linesize;
+ const int x0 = avpriv_mirror(x - i, w - 1) * linesize;
+ const int x1 = avpriv_mirror(x + i, w - 1) * linesize;
sum_l += icoeff[0][i] * (src_l[x0] + src_l[x1]);
sum_h += icoeff[1][i] * (src_h[x0] + src_h[x1]);
diff --git a/libavfilter/vf_sab.c b/libavfilter/vf_sab.c
index b8af27c..b8bf1bc 100644
--- a/libavfilter/vf_sab.c
+++ b/libavfilter/vf_sab.c
@@ -220,19 +220,6 @@ static int config_props(AVFilterLink *inlink)
#define NB_PLANES 4
-static inline int mirror(int x, int w)
-{
- if (!w)
- return 0;
-
- while ((unsigned)x > (unsigned)w) {
- x = -x;
- if (x < 0)
- x += 2 * w;
- }
- return x;
-}
-
static void blur(uint8_t *dst, const int dst_linesize,
const uint8_t *src, const int src_linesize,
const int w, const int h, FilterParam *fp)
@@ -266,7 +253,7 @@ static void blur(uint8_t *dst, const int dst_linesize,
for (dy = 0; dy < radius*2 + 1; dy++) {
int dx;
int iy = y+dy - radius;
- iy = mirror(iy, h-1);
+ iy = avpriv_mirror(iy, h-1);
for (dx = 0; dx < radius*2 + 1; dx++) {
const int ix = x+dx - radius;
@@ -277,11 +264,11 @@ static void blur(uint8_t *dst, const int dst_linesize,
for (dy = 0; dy < radius*2+1; dy++) {
int dx;
int iy = y+dy - radius;
- iy = mirror(iy, h-1);
+ iy = avpriv_mirror(iy, h-1);
for (dx = 0; dx < radius*2 + 1; dx++) {
int ix = x+dx - radius;
- ix = mirror(ix, w-1);
+ ix = avpriv_mirror(ix, w-1);
UPDATE_FACTOR;
}
}
diff --git a/libavutil/internal.h b/libavutil/internal.h
index 77af6f9..0a20142 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -256,6 +256,19 @@ int avpriv_open(const char *filename, int flags, ...);
int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt);
+static av_always_inline av_const int avpriv_mirror(int x, int w)
+{
+ if (!w)
+ return 0;
+
+ while ((unsigned)x > (unsigned)w) {
+ x = -x;
+ if (x < 0)
+ x += 2 * w;
+ }
+ return x;
+}
+
#if FF_API_GET_CHANNEL_LAYOUT_COMPAT
uint64_t ff_get_channel_layout(const char *name, int compat);
#endif
More information about the ffmpeg-cvslog
mailing list