comparison dsputil.c @ 11499:2a4dc3c0b012 libavcodec

Move H264 dsputil functions into their own struct This moves the H264-specific functions from DSPContext to the new H264DSPContext. The code is made conditional on CONFIG_H264DSP which is set by the codecs requiring it. The qpel and chroma MC functions are not moved as these are used by non-h264 code.
author mru
date Tue, 16 Mar 2010 01:17:00 +0000
parents 0f0cd6b5791f
children f7281af560fe
comparison
equal deleted inserted replaced
11498:8e889ce0d616 11499:2a4dc3c0b012
2595 #undef op_put 2595 #undef op_put
2596 #undef op2_avg 2596 #undef op2_avg
2597 #undef op2_put 2597 #undef op2_put
2598 #endif 2598 #endif
2599 2599
2600 #define op_scale1(x) block[x] = av_clip_uint8( (block[x]*weight + offset) >> log2_denom )
2601 #define op_scale2(x) dst[x] = av_clip_uint8( (src[x]*weights + dst[x]*weightd + offset) >> (log2_denom+1))
2602 #define H264_WEIGHT(W,H) \
2603 static void weight_h264_pixels ## W ## x ## H ## _c(uint8_t *block, int stride, int log2_denom, int weight, int offset){ \
2604 int y; \
2605 offset <<= log2_denom; \
2606 if(log2_denom) offset += 1<<(log2_denom-1); \
2607 for(y=0; y<H; y++, block += stride){ \
2608 op_scale1(0); \
2609 op_scale1(1); \
2610 if(W==2) continue; \
2611 op_scale1(2); \
2612 op_scale1(3); \
2613 if(W==4) continue; \
2614 op_scale1(4); \
2615 op_scale1(5); \
2616 op_scale1(6); \
2617 op_scale1(7); \
2618 if(W==8) continue; \
2619 op_scale1(8); \
2620 op_scale1(9); \
2621 op_scale1(10); \
2622 op_scale1(11); \
2623 op_scale1(12); \
2624 op_scale1(13); \
2625 op_scale1(14); \
2626 op_scale1(15); \
2627 } \
2628 } \
2629 static void biweight_h264_pixels ## W ## x ## H ## _c(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset){ \
2630 int y; \
2631 offset = ((offset + 1) | 1) << log2_denom; \
2632 for(y=0; y<H; y++, dst += stride, src += stride){ \
2633 op_scale2(0); \
2634 op_scale2(1); \
2635 if(W==2) continue; \
2636 op_scale2(2); \
2637 op_scale2(3); \
2638 if(W==4) continue; \
2639 op_scale2(4); \
2640 op_scale2(5); \
2641 op_scale2(6); \
2642 op_scale2(7); \
2643 if(W==8) continue; \
2644 op_scale2(8); \
2645 op_scale2(9); \
2646 op_scale2(10); \
2647 op_scale2(11); \
2648 op_scale2(12); \
2649 op_scale2(13); \
2650 op_scale2(14); \
2651 op_scale2(15); \
2652 } \
2653 }
2654
2655 H264_WEIGHT(16,16)
2656 H264_WEIGHT(16,8)
2657 H264_WEIGHT(8,16)
2658 H264_WEIGHT(8,8)
2659 H264_WEIGHT(8,4)
2660 H264_WEIGHT(4,8)
2661 H264_WEIGHT(4,4)
2662 H264_WEIGHT(4,2)
2663 H264_WEIGHT(2,4)
2664 H264_WEIGHT(2,2)
2665
2666 #undef op_scale1
2667 #undef op_scale2
2668 #undef H264_WEIGHT
2669
2670 static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){ 2600 static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
2671 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; 2601 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
2672 int i; 2602 int i;
2673 2603
2674 for(i=0; i<h; i++){ 2604 for(i=0; i<h; i++){
2708 } 2638 }
2709 void ff_avg_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { 2639 void ff_avg_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
2710 avg_pixels8_c(dst, src, stride, 8); 2640 avg_pixels8_c(dst, src, stride, 8);
2711 } 2641 }
2712 #endif /* CONFIG_VC1_DECODER */ 2642 #endif /* CONFIG_VC1_DECODER */
2713
2714 /* H264 specific */
2715 void ff_h264dspenc_init(DSPContext* c, AVCodecContext *avctx);
2716 2643
2717 #if CONFIG_RV40_DECODER 2644 #if CONFIG_RV40_DECODER
2718 static void put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){ 2645 static void put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
2719 put_pixels16_xy2_c(dst, src, stride, 16); 2646 put_pixels16_xy2_c(dst, src, stride, 16);
2720 } 2647 }
2903 xy = y * stride + x; 2830 xy = y * stride + x;
2904 yz = y * 8 + x; 2831 yz = y * 8 + x;
2905 src[xy] = (temp[yz-1] + 2*temp[yz] + temp[yz+1] + 8)>>4; 2832 src[xy] = (temp[yz-1] + 2*temp[yz] + temp[yz+1] + 8)>>4;
2906 } 2833 }
2907 } 2834 }
2908 }
2909
2910 static av_always_inline av_flatten void h264_loop_filter_luma_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta, int8_t *tc0)
2911 {
2912 int i, d;
2913 for( i = 0; i < 4; i++ ) {
2914 if( tc0[i] < 0 ) {
2915 pix += 4*ystride;
2916 continue;
2917 }
2918 for( d = 0; d < 4; d++ ) {
2919 const int p0 = pix[-1*xstride];
2920 const int p1 = pix[-2*xstride];
2921 const int p2 = pix[-3*xstride];
2922 const int q0 = pix[0];
2923 const int q1 = pix[1*xstride];
2924 const int q2 = pix[2*xstride];
2925
2926 if( FFABS( p0 - q0 ) < alpha &&
2927 FFABS( p1 - p0 ) < beta &&
2928 FFABS( q1 - q0 ) < beta ) {
2929
2930 int tc = tc0[i];
2931 int i_delta;
2932
2933 if( FFABS( p2 - p0 ) < beta ) {
2934 if(tc0[i])
2935 pix[-2*xstride] = p1 + av_clip( (( p2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - p1, -tc0[i], tc0[i] );
2936 tc++;
2937 }
2938 if( FFABS( q2 - q0 ) < beta ) {
2939 if(tc0[i])
2940 pix[ xstride] = q1 + av_clip( (( q2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - q1, -tc0[i], tc0[i] );
2941 tc++;
2942 }
2943
2944 i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
2945 pix[-xstride] = av_clip_uint8( p0 + i_delta ); /* p0' */
2946 pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */
2947 }
2948 pix += ystride;
2949 }
2950 }
2951 }
2952 static void h264_v_loop_filter_luma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
2953 {
2954 h264_loop_filter_luma_c(pix, stride, 1, alpha, beta, tc0);
2955 }
2956 static void h264_h_loop_filter_luma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
2957 {
2958 h264_loop_filter_luma_c(pix, 1, stride, alpha, beta, tc0);
2959 }
2960
2961 static av_always_inline av_flatten void h264_loop_filter_luma_intra_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta)
2962 {
2963 int d;
2964 for( d = 0; d < 16; d++ ) {
2965 const int p2 = pix[-3*xstride];
2966 const int p1 = pix[-2*xstride];
2967 const int p0 = pix[-1*xstride];
2968
2969 const int q0 = pix[ 0*xstride];
2970 const int q1 = pix[ 1*xstride];
2971 const int q2 = pix[ 2*xstride];
2972
2973 if( FFABS( p0 - q0 ) < alpha &&
2974 FFABS( p1 - p0 ) < beta &&
2975 FFABS( q1 - q0 ) < beta ) {
2976
2977 if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){
2978 if( FFABS( p2 - p0 ) < beta)
2979 {
2980 const int p3 = pix[-4*xstride];
2981 /* p0', p1', p2' */
2982 pix[-1*xstride] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3;
2983 pix[-2*xstride] = ( p2 + p1 + p0 + q0 + 2 ) >> 2;
2984 pix[-3*xstride] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3;
2985 } else {
2986 /* p0' */
2987 pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
2988 }
2989 if( FFABS( q2 - q0 ) < beta)
2990 {
2991 const int q3 = pix[3*xstride];
2992 /* q0', q1', q2' */
2993 pix[0*xstride] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3;
2994 pix[1*xstride] = ( p0 + q0 + q1 + q2 + 2 ) >> 2;
2995 pix[2*xstride] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3;
2996 } else {
2997 /* q0' */
2998 pix[0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
2999 }
3000 }else{
3001 /* p0', q0' */
3002 pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
3003 pix[ 0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
3004 }
3005 }
3006 pix += ystride;
3007 }
3008 }
3009 static void h264_v_loop_filter_luma_intra_c(uint8_t *pix, int stride, int alpha, int beta)
3010 {
3011 h264_loop_filter_luma_intra_c(pix, stride, 1, alpha, beta);
3012 }
3013 static void h264_h_loop_filter_luma_intra_c(uint8_t *pix, int stride, int alpha, int beta)
3014 {
3015 h264_loop_filter_luma_intra_c(pix, 1, stride, alpha, beta);
3016 }
3017
3018 static av_always_inline av_flatten void h264_loop_filter_chroma_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta, int8_t *tc0)
3019 {
3020 int i, d;
3021 for( i = 0; i < 4; i++ ) {
3022 const int tc = tc0[i];
3023 if( tc <= 0 ) {
3024 pix += 2*ystride;
3025 continue;
3026 }
3027 for( d = 0; d < 2; d++ ) {
3028 const int p0 = pix[-1*xstride];
3029 const int p1 = pix[-2*xstride];
3030 const int q0 = pix[0];
3031 const int q1 = pix[1*xstride];
3032
3033 if( FFABS( p0 - q0 ) < alpha &&
3034 FFABS( p1 - p0 ) < beta &&
3035 FFABS( q1 - q0 ) < beta ) {
3036
3037 int delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
3038
3039 pix[-xstride] = av_clip_uint8( p0 + delta ); /* p0' */
3040 pix[0] = av_clip_uint8( q0 - delta ); /* q0' */
3041 }
3042 pix += ystride;
3043 }
3044 }
3045 }
3046 static void h264_v_loop_filter_chroma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
3047 {
3048 h264_loop_filter_chroma_c(pix, stride, 1, alpha, beta, tc0);
3049 }
3050 static void h264_h_loop_filter_chroma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
3051 {
3052 h264_loop_filter_chroma_c(pix, 1, stride, alpha, beta, tc0);
3053 }
3054
3055 static av_always_inline av_flatten void h264_loop_filter_chroma_intra_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta)
3056 {
3057 int d;
3058 for( d = 0; d < 8; d++ ) {
3059 const int p0 = pix[-1*xstride];
3060 const int p1 = pix[-2*xstride];
3061 const int q0 = pix[0];
3062 const int q1 = pix[1*xstride];
3063
3064 if( FFABS( p0 - q0 ) < alpha &&
3065 FFABS( p1 - p0 ) < beta &&
3066 FFABS( q1 - q0 ) < beta ) {
3067
3068 pix[-xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */
3069 pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */
3070 }
3071 pix += ystride;
3072 }
3073 }
3074 static void h264_v_loop_filter_chroma_intra_c(uint8_t *pix, int stride, int alpha, int beta)
3075 {
3076 h264_loop_filter_chroma_intra_c(pix, stride, 1, alpha, beta);
3077 }
3078 static void h264_h_loop_filter_chroma_intra_c(uint8_t *pix, int stride, int alpha, int beta)
3079 {
3080 h264_loop_filter_chroma_intra_c(pix, 1, stride, alpha, beta);
3081 } 2835 }
3082 2836
3083 static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) 2837 static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
3084 { 2838 {
3085 int s, i; 2839 int s, i;
4500 c->idct = ff_simple_idct; 4254 c->idct = ff_simple_idct;
4501 c->idct_permutation_type= FF_NO_IDCT_PERM; 4255 c->idct_permutation_type= FF_NO_IDCT_PERM;
4502 } 4256 }
4503 } 4257 }
4504 4258
4505 if (CONFIG_H264_DECODER) {
4506 c->h264_idct_add= ff_h264_idct_add_c;
4507 c->h264_idct8_add= ff_h264_idct8_add_c;
4508 c->h264_idct_dc_add= ff_h264_idct_dc_add_c;
4509 c->h264_idct8_dc_add= ff_h264_idct8_dc_add_c;
4510 c->h264_idct_add16 = ff_h264_idct_add16_c;
4511 c->h264_idct8_add4 = ff_h264_idct8_add4_c;
4512 c->h264_idct_add8 = ff_h264_idct_add8_c;
4513 c->h264_idct_add16intra= ff_h264_idct_add16intra_c;
4514 }
4515
4516 c->get_pixels = get_pixels_c; 4259 c->get_pixels = get_pixels_c;
4517 c->diff_pixels = diff_pixels_c; 4260 c->diff_pixels = diff_pixels_c;
4518 c->put_pixels_clamped = put_pixels_clamped_c; 4261 c->put_pixels_clamped = put_pixels_clamped_c;
4519 c->put_signed_pixels_clamped = put_signed_pixels_clamped_c; 4262 c->put_signed_pixels_clamped = put_signed_pixels_clamped_c;
4520 c->put_pixels_nonclamped = put_pixels_nonclamped_c; 4263 c->put_pixels_nonclamped = put_pixels_nonclamped_c;
4632 c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c; 4375 c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;
4633 c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c; 4376 c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;
4634 c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c; 4377 c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;
4635 c->put_no_rnd_vc1_chroma_pixels_tab[0]= put_no_rnd_vc1_chroma_mc8_c; 4378 c->put_no_rnd_vc1_chroma_pixels_tab[0]= put_no_rnd_vc1_chroma_mc8_c;
4636 c->avg_no_rnd_vc1_chroma_pixels_tab[0]= avg_no_rnd_vc1_chroma_mc8_c; 4379 c->avg_no_rnd_vc1_chroma_pixels_tab[0]= avg_no_rnd_vc1_chroma_mc8_c;
4637
4638 c->weight_h264_pixels_tab[0]= weight_h264_pixels16x16_c;
4639 c->weight_h264_pixels_tab[1]= weight_h264_pixels16x8_c;
4640 c->weight_h264_pixels_tab[2]= weight_h264_pixels8x16_c;
4641 c->weight_h264_pixels_tab[3]= weight_h264_pixels8x8_c;
4642 c->weight_h264_pixels_tab[4]= weight_h264_pixels8x4_c;
4643 c->weight_h264_pixels_tab[5]= weight_h264_pixels4x8_c;
4644 c->weight_h264_pixels_tab[6]= weight_h264_pixels4x4_c;
4645 c->weight_h264_pixels_tab[7]= weight_h264_pixels4x2_c;
4646 c->weight_h264_pixels_tab[8]= weight_h264_pixels2x4_c;
4647 c->weight_h264_pixels_tab[9]= weight_h264_pixels2x2_c;
4648 c->biweight_h264_pixels_tab[0]= biweight_h264_pixels16x16_c;
4649 c->biweight_h264_pixels_tab[1]= biweight_h264_pixels16x8_c;
4650 c->biweight_h264_pixels_tab[2]= biweight_h264_pixels8x16_c;
4651 c->biweight_h264_pixels_tab[3]= biweight_h264_pixels8x8_c;
4652 c->biweight_h264_pixels_tab[4]= biweight_h264_pixels8x4_c;
4653 c->biweight_h264_pixels_tab[5]= biweight_h264_pixels4x8_c;
4654 c->biweight_h264_pixels_tab[6]= biweight_h264_pixels4x4_c;
4655 c->biweight_h264_pixels_tab[7]= biweight_h264_pixels4x2_c;
4656 c->biweight_h264_pixels_tab[8]= biweight_h264_pixels2x4_c;
4657 c->biweight_h264_pixels_tab[9]= biweight_h264_pixels2x2_c;
4658 4380
4659 c->draw_edges = draw_edges_c; 4381 c->draw_edges = draw_edges_c;
4660 4382
4661 #if CONFIG_CAVS_DECODER 4383 #if CONFIG_CAVS_DECODER
4662 ff_cavsdsp_init(c,avctx); 4384 ff_cavsdsp_init(c,avctx);
4735 c->bswap_buf= bswap_buf; 4457 c->bswap_buf= bswap_buf;
4736 #if CONFIG_PNG_DECODER 4458 #if CONFIG_PNG_DECODER
4737 c->add_png_paeth_prediction= ff_add_png_paeth_prediction; 4459 c->add_png_paeth_prediction= ff_add_png_paeth_prediction;
4738 #endif 4460 #endif
4739 4461
4740 c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_c;
4741 c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_c;
4742 c->h264_v_loop_filter_luma_intra= h264_v_loop_filter_luma_intra_c;
4743 c->h264_h_loop_filter_luma_intra= h264_h_loop_filter_luma_intra_c;
4744 c->h264_v_loop_filter_chroma= h264_v_loop_filter_chroma_c;
4745 c->h264_h_loop_filter_chroma= h264_h_loop_filter_chroma_c;
4746 c->h264_v_loop_filter_chroma_intra= h264_v_loop_filter_chroma_intra_c;
4747 c->h264_h_loop_filter_chroma_intra= h264_h_loop_filter_chroma_intra_c;
4748 c->h264_loop_filter_strength= NULL;
4749
4750 if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) { 4462 if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
4751 c->h263_h_loop_filter= h263_h_loop_filter_c; 4463 c->h263_h_loop_filter= h263_h_loop_filter_c;
4752 c->h263_v_loop_filter= h263_v_loop_filter_c; 4464 c->h263_v_loop_filter= h263_v_loop_filter_c;
4753 } 4465 }
4754 4466