LCOV - code coverage report
Current view: top level - libavcodec - h264dsp_template.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 159 162 98.1 %
Date: 2017-12-15 18:13:28 Functions: 63 140 45.0 %

          Line data    Source code
       1             : /*
       2             :  * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
       3             :  * Copyright (c) 2003-2011 Michael Niedermayer <michaelni@gmx.at>
       4             :  *
       5             :  * This file is part of FFmpeg.
       6             :  *
       7             :  * FFmpeg is free software; you can redistribute it and/or
       8             :  * modify it under the terms of the GNU Lesser General Public
       9             :  * License as published by the Free Software Foundation; either
      10             :  * version 2.1 of the License, or (at your option) any later version.
      11             :  *
      12             :  * FFmpeg is distributed in the hope that it will be useful,
      13             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :  * Lesser General Public License for more details.
      16             :  *
      17             :  * You should have received a copy of the GNU Lesser General Public
      18             :  * License along with FFmpeg; if not, write to the Free Software
      19             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      20             :  */
      21             : 
      22             : /**
      23             :  * @file
      24             :  * H.264 / AVC / MPEG-4 part10 DSP functions.
      25             :  * @author Michael Niedermayer <michaelni@gmx.at>
      26             :  */
      27             : 
      28             : #include "bit_depth_template.c"
      29             : 
      30             : #define op_scale1(x)  block[x] = av_clip_pixel( (block[x]*weight + offset) >> log2_denom )
      31             : #define op_scale2(x)  dst[x] = av_clip_pixel( (src[x]*weights + dst[x]*weightd + offset) >> (log2_denom+1))
      32             : #define H264_WEIGHT(W) \
      33             : static void FUNCC(weight_h264_pixels ## W)(uint8_t *_block, ptrdiff_t stride, int height, \
      34             :                                            int log2_denom, int weight, int offset) \
      35             : { \
      36             :     int y; \
      37             :     pixel *block = (pixel*)_block; \
      38             :     stride >>= sizeof(pixel)-1; \
      39             :     offset = (unsigned)offset << (log2_denom + (BIT_DEPTH-8)); \
      40             :     if(log2_denom) offset += 1<<(log2_denom-1); \
      41             :     for (y = 0; y < height; y++, block += stride) { \
      42             :         op_scale1(0); \
      43             :         op_scale1(1); \
      44             :         if(W==2) continue; \
      45             :         op_scale1(2); \
      46             :         op_scale1(3); \
      47             :         if(W==4) continue; \
      48             :         op_scale1(4); \
      49             :         op_scale1(5); \
      50             :         op_scale1(6); \
      51             :         op_scale1(7); \
      52             :         if(W==8) continue; \
      53             :         op_scale1(8); \
      54             :         op_scale1(9); \
      55             :         op_scale1(10); \
      56             :         op_scale1(11); \
      57             :         op_scale1(12); \
      58             :         op_scale1(13); \
      59             :         op_scale1(14); \
      60             :         op_scale1(15); \
      61             :     } \
      62             : } \
      63             : static void FUNCC(biweight_h264_pixels ## W)(uint8_t *_dst, uint8_t *_src, ptrdiff_t stride, int height, \
      64             :                                              int log2_denom, int weightd, int weights, int offset) \
      65             : { \
      66             :     int y; \
      67             :     pixel *dst = (pixel*)_dst; \
      68             :     pixel *src = (pixel*)_src; \
      69             :     stride >>= sizeof(pixel)-1; \
      70             :     offset = (unsigned)offset << (BIT_DEPTH-8); \
      71             :     offset = (unsigned)((offset + 1) | 1) << log2_denom; \
      72             :     for (y = 0; y < height; y++, dst += stride, src += stride) { \
      73             :         op_scale2(0); \
      74             :         op_scale2(1); \
      75             :         if(W==2) continue; \
      76             :         op_scale2(2); \
      77             :         op_scale2(3); \
      78             :         if(W==4) continue; \
      79             :         op_scale2(4); \
      80             :         op_scale2(5); \
      81             :         op_scale2(6); \
      82             :         op_scale2(7); \
      83             :         if(W==8) continue; \
      84             :         op_scale2(8); \
      85             :         op_scale2(9); \
      86             :         op_scale2(10); \
      87             :         op_scale2(11); \
      88             :         op_scale2(12); \
      89             :         op_scale2(13); \
      90             :         op_scale2(14); \
      91             :         op_scale2(15); \
      92             :     } \
      93             : }
      94             : 
      95      736019 : H264_WEIGHT(16)
      96      856551 : H264_WEIGHT(8)
      97      820102 : H264_WEIGHT(4)
      98      543708 : H264_WEIGHT(2)
      99             : 
     100             : #undef op_scale1
     101             : #undef op_scale2
     102             : #undef H264_WEIGHT
     103             : 
     104    35800267 : static av_always_inline av_flatten void FUNCC(h264_loop_filter_luma)(uint8_t *p_pix, int xstride, int ystride, int inner_iters, int alpha, int beta, int8_t *tc0)
     105             : {
     106    35800267 :     pixel *pix = (pixel*)p_pix;
     107             :     int i, d;
     108    35800267 :     xstride >>= sizeof(pixel)-1;
     109    35800267 :     ystride >>= sizeof(pixel)-1;
     110    35800267 :     alpha <<= BIT_DEPTH - 8;
     111    35800267 :     beta  <<= BIT_DEPTH - 8;
     112   179001335 :     for( i = 0; i < 4; i++ ) {
     113   143201068 :         const int tc_orig = tc0[i] * (1 << (BIT_DEPTH - 8));
     114   143201068 :         if( tc_orig < 0 ) {
     115    23778418 :             pix += inner_iters*ystride;
     116    23778418 :             continue;
     117             :         }
     118   594713954 :         for( d = 0; d < inner_iters; d++ ) {
     119   475291304 :             const int p0 = pix[-1*xstride];
     120   475291304 :             const int p1 = pix[-2*xstride];
     121   475291304 :             const int p2 = pix[-3*xstride];
     122   475291304 :             const int q0 = pix[0];
     123   475291304 :             const int q1 = pix[1*xstride];
     124   475291304 :             const int q2 = pix[2*xstride];
     125             : 
     126   881328549 :             if( FFABS( p0 - q0 ) < alpha &&
     127   710392303 :                 FFABS( p1 - p0 ) < beta &&
     128   304355058 :                 FFABS( q1 - q0 ) < beta ) {
     129             : 
     130   254515652 :                 int tc = tc_orig;
     131             :                 int i_delta;
     132             : 
     133   254515652 :                 if( FFABS( p2 - p0 ) < beta ) {
     134   215595611 :                     if(tc_orig)
     135   202179851 :                     pix[-2*xstride] = p1 + av_clip( (( p2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - p1, -tc_orig, tc_orig );
     136   215595611 :                     tc++;
     137             :                 }
     138   254515652 :                 if( FFABS( q2 - q0 ) < beta ) {
     139   214449736 :                     if(tc_orig)
     140   201053002 :                     pix[   xstride] = q1 + av_clip( (( q2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - q1, -tc_orig, tc_orig );
     141   214449736 :                     tc++;
     142             :                 }
     143             : 
     144   254515652 :                 i_delta = av_clip( (((q0 - p0 ) * 4) + (p1 - q1) + 4) >> 3, -tc, tc );
     145   254515652 :                 pix[-xstride] = av_clip_pixel( p0 + i_delta );    /* p0' */
     146   254515652 :                 pix[0]        = av_clip_pixel( q0 - i_delta );    /* q0' */
     147             :             }
     148   475291304 :             pix += ystride;
     149             :         }
     150             :     }
     151    35800267 : }
     152    18170594 : static void FUNCC(h264_v_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
     153             : {
     154    18170594 :     FUNCC(h264_loop_filter_luma)(pix, stride, sizeof(pixel), 4, alpha, beta, tc0);
     155    18170594 : }
     156    17329761 : static void FUNCC(h264_h_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
     157             : {
     158    17329761 :     FUNCC(h264_loop_filter_luma)(pix, sizeof(pixel), stride, 4, alpha, beta, tc0);
     159    17329761 : }
     160      299912 : static void FUNCC(h264_h_loop_filter_luma_mbaff)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
     161             : {
     162      299912 :     FUNCC(h264_loop_filter_luma)(pix, sizeof(pixel), stride, 2, alpha, beta, tc0);
     163      299912 : }
     164             : 
     165     5423059 : static av_always_inline av_flatten void FUNCC(h264_loop_filter_luma_intra)(uint8_t *p_pix, int xstride, int ystride, int inner_iters, int alpha, int beta)
     166             : {
     167     5423059 :     pixel *pix = (pixel*)p_pix;
     168             :     int d;
     169     5423059 :     xstride >>= sizeof(pixel)-1;
     170     5423059 :     ystride >>= sizeof(pixel)-1;
     171     5423059 :     alpha <<= BIT_DEPTH - 8;
     172     5423059 :     beta  <<= BIT_DEPTH - 8;
     173    89248603 :     for( d = 0; d < 4 * inner_iters; d++ ) {
     174    83825544 :         const int p2 = pix[-3*xstride];
     175    83825544 :         const int p1 = pix[-2*xstride];
     176    83825544 :         const int p0 = pix[-1*xstride];
     177             : 
     178    83825544 :         const int q0 = pix[ 0*xstride];
     179    83825544 :         const int q1 = pix[ 1*xstride];
     180    83825544 :         const int q2 = pix[ 2*xstride];
     181             : 
     182   157350067 :         if( FFABS( p0 - q0 ) < alpha &&
     183   132180652 :             FFABS( p1 - p0 ) < beta &&
     184    58656129 :             FFABS( q1 - q0 ) < beta ) {
     185             : 
     186    50347692 :             if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){
     187    41584879 :                 if( FFABS( p2 - p0 ) < beta)
     188             :                 {
     189    37344928 :                     const int p3 = pix[-4*xstride];
     190             :                     /* p0', p1', p2' */
     191    37344928 :                     pix[-1*xstride] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3;
     192    37344928 :                     pix[-2*xstride] = ( p2 + p1 + p0 + q0 + 2 ) >> 2;
     193    37344928 :                     pix[-3*xstride] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3;
     194             :                 } else {
     195             :                     /* p0' */
     196     4239951 :                     pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
     197             :                 }
     198    41584879 :                 if( FFABS( q2 - q0 ) < beta)
     199             :                 {
     200    37125173 :                     const int q3 = pix[3*xstride];
     201             :                     /* q0', q1', q2' */
     202    37125173 :                     pix[0*xstride] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3;
     203    37125173 :                     pix[1*xstride] = ( p0 + q0 + q1 + q2 + 2 ) >> 2;
     204    37125173 :                     pix[2*xstride] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3;
     205             :                 } else {
     206             :                     /* q0' */
     207     4459706 :                     pix[0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
     208             :                 }
     209             :             }else{
     210             :                 /* p0', q0' */
     211     8762813 :                 pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
     212     8762813 :                 pix[ 0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
     213             :             }
     214             :         }
     215    83825544 :         pix += ystride;
     216             :     }
     217     5423059 : }
     218     2237845 : static void FUNCC(h264_v_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta)
     219             : {
     220     2237845 :     FUNCC(h264_loop_filter_luma_intra)(pix, stride, sizeof(pixel), 4, alpha, beta);
     221     2237845 : }
     222     2817289 : static void FUNCC(h264_h_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta)
     223             : {
     224     2817289 :     FUNCC(h264_loop_filter_luma_intra)(pix, sizeof(pixel), stride, 4, alpha, beta);
     225     2817289 : }
     226      367925 : static void FUNCC(h264_h_loop_filter_luma_mbaff_intra)(uint8_t *pix, int stride, int alpha, int beta)
     227             : {
     228      367925 :     FUNCC(h264_loop_filter_luma_intra)(pix, sizeof(pixel), stride, 2, alpha, beta);
     229      367925 : }
     230             : 
     231    42322981 : static av_always_inline av_flatten void FUNCC(h264_loop_filter_chroma)(uint8_t *p_pix, int xstride, int ystride, int inner_iters, int alpha, int beta, int8_t *tc0)
     232             : {
     233    42322981 :     pixel *pix = (pixel*)p_pix;
     234             :     int i, d;
     235    42322981 :     alpha <<= BIT_DEPTH - 8;
     236    42322981 :     beta  <<= BIT_DEPTH - 8;
     237    42322981 :     xstride >>= sizeof(pixel)-1;
     238    42322981 :     ystride >>= sizeof(pixel)-1;
     239   211614905 :     for( i = 0; i < 4; i++ ) {
     240   169291924 :         const int tc = ((tc0[i] - 1U) << (BIT_DEPTH - 8)) + 1;
     241   169291924 :         if( tc <= 0 ) {
     242    22123510 :             pix += inner_iters*ystride;
     243    22123510 :             continue;
     244             :         }
     245   450173770 :         for( d = 0; d < inner_iters; d++ ) {
     246   303005356 :             const int p0 = pix[-1*xstride];
     247   303005356 :             const int p1 = pix[-2*xstride];
     248   303005356 :             const int q0 = pix[0];
     249   303005356 :             const int q1 = pix[1*xstride];
     250             : 
     251   599924941 :             if( FFABS( p0 - q0 ) < alpha &&
     252   576092012 :                 FFABS( p1 - p0 ) < beta &&
     253   279172427 :                 FFABS( q1 - q0 ) < beta ) {
     254             : 
     255   267344197 :                 int delta = av_clip( ((q0 - p0) * 4 + (p1 - q1) + 4) >> 3, -tc, tc );
     256             : 
     257   267344197 :                 pix[-xstride] = av_clip_pixel( p0 + delta );    /* p0' */
     258   267344197 :                 pix[0]        = av_clip_pixel( q0 - delta );    /* q0' */
     259             :             }
     260   303005356 :             pix += ystride;
     261             :         }
     262             :     }
     263    42322981 : }
     264    23081598 : static void FUNCC(h264_v_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
     265             : {
     266    23081598 :     FUNCC(h264_loop_filter_chroma)(pix, stride, sizeof(pixel), 2, alpha, beta, tc0);
     267    23081598 : }
     268    17255669 : static void FUNCC(h264_h_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
     269             : {
     270    17255669 :     FUNCC(h264_loop_filter_chroma)(pix, sizeof(pixel), stride, 2, alpha, beta, tc0);
     271    17255669 : }
     272      599366 : static void FUNCC(h264_h_loop_filter_chroma_mbaff)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
     273             : {
     274      599366 :     FUNCC(h264_loop_filter_chroma)(pix, sizeof(pixel), stride, 1, alpha, beta, tc0);
     275      599366 : }
     276     1386348 : static void FUNCC(h264_h_loop_filter_chroma422)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
     277             : {
     278     1386348 :     FUNCC(h264_loop_filter_chroma)(pix, sizeof(pixel), stride, 4, alpha, beta, tc0);
     279     1386348 : }
     280           0 : static void FUNCC(h264_h_loop_filter_chroma422_mbaff)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
     281             : {
     282           0 :     FUNCC(h264_loop_filter_chroma)(pix, sizeof(pixel), stride, 2, alpha, beta, tc0);
     283           0 : }
     284             : 
     285    10624963 : static av_always_inline av_flatten void FUNCC(h264_loop_filter_chroma_intra)(uint8_t *p_pix, int xstride, int ystride, int inner_iters, int alpha, int beta)
     286             : {
     287    10624963 :     pixel *pix = (pixel*)p_pix;
     288             :     int d;
     289    10624963 :     xstride >>= sizeof(pixel)-1;
     290    10624963 :     ystride >>= sizeof(pixel)-1;
     291    10624963 :     alpha <<= BIT_DEPTH - 8;
     292    10624963 :     beta  <<= BIT_DEPTH - 8;
     293   103554779 :     for( d = 0; d < 4 * inner_iters; d++ ) {
     294    92929816 :         const int p0 = pix[-1*xstride];
     295    92929816 :         const int p1 = pix[-2*xstride];
     296    92929816 :         const int q0 = pix[0];
     297    92929816 :         const int q1 = pix[1*xstride];
     298             : 
     299   183117499 :         if( FFABS( p0 - q0 ) < alpha &&
     300   175439408 :             FFABS( p1 - p0 ) < beta &&
     301    85251725 :             FFABS( q1 - q0 ) < beta ) {
     302             : 
     303    81787891 :             pix[-xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2;   /* p0' */
     304    81787891 :             pix[0]        = ( 2*q1 + q0 + p1 + 2 ) >> 2;   /* q0' */
     305             :         }
     306    92929816 :         pix += ystride;
     307             :     }
     308    10624963 : }
     309     4365614 : static void FUNCC(h264_v_loop_filter_chroma_intra)(uint8_t *pix, int stride, int alpha, int beta)
     310             : {
     311     4365614 :     FUNCC(h264_loop_filter_chroma_intra)(pix, stride, sizeof(pixel), 2, alpha, beta);
     312     4365614 : }
     313     4274303 : static void FUNCC(h264_h_loop_filter_chroma_intra)(uint8_t *pix, int stride, int alpha, int beta)
     314             : {
     315     4274303 :     FUNCC(h264_loop_filter_chroma_intra)(pix, sizeof(pixel), stride, 2, alpha, beta);
     316     4274303 : }
     317      516132 : static void FUNCC(h264_h_loop_filter_chroma_mbaff_intra)(uint8_t *pix, int stride, int alpha, int beta)
     318             : {
     319      516132 :     FUNCC(h264_loop_filter_chroma_intra)(pix, sizeof(pixel), stride, 1, alpha, beta);
     320      516132 : }
     321     1249330 : static void FUNCC(h264_h_loop_filter_chroma422_intra)(uint8_t *pix, int stride, int alpha, int beta)
     322             : {
     323     1249330 :     FUNCC(h264_loop_filter_chroma_intra)(pix, sizeof(pixel), stride, 4, alpha, beta);
     324     1249330 : }
     325      219584 : static void FUNCC(h264_h_loop_filter_chroma422_mbaff_intra)(uint8_t *pix, int stride, int alpha, int beta)
     326             : {
     327      219584 :     FUNCC(h264_loop_filter_chroma_intra)(pix, sizeof(pixel), stride, 2, alpha, beta);
     328      219584 : }

Generated by: LCOV version 1.13