[FFmpeg-cvslog] dsputil_template: Detemplatize the code

Diego Biurrun git at videolan.org
Wed Mar 26 15:07:09 CET 2014


ffmpeg | branch: master | Diego Biurrun <diego at biurrun.de> | Thu Jan  9 12:09:35 2014 +0100| [2c01ad8b206d326700974438f7193f22be416eb1] | committer: Diego Biurrun

dsputil_template: Detemplatize the code

The indirection makes no sense without multiple instantiation.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2c01ad8b206d326700974438f7193f22be416eb1
---

 libavcodec/dsputil.c          |   18 +---
 libavcodec/dsputil_template.c |  223 ++++++++++++++++++++---------------------
 2 files changed, 114 insertions(+), 127 deletions(-)

diff --git a/libavcodec/dsputil.c b/libavcodec/dsputil.c
index 5bb9441..4a2011a 100644
--- a/libavcodec/dsputil.c
+++ b/libavcodec/dsputil.c
@@ -2602,26 +2602,18 @@ av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
 
     c->add_pixels8 = add_pixels8_c;
 
-#undef FUNC
-#undef FUNCC
-#define FUNC(f,  depth) f ## _ ## depth
-#define FUNCC(f, depth) f ## _ ## depth ## _c
+    c->draw_edges = draw_edges_8_c;
 
-    c->draw_edges = FUNCC(draw_edges, 8);
-
-    c->clear_block  = FUNCC(clear_block, 8);
-    c->clear_blocks = FUNCC(clear_blocks, 8);
-
-#define BIT_DEPTH_FUNCS(depth)                  \
-    c->get_pixels = FUNCC(get_pixels, depth);
+    c->clear_block  = clear_block_8_c;
+    c->clear_blocks = clear_blocks_8_c;
 
     switch (avctx->bits_per_raw_sample) {
     case 9:
     case 10:
-        BIT_DEPTH_FUNCS(16);
+        c->get_pixels = get_pixels_16_c;
         break;
     default:
-        BIT_DEPTH_FUNCS(8);
+        c->get_pixels = get_pixels_8_c;
         break;
     }
 
diff --git a/libavcodec/dsputil_template.c b/libavcodec/dsputil_template.c
index f9bf5f1..7d8ae15 100644
--- a/libavcodec/dsputil_template.c
+++ b/libavcodec/dsputil_template.c
@@ -29,16 +29,12 @@
 
 #include "pixels.h"
 
-#include "bit_depth_template.c"
-
 /* draw the edges of width 'w' of an image of size width, height */
 // FIXME: Check that this is OK for MPEG-4 interlaced.
-static void FUNCC(draw_edges)(uint8_t *_buf, int _wrap, int width, int height,
-                              int w, int h, int sides)
+static void draw_edges_8_c(uint8_t *buf, int wrap, int width, int height,
+                           int w, int h, int sides)
 {
-    pixel *buf = (pixel *) _buf;
-    int wrap   = _wrap / sizeof(pixel);
-    pixel *ptr = buf, *last_line;
+    uint8_t *ptr = buf, *last_line;
     int i;
 
     /* left and right */
@@ -54,76 +50,75 @@ static void FUNCC(draw_edges)(uint8_t *_buf, int _wrap, int width, int height,
     if (sides & EDGE_TOP)
         for (i = 0; i < h; i++)
             // top
-            memcpy(buf - (i + 1) * wrap, buf, (width + w + w) * sizeof(pixel));
+            memcpy(buf - (i + 1) * wrap, buf, width + w + w);
     if (sides & EDGE_BOTTOM)
         for (i = 0; i < h; i++)
             // bottom
-            memcpy(last_line + (i + 1) * wrap, last_line,
-                   (width + w + w) * sizeof(pixel));
+            memcpy(last_line + (i + 1) * wrap, last_line, width + w + w);
 }
 
-static void FUNCC(clear_block)(int16_t *block)
+static void clear_block_8_c(int16_t *block)
 {
     memset(block, 0, sizeof(int16_t) * 64);
 }
 
-static void FUNCC(clear_blocks)(int16_t *blocks)
+static void clear_blocks_8_c(int16_t *blocks)
 {
     memset(blocks, 0, sizeof(int16_t) * 6 * 64);
 }
 
 #define PIXOP2(OPNAME, OP)                                              \
-static inline void FUNC(OPNAME ## _no_rnd_pixels8_l2)(uint8_t *dst,     \
-                                                      const uint8_t *src1, \
-                                                      const uint8_t *src2, \
-                                                      int dst_stride,   \
-                                                      int src_stride1,  \
-                                                      int src_stride2,  \
-                                                      int h)            \
+static inline void OPNAME ## _no_rnd_pixels8_l2_8(uint8_t *dst,         \
+                                                  const uint8_t *src1,  \
+                                                  const uint8_t *src2,  \
+                                                  int dst_stride,       \
+                                                  int src_stride1,      \
+                                                  int src_stride2,      \
+                                                  int h)                \
 {                                                                       \
     int i;                                                              \
                                                                         \
     for (i = 0; i < h; i++) {                                           \
-        pixel4 a, b;                                                    \
-        a = AV_RN4P(&src1[i * src_stride1]);                            \
-        b = AV_RN4P(&src2[i * src_stride2]);                            \
-        OP(*((pixel4 *) &dst[i * dst_stride]),                          \
-           no_rnd_avg_pixel4(a, b));                                    \
-        a = AV_RN4P(&src1[i * src_stride1 + 4 * sizeof(pixel)]);        \
-        b = AV_RN4P(&src2[i * src_stride2 + 4 * sizeof(pixel)]);        \
-        OP(*((pixel4 *) &dst[i * dst_stride + 4 * sizeof(pixel)]),      \
-           no_rnd_avg_pixel4(a, b));                                    \
+        uint32_t a, b;                                                  \
+        a = AV_RN32(&src1[i * src_stride1]);                            \
+        b = AV_RN32(&src2[i * src_stride2]);                            \
+        OP(*((uint32_t *) &dst[i * dst_stride]),                        \
+           no_rnd_avg32(a, b));                                         \
+        a = AV_RN32(&src1[i * src_stride1 + 4]);                        \
+        b = AV_RN32(&src2[i * src_stride2 + 4]);                        \
+        OP(*((uint32_t *) &dst[i * dst_stride + 4]),                    \
+           no_rnd_avg32(a, b));                                         \
     }                                                                   \
 }                                                                       \
                                                                         \
-static inline void FUNC(OPNAME ## _no_rnd_pixels16_l2)(uint8_t *dst,    \
-                                                       const uint8_t *src1, \
-                                                       const uint8_t *src2, \
-                                                       int dst_stride,  \
-                                                       int src_stride1, \
-                                                       int src_stride2, \
-                                                       int h)           \
+static inline void OPNAME ## _no_rnd_pixels16_l2_8(uint8_t *dst,        \
+                                                   const uint8_t *src1, \
+                                                   const uint8_t *src2, \
+                                                   int dst_stride,      \
+                                                   int src_stride1,     \
+                                                   int src_stride2,     \
+                                                   int h)               \
 {                                                                       \
-    FUNC(OPNAME ## _no_rnd_pixels8_l2)(dst, src1, src2, dst_stride,     \
-                                       src_stride1, src_stride2, h);    \
-    FUNC(OPNAME ## _no_rnd_pixels8_l2)(dst  + 8 * sizeof(pixel),        \
-                                       src1 + 8 * sizeof(pixel),        \
-                                       src2 + 8 * sizeof(pixel),        \
-                                       dst_stride, src_stride1,         \
-                                       src_stride2, h);                 \
+    OPNAME ## _no_rnd_pixels8_l2_8(dst, src1, src2, dst_stride,         \
+                                   src_stride1, src_stride2, h);        \
+    OPNAME ## _no_rnd_pixels8_l2_8(dst  + 8,                            \
+                                   src1 + 8,                            \
+                                   src2 + 8,                            \
+                                   dst_stride, src_stride1,             \
+                                   src_stride2, h);                     \
 }                                                                       \
                                                                         \
-static inline void FUNC(OPNAME ## _pixels8_l4)(uint8_t *dst,            \
-                                               const uint8_t *src1,     \
-                                               const uint8_t *src2,     \
-                                               const uint8_t *src3,     \
-                                               const uint8_t *src4,     \
-                                               int dst_stride,          \
-                                               int src_stride1,         \
-                                               int src_stride2,         \
-                                               int src_stride3,         \
-                                               int src_stride4,         \
-                                               int h)                   \
+static inline void OPNAME ## _pixels8_l4_8(uint8_t *dst,                \
+                                           const uint8_t *src1,         \
+                                           const uint8_t *src2,         \
+                                           const uint8_t *src3,         \
+                                           const uint8_t *src4,         \
+                                           int dst_stride,              \
+                                           int src_stride1,             \
+                                           int src_stride2,             \
+                                           int src_stride3,             \
+                                           int src_stride4,             \
+                                           int h)                       \
 {                                                                       \
     /* FIXME HIGH BIT DEPTH */                                          \
     int i;                                                              \
@@ -163,17 +158,17 @@ static inline void FUNC(OPNAME ## _pixels8_l4)(uint8_t *dst,            \
     }                                                                   \
 }                                                                       \
                                                                         \
-static inline void FUNC(OPNAME ## _no_rnd_pixels8_l4)(uint8_t *dst,     \
-                                                      const uint8_t *src1, \
-                                                      const uint8_t *src2, \
-                                                      const uint8_t *src3, \
-                                                      const uint8_t *src4, \
-                                                      int dst_stride,   \
-                                                      int src_stride1,  \
-                                                      int src_stride2,  \
-                                                      int src_stride3,  \
-                                                      int src_stride4,  \
-                                                      int h)            \
+static inline void OPNAME ## _no_rnd_pixels8_l4_8(uint8_t *dst,         \
+                                                  const uint8_t *src1,  \
+                                                  const uint8_t *src2,  \
+                                                  const uint8_t *src3,  \
+                                                  const uint8_t *src4,  \
+                                                  int dst_stride,       \
+                                                  int src_stride1,      \
+                                                  int src_stride2,      \
+                                                  int src_stride3,      \
+                                                  int src_stride4,      \
+                                                  int h)                \
 {                                                                       \
     /* FIXME HIGH BIT DEPTH */                                          \
     int i;                                                              \
@@ -212,57 +207,57 @@ static inline void FUNC(OPNAME ## _no_rnd_pixels8_l4)(uint8_t *dst,     \
            h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL));                \
     }                                                                   \
 }                                                                       \
-static inline void FUNC(OPNAME ## _pixels16_l4)(uint8_t *dst,           \
-                                                const uint8_t *src1,    \
-                                                const uint8_t *src2,    \
-                                                const uint8_t *src3,    \
-                                                const uint8_t *src4,    \
-                                                int dst_stride,         \
-                                                int src_stride1,        \
-                                                int src_stride2,        \
-                                                int src_stride3,        \
-                                                int src_stride4,        \
-                                                int h)                  \
+                                                                        \
+static inline void OPNAME ## _pixels16_l4_8(uint8_t *dst,               \
+                                            const uint8_t *src1,        \
+                                            const uint8_t *src2,        \
+                                            const uint8_t *src3,        \
+                                            const uint8_t *src4,        \
+                                            int dst_stride,             \
+                                            int src_stride1,            \
+                                            int src_stride2,            \
+                                            int src_stride3,            \
+                                            int src_stride4,            \
+                                            int h)                      \
 {                                                                       \
-    FUNC(OPNAME ## _pixels8_l4)(dst, src1, src2, src3, src4, dst_stride, \
-                                src_stride1, src_stride2, src_stride3,  \
-                                src_stride4, h);                        \
-    FUNC(OPNAME ## _pixels8_l4)(dst  + 8 * sizeof(pixel),               \
-                                src1 + 8 * sizeof(pixel),               \
-                                src2 + 8 * sizeof(pixel),               \
-                                src3 + 8 * sizeof(pixel),               \
-                                src4 + 8 * sizeof(pixel),               \
-                                dst_stride, src_stride1, src_stride2,   \
-                                src_stride3, src_stride4, h);           \
+    OPNAME ## _pixels8_l4_8(dst, src1, src2, src3, src4, dst_stride,    \
+                            src_stride1, src_stride2, src_stride3,      \
+                            src_stride4, h);                            \
+    OPNAME ## _pixels8_l4_8(dst  + 8,                                   \
+                            src1 + 8, src2 + 8,                         \
+                            src3 + 8, src4 + 8,                         \
+                            dst_stride, src_stride1, src_stride2,       \
+                            src_stride3, src_stride4, h);               \
 }                                                                       \
-static inline void FUNC(OPNAME ## _no_rnd_pixels16_l4)(uint8_t *dst,    \
-                                                       const uint8_t *src1, \
-                                                       const uint8_t *src2, \
-                                                       const uint8_t *src3, \
-                                                       const uint8_t *src4, \
-                                                       int dst_stride,  \
-                                                       int src_stride1, \
-                                                       int src_stride2, \
-                                                       int src_stride3, \
-                                                       int src_stride4, \
-                                                       int h)           \
+                                                                        \
+static inline void OPNAME ## _no_rnd_pixels16_l4_8(uint8_t *dst,        \
+                                                   const uint8_t *src1, \
+                                                   const uint8_t *src2, \
+                                                   const uint8_t *src3, \
+                                                   const uint8_t *src4, \
+                                                   int dst_stride,      \
+                                                   int src_stride1,     \
+                                                   int src_stride2,     \
+                                                   int src_stride3,     \
+                                                   int src_stride4,     \
+                                                   int h)               \
 {                                                                       \
-    FUNC(OPNAME ## _no_rnd_pixels8_l4)(dst, src1, src2, src3, src4,     \
-                                       dst_stride, src_stride1, src_stride2, \
-                                       src_stride3, src_stride4, h);    \
-    FUNC(OPNAME ## _no_rnd_pixels8_l4)(dst  + 8 * sizeof(pixel),        \
-                                       src1 + 8 * sizeof(pixel),        \
-                                       src2 + 8 * sizeof(pixel),        \
-                                       src3 + 8 * sizeof(pixel),        \
-                                       src4 + 8 * sizeof(pixel),        \
-                                       dst_stride, src_stride1, src_stride2, \
-                                       src_stride3, src_stride4, h);    \
+    OPNAME ## _no_rnd_pixels8_l4_8(dst, src1, src2, src3, src4,         \
+                                   dst_stride, src_stride1,             \
+                                   src_stride2, src_stride3,            \
+                                   src_stride4, h);                     \
+    OPNAME ## _no_rnd_pixels8_l4_8(dst  + 8,                            \
+                                   src1 + 8, src2 + 8,                  \
+                                   src3 + 8, src4 + 8,                  \
+                                   dst_stride, src_stride1,             \
+                                   src_stride2, src_stride3,            \
+                                   src_stride4, h);                     \
 }                                                                       \
                                                                         \
-static inline void FUNCC(OPNAME ## _pixels8_xy2)(uint8_t *block,        \
-                                                 const uint8_t *pixels, \
-                                                 ptrdiff_t line_size,   \
-                                                 int h)                 \
+static inline void OPNAME ## _pixels8_xy2_8_c(uint8_t *block,           \
+                                              const uint8_t *pixels,    \
+                                              ptrdiff_t line_size,      \
+                                              int h)                    \
 {                                                                       \
     /* FIXME HIGH BIT DEPTH */                                          \
     int j;                                                              \
@@ -307,11 +302,11 @@ static inline void FUNCC(OPNAME ## _pixels8_xy2)(uint8_t *block,        \
     }                                                                   \
 }                                                                       \
                                                                         \
-CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_xy2),                          \
-               FUNCC(OPNAME ## _pixels8_xy2),                           \
-               8 * sizeof(pixel))                                       \
+CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_8_c,                             \
+               OPNAME ## _pixels8_xy2_8_c,                              \
+               8)                                                       \
 
-#define op_avg(a, b) a = rnd_avg_pixel4(a, b)
+#define op_avg(a, b) a = rnd_avg32(a, b)
 #define op_put(a, b) a = b
 #define put_no_rnd_pixels8_8_c put_pixels8_8_c
 PIXOP2(avg, op_avg)



More information about the ffmpeg-cvslog mailing list