dsputil_template: Detemplatize the code

The indirection makes no sense without multiple instantiation.
pull/64/head
Diego Biurrun 11 years ago
parent aba70bb538
commit 2c01ad8b20
  1. 18
      libavcodec/dsputil.c
  2. 97
      libavcodec/dsputil_template.c

@ -2602,26 +2602,18 @@ av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
c->add_pixels8 = add_pixels8_c; c->add_pixels8 = add_pixels8_c;
#undef FUNC c->draw_edges = draw_edges_8_c;
#undef FUNCC
#define FUNC(f, depth) f ## _ ## depth
#define FUNCC(f, depth) f ## _ ## depth ## _c
c->draw_edges = FUNCC(draw_edges, 8); c->clear_block = clear_block_8_c;
c->clear_blocks = clear_blocks_8_c;
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);
switch (avctx->bits_per_raw_sample) { switch (avctx->bits_per_raw_sample) {
case 9: case 9:
case 10: case 10:
BIT_DEPTH_FUNCS(16); c->get_pixels = get_pixels_16_c;
break; break;
default: default:
BIT_DEPTH_FUNCS(8); c->get_pixels = get_pixels_8_c;
break; break;
} }

@ -29,16 +29,12 @@
#include "pixels.h" #include "pixels.h"
#include "bit_depth_template.c"
/* draw the edges of width 'w' of an image of size width, height */ /* draw the edges of width 'w' of an image of size width, height */
// FIXME: Check that this is OK for MPEG-4 interlaced. // FIXME: Check that this is OK for MPEG-4 interlaced.
static void FUNCC(draw_edges)(uint8_t *_buf, int _wrap, int width, int height, static void draw_edges_8_c(uint8_t *buf, int wrap, int width, int height,
int w, int h, int sides) int w, int h, int sides)
{ {
pixel *buf = (pixel *) _buf; uint8_t *ptr = buf, *last_line;
int wrap = _wrap / sizeof(pixel);
pixel *ptr = buf, *last_line;
int i; int i;
/* left and right */ /* left and right */
@ -54,26 +50,25 @@ static void FUNCC(draw_edges)(uint8_t *_buf, int _wrap, int width, int height,
if (sides & EDGE_TOP) if (sides & EDGE_TOP)
for (i = 0; i < h; i++) for (i = 0; i < h; i++)
// top // 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) if (sides & EDGE_BOTTOM)
for (i = 0; i < h; i++) for (i = 0; i < h; i++)
// bottom // bottom
memcpy(last_line + (i + 1) * wrap, last_line, memcpy(last_line + (i + 1) * wrap, last_line, width + w + w);
(width + w + w) * sizeof(pixel));
} }
static void FUNCC(clear_block)(int16_t *block) static void clear_block_8_c(int16_t *block)
{ {
memset(block, 0, sizeof(int16_t) * 64); 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); memset(blocks, 0, sizeof(int16_t) * 6 * 64);
} }
#define PIXOP2(OPNAME, OP) \ #define PIXOP2(OPNAME, OP) \
static inline void FUNC(OPNAME ## _no_rnd_pixels8_l2)(uint8_t *dst, \ static inline void OPNAME ## _no_rnd_pixels8_l2_8(uint8_t *dst, \
const uint8_t *src1, \ const uint8_t *src1, \
const uint8_t *src2, \ const uint8_t *src2, \
int dst_stride, \ int dst_stride, \
@ -84,19 +79,19 @@ static inline void FUNC(OPNAME ## _no_rnd_pixels8_l2)(uint8_t *dst, \
int i; \ int i; \
\ \
for (i = 0; i < h; i++) { \ for (i = 0; i < h; i++) { \
pixel4 a, b; \ uint32_t a, b; \
a = AV_RN4P(&src1[i * src_stride1]); \ a = AV_RN32(&src1[i * src_stride1]); \
b = AV_RN4P(&src2[i * src_stride2]); \ b = AV_RN32(&src2[i * src_stride2]); \
OP(*((pixel4 *) &dst[i * dst_stride]), \ OP(*((uint32_t *) &dst[i * dst_stride]), \
no_rnd_avg_pixel4(a, b)); \ no_rnd_avg32(a, b)); \
a = AV_RN4P(&src1[i * src_stride1 + 4 * sizeof(pixel)]); \ a = AV_RN32(&src1[i * src_stride1 + 4]); \
b = AV_RN4P(&src2[i * src_stride2 + 4 * sizeof(pixel)]); \ b = AV_RN32(&src2[i * src_stride2 + 4]); \
OP(*((pixel4 *) &dst[i * dst_stride + 4 * sizeof(pixel)]), \ OP(*((uint32_t *) &dst[i * dst_stride + 4]), \
no_rnd_avg_pixel4(a, b)); \ no_rnd_avg32(a, b)); \
} \ } \
} \ } \
\ \
static inline void FUNC(OPNAME ## _no_rnd_pixels16_l2)(uint8_t *dst, \ static inline void OPNAME ## _no_rnd_pixels16_l2_8(uint8_t *dst, \
const uint8_t *src1, \ const uint8_t *src1, \
const uint8_t *src2, \ const uint8_t *src2, \
int dst_stride, \ int dst_stride, \
@ -104,16 +99,16 @@ static inline void FUNC(OPNAME ## _no_rnd_pixels16_l2)(uint8_t *dst, \
int src_stride2, \ int src_stride2, \
int h) \ int h) \
{ \ { \
FUNC(OPNAME ## _no_rnd_pixels8_l2)(dst, src1, src2, dst_stride, \ OPNAME ## _no_rnd_pixels8_l2_8(dst, src1, src2, dst_stride, \
src_stride1, src_stride2, h); \ src_stride1, src_stride2, h); \
FUNC(OPNAME ## _no_rnd_pixels8_l2)(dst + 8 * sizeof(pixel), \ OPNAME ## _no_rnd_pixels8_l2_8(dst + 8, \
src1 + 8 * sizeof(pixel), \ src1 + 8, \
src2 + 8 * sizeof(pixel), \ src2 + 8, \
dst_stride, src_stride1, \ dst_stride, src_stride1, \
src_stride2, h); \ src_stride2, h); \
} \ } \
\ \
static inline void FUNC(OPNAME ## _pixels8_l4)(uint8_t *dst, \ static inline void OPNAME ## _pixels8_l4_8(uint8_t *dst, \
const uint8_t *src1, \ const uint8_t *src1, \
const uint8_t *src2, \ const uint8_t *src2, \
const uint8_t *src3, \ const uint8_t *src3, \
@ -163,7 +158,7 @@ static inline void FUNC(OPNAME ## _pixels8_l4)(uint8_t *dst, \
} \ } \
} \ } \
\ \
static inline void FUNC(OPNAME ## _no_rnd_pixels8_l4)(uint8_t *dst, \ static inline void OPNAME ## _no_rnd_pixels8_l4_8(uint8_t *dst, \
const uint8_t *src1, \ const uint8_t *src1, \
const uint8_t *src2, \ const uint8_t *src2, \
const uint8_t *src3, \ const uint8_t *src3, \
@ -212,7 +207,8 @@ static inline void FUNC(OPNAME ## _no_rnd_pixels8_l4)(uint8_t *dst, \
h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \ h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
} \ } \
} \ } \
static inline void FUNC(OPNAME ## _pixels16_l4)(uint8_t *dst, \ \
static inline void OPNAME ## _pixels16_l4_8(uint8_t *dst, \
const uint8_t *src1, \ const uint8_t *src1, \
const uint8_t *src2, \ const uint8_t *src2, \
const uint8_t *src3, \ const uint8_t *src3, \
@ -224,18 +220,17 @@ static inline void FUNC(OPNAME ## _pixels16_l4)(uint8_t *dst, \
int src_stride4, \ int src_stride4, \
int h) \ int h) \
{ \ { \
FUNC(OPNAME ## _pixels8_l4)(dst, src1, src2, src3, src4, dst_stride, \ OPNAME ## _pixels8_l4_8(dst, src1, src2, src3, src4, dst_stride, \
src_stride1, src_stride2, src_stride3, \ src_stride1, src_stride2, src_stride3, \
src_stride4, h); \ src_stride4, h); \
FUNC(OPNAME ## _pixels8_l4)(dst + 8 * sizeof(pixel), \ OPNAME ## _pixels8_l4_8(dst + 8, \
src1 + 8 * sizeof(pixel), \ src1 + 8, src2 + 8, \
src2 + 8 * sizeof(pixel), \ src3 + 8, src4 + 8, \
src3 + 8 * sizeof(pixel), \
src4 + 8 * sizeof(pixel), \
dst_stride, src_stride1, src_stride2, \ dst_stride, src_stride1, src_stride2, \
src_stride3, src_stride4, h); \ src_stride3, src_stride4, h); \
} \ } \
static inline void FUNC(OPNAME ## _no_rnd_pixels16_l4)(uint8_t *dst, \ \
static inline void OPNAME ## _no_rnd_pixels16_l4_8(uint8_t *dst, \
const uint8_t *src1, \ const uint8_t *src1, \
const uint8_t *src2, \ const uint8_t *src2, \
const uint8_t *src3, \ const uint8_t *src3, \
@ -247,19 +242,19 @@ static inline void FUNC(OPNAME ## _no_rnd_pixels16_l4)(uint8_t *dst, \
int src_stride4, \ int src_stride4, \
int h) \ int h) \
{ \ { \
FUNC(OPNAME ## _no_rnd_pixels8_l4)(dst, src1, src2, src3, src4, \ OPNAME ## _no_rnd_pixels8_l4_8(dst, src1, src2, src3, src4, \
dst_stride, src_stride1, src_stride2, \ dst_stride, src_stride1, \
src_stride3, src_stride4, h); \ src_stride2, src_stride3, \
FUNC(OPNAME ## _no_rnd_pixels8_l4)(dst + 8 * sizeof(pixel), \ src_stride4, h); \
src1 + 8 * sizeof(pixel), \ OPNAME ## _no_rnd_pixels8_l4_8(dst + 8, \
src2 + 8 * sizeof(pixel), \ src1 + 8, src2 + 8, \
src3 + 8 * sizeof(pixel), \ src3 + 8, src4 + 8, \
src4 + 8 * sizeof(pixel), \ dst_stride, src_stride1, \
dst_stride, src_stride1, src_stride2, \ src_stride2, src_stride3, \
src_stride3, src_stride4, h); \ src_stride4, h); \
} \ } \
\ \
static inline void FUNCC(OPNAME ## _pixels8_xy2)(uint8_t *block, \ static inline void OPNAME ## _pixels8_xy2_8_c(uint8_t *block, \
const uint8_t *pixels, \ const uint8_t *pixels, \
ptrdiff_t line_size, \ ptrdiff_t line_size, \
int h) \ int h) \
@ -307,11 +302,11 @@ static inline void FUNCC(OPNAME ## _pixels8_xy2)(uint8_t *block, \
} \ } \
} \ } \
\ \
CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_xy2), \ CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_8_c, \
FUNCC(OPNAME ## _pixels8_xy2), \ OPNAME ## _pixels8_xy2_8_c, \
8 * sizeof(pixel)) \ 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 op_put(a, b) a = b
#define put_no_rnd_pixels8_8_c put_pixels8_8_c #define put_no_rnd_pixels8_8_c put_pixels8_8_c
PIXOP2(avg, op_avg) PIXOP2(avg, op_avg)

Loading…
Cancel
Save