From 87ce8b495f0e73625bc583e01c07bcd3e67b95ab Mon Sep 17 00:00:00 2001 From: Oskar Arvidsson Date: Tue, 29 Mar 2011 17:48:55 +0200 Subject: [PATCH] Template dsputil_template.c with respect to pixel size, etc. Preparatory patch for high bit depth h264 decoding support. Signed-off-by: Ronald S. Bultje --- libavcodec/dsputil_template.c | 704 +++++++++++++++++++--------------- 1 file changed, 398 insertions(+), 306 deletions(-) diff --git a/libavcodec/dsputil_template.c b/libavcodec/dsputil_template.c index 866817ce2e..f69c4671f9 100644 --- a/libavcodec/dsputil_template.c +++ b/libavcodec/dsputil_template.c @@ -29,18 +29,46 @@ #include "dsputil.h" +#define BIT_DEPTH 8 + +#define pixel uint8_t +#define pixel2 uint16_t +#define pixel4 uint32_t +#define dctcoef int16_t + +#define FUNC(a) a +#define FUNCC(a) a ## _c +#define INIT_CLIP uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; +#define CLIP(a) cm[a] +#define AV_RN2P AV_RN16 +#define AV_RN4P AV_RN32 +#define PIXEL_MAX ((1< 8 + int j; + for (j = 0; j < w; j++) { + ptr[j-w] = ptr[0]; + ptr[j+width] = ptr[width-1]; + } +#else memset(ptr - w, ptr[0], w); memset(ptr + width, ptr[width-1], w); +#endif ptr += wrap; } @@ -49,10 +77,10 @@ static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w, i last_line = buf + (height - 1) * wrap; if (sides & EDGE_TOP) for(i = 0; i < w; i++) - memcpy(buf - (i + 1) * wrap, buf, width + w + w); // top + memcpy(buf - (i + 1) * wrap, buf, (width + w + w) * sizeof(pixel)); // top if (sides & EDGE_BOTTOM) for (i = 0; i < w; i++) - memcpy(last_line + (i + 1) * wrap, last_line, width + w + w); // bottom + memcpy(last_line + (i + 1) * wrap, last_line, (width + w + w) * sizeof(pixel)); // bottom } /** @@ -67,7 +95,7 @@ static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w, i * @param w width of the source buffer * @param h height of the source buffer */ -void ff_emulated_edge_mc(uint8_t *buf, const uint8_t *src, int linesize, int block_w, int block_h, +void FUNC(ff_emulated_edge_mc)(uint8_t *buf, const uint8_t *src, int linesize, int block_w, int block_h, int src_x, int src_y, int w, int h){ int x, y; int start_y, start_x, end_y, end_x; @@ -80,10 +108,10 @@ void ff_emulated_edge_mc(uint8_t *buf, const uint8_t *src, int linesize, int blo src_y=1-block_h; } if(src_x>= w){ - src+= (w-1-src_x); + src+= (w-1-src_x)*sizeof(pixel); src_x=w-1; }else if(src_x<=-block_w){ - src+= (1-block_w-src_x); + src+= (1-block_w-src_x)*sizeof(pixel); src_x=1-block_w; } @@ -95,18 +123,18 @@ void ff_emulated_edge_mc(uint8_t *buf, const uint8_t *src, int linesize, int blo assert(start_x < end_x && block_w); w = end_x - start_x; - src += start_y*linesize + start_x; - buf += start_x; + src += start_y*linesize + start_x*sizeof(pixel); + buf += start_x*sizeof(pixel); //top for(y=0; y>1) ) #else // 64 bit variant #define PIXOP2(OPNAME, OP) \ -static void OPNAME ## _pixels2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ +static void FUNCC(OPNAME ## _pixels2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ int i;\ for(i=0; i>2)&0x0F0F0F0FUL));\ }\ }\ -static inline void OPNAME ## _pixels16_l4(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\ +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){\ - OPNAME ## _pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\ - OPNAME ## _pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, 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);\ }\ -static inline void OPNAME ## _no_rnd_pixels16_l4(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\ +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){\ - OPNAME ## _no_rnd_pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\ - OPNAME ## _no_rnd_pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, 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);\ }\ \ -static inline void OPNAME ## _pixels2_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ +static inline void FUNCC(OPNAME ## _pixels2_xy2)(uint8_t *_block, const uint8_t *_pixels, int line_size, int h)\ {\ int i, a0, b0, a1, b1;\ + pixel *block = (pixel*)_block;\ + const pixel *pixels = (const pixel*)_pixels;\ + line_size /= sizeof(pixel);\ a0= pixels[0];\ b0= pixels[1] + 2;\ a0 += b0;\ @@ -546,8 +588,9 @@ static inline void OPNAME ## _pixels2_xy2_c(uint8_t *block, const uint8_t *pixel }\ }\ \ -static inline void OPNAME ## _pixels4_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ +static inline void FUNCC(OPNAME ## _pixels4_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ {\ + /* FIXME HIGH BIT DEPTH */\ int i;\ const uint32_t a= AV_RN32(pixels );\ const uint32_t b= AV_RN32(pixels+1);\ @@ -582,8 +625,9 @@ static inline void OPNAME ## _pixels4_xy2_c(uint8_t *block, const uint8_t *pixel }\ }\ \ -static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ +static inline void FUNCC(OPNAME ## _pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ {\ + /* FIXME HIGH BIT DEPTH */\ int j;\ for(j=0; j<2; j++){\ int i;\ @@ -623,8 +667,9 @@ static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixel }\ }\ \ -static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ +static inline void FUNCC(OPNAME ## _no_rnd_pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ {\ + /* FIXME HIGH BIT DEPTH */\ int j;\ for(j=0; j<2; j++){\ int i;\ @@ -664,18 +709,17 @@ static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t }\ }\ \ -CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels8_c , 8)\ -CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels8_x2_c , 8)\ -CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels8_y2_c , 8)\ -CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels8_xy2_c, 8)\ -av_unused CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_c , OPNAME ## _pixels8_c , 8)\ -CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels8_x2_c , 8)\ -CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels8_y2_c , 8)\ -CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels8_xy2_c, 8)\ +CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16) , FUNCC(OPNAME ## _pixels8) , 8*sizeof(pixel))\ +CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_x2) , FUNCC(OPNAME ## _pixels8_x2) , 8*sizeof(pixel))\ +CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_y2) , FUNCC(OPNAME ## _pixels8_y2) , 8*sizeof(pixel))\ +CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_xy2), FUNCC(OPNAME ## _pixels8_xy2), 8*sizeof(pixel))\ +av_unused CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16) , FUNCC(OPNAME ## _pixels8) , 8*sizeof(pixel))\ +CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16_x2) , FUNCC(OPNAME ## _no_rnd_pixels8_x2) , 8*sizeof(pixel))\ +CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16_y2) , FUNCC(OPNAME ## _no_rnd_pixels8_y2) , 8*sizeof(pixel))\ +CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16_xy2), FUNCC(OPNAME ## _no_rnd_pixels8_xy2), 8*sizeof(pixel))\ -#define op_avg(a, b) a = rnd_avg32(a, b) +#define op_avg(a, b) a = rnd_avg_pixel4(a, b) #endif - #define op_put(a, b) a = b PIXOP2(avg, op_avg) @@ -686,21 +730,24 @@ PIXOP2(put, op_put) #define put_no_rnd_pixels8_c put_pixels8_c #define put_no_rnd_pixels16_c put_pixels16_c -static void put_no_rnd_pixels16_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){ - put_no_rnd_pixels16_l2(dst, a, b, stride, stride, stride, h); +static void FUNCC(put_no_rnd_pixels16_l2)(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){ + FUNC(put_no_rnd_pixels16_l2)(dst, a, b, stride, stride, stride, h); } -static void put_no_rnd_pixels8_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){ - put_no_rnd_pixels8_l2(dst, a, b, stride, stride, stride, h); +static void FUNCC(put_no_rnd_pixels8_l2)(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){ + FUNC(put_no_rnd_pixels8_l2)(dst, a, b, stride, stride, stride, h); } #define H264_CHROMA_MC(OPNAME, OP)\ -static void OPNAME ## h264_chroma_mc2_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\ +static void FUNCC(OPNAME ## h264_chroma_mc2)(uint8_t *_dst/*align 8*/, uint8_t *_src/*align 1*/, int stride, int h, int x, int y){\ + pixel *dst = (pixel*)_dst;\ + pixel *src = (pixel*)_src;\ const int A=(8-x)*(8-y);\ const int B=( x)*(8-y);\ const int C=(8-x)*( y);\ const int D=( x)*( y);\ int i;\ + stride /= sizeof(pixel);\ \ assert(x<8 && y<8 && x>=0 && y>=0);\ \ @@ -723,12 +770,15 @@ static void OPNAME ## h264_chroma_mc2_c(uint8_t *dst/*align 8*/, uint8_t *src/*a }\ }\ \ -static void OPNAME ## h264_chroma_mc4_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\ +static void FUNCC(OPNAME ## h264_chroma_mc4)(uint8_t *_dst/*align 8*/, uint8_t *_src/*align 1*/, int stride, int h, int x, int y){\ + pixel *dst = (pixel*)_dst;\ + pixel *src = (pixel*)_src;\ const int A=(8-x)*(8-y);\ const int B=( x)*(8-y);\ const int C=(8-x)*( y);\ const int D=( x)*( y);\ int i;\ + stride /= sizeof(pixel);\ \ assert(x<8 && y<8 && x>=0 && y>=0);\ \ @@ -755,12 +805,15 @@ static void OPNAME ## h264_chroma_mc4_c(uint8_t *dst/*align 8*/, uint8_t *src/*a }\ }\ \ -static void OPNAME ## h264_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\ +static void FUNCC(OPNAME ## h264_chroma_mc8)(uint8_t *_dst/*align 8*/, uint8_t *_src/*align 1*/, int stride, int h, int x, int y){\ + pixel *dst = (pixel*)_dst;\ + pixel *src = (pixel*)_src;\ const int A=(8-x)*(8-y);\ const int B=( x)*(8-y);\ const int C=(8-x)*( y);\ const int D=( x)*( y);\ int i;\ + stride /= sizeof(pixel);\ \ assert(x<8 && y<8 && x>=0 && y>=0);\ \ @@ -804,10 +857,14 @@ H264_CHROMA_MC(avg_ , op_avg) #undef op_put #define H264_LOWPASS(OPNAME, OP, OP2) \ -static av_unused void OPNAME ## h264_qpel2_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ +static av_unused void FUNC(OPNAME ## h264_qpel2_h_lowpass)(uint8_t *_dst, uint8_t *_src, int dstStride, int srcStride){\ const int h=2;\ - uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ + INIT_CLIP\ int i;\ + pixel *dst = (pixel*)_dst;\ + pixel *src = (pixel*)_src;\ + dstStride /= sizeof(pixel);\ + srcStride /= sizeof(pixel);\ for(i=0; i 9) ? (-10 * ((1< 9) ? (-10 * ((1< 9) ? (-10 * ((1<>5]+1)>>1) +#define op_avg(a, b) a = (((a)+CLIP(((b) + 16)>>5)+1)>>1) //#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7) -#define op_put(a, b) a = cm[((b) + 16)>>5] -#define op2_avg(a, b) a = (((a)+cm[((b) + 512)>>10]+1)>>1) -#define op2_put(a, b) a = cm[((b) + 512)>>10] +#define op_put(a, b) a = CLIP(((b) + 16)>>5) +#define op2_avg(a, b) a = (((a)+CLIP(((b) + 512)>>10)+1)>>1) +#define op2_put(a, b) a = CLIP(((b) + 512)>>10) H264_LOWPASS(put_ , op_put, op2_put) H264_LOWPASS(avg_ , op_avg, op2_avg) @@ -1230,28 +1322,28 @@ H264_MC(avg_, 16) #define put_h264_qpel16_mc00_c ff_put_pixels16x16_c #define avg_h264_qpel16_mc00_c ff_avg_pixels16x16_c -void ff_put_pixels8x8_c(uint8_t *dst, uint8_t *src, int stride) { - put_pixels8_c(dst, src, stride, 8); +void FUNCC(ff_put_pixels8x8)(uint8_t *dst, uint8_t *src, int stride) { + FUNCC(put_pixels8)(dst, src, stride, 8); } -void ff_avg_pixels8x8_c(uint8_t *dst, uint8_t *src, int stride) { - avg_pixels8_c(dst, src, stride, 8); +void FUNCC(ff_avg_pixels8x8)(uint8_t *dst, uint8_t *src, int stride) { + FUNCC(avg_pixels8)(dst, src, stride, 8); } -void ff_put_pixels16x16_c(uint8_t *dst, uint8_t *src, int stride) { - put_pixels16_c(dst, src, stride, 16); +void FUNCC(ff_put_pixels16x16)(uint8_t *dst, uint8_t *src, int stride) { + FUNCC(put_pixels16)(dst, src, stride, 16); } -void ff_avg_pixels16x16_c(uint8_t *dst, uint8_t *src, int stride) { - avg_pixels16_c(dst, src, stride, 16); +void FUNCC(ff_avg_pixels16x16)(uint8_t *dst, uint8_t *src, int stride) { + FUNCC(avg_pixels16)(dst, src, stride, 16); } -static void clear_block_c(DCTELEM *block) +static void FUNCC(clear_block)(DCTELEM *block) { - memset(block, 0, sizeof(DCTELEM)*64); + memset(block, 0, sizeof(dctcoef)*64); } /** * memset(blocks, 0, sizeof(DCTELEM)*6*64) */ -static void clear_blocks_c(DCTELEM *blocks) +static void FUNCC(clear_blocks)(DCTELEM *blocks) { - memset(blocks, 0, sizeof(DCTELEM)*6*64); + memset(blocks, 0, sizeof(dctcoef)*6*64); }