LCOV - code coverage report
Current view: top level - libavcodec - h264idct_template.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 203 203 100.0 %
Date: 2017-12-15 02:19:58 Functions: 36 60 60.0 %

          Line data    Source code
       1             : /*
       2             :  * H.264 IDCT
       3             :  * Copyright (c) 2004-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 IDCT.
      25             :  * @author Michael Niedermayer <michaelni@gmx.at>
      26             :  */
      27             : 
      28             : #include "bit_depth_template.c"
      29             : #include "libavutil/common.h"
      30             : #include "h264dec.h"
      31             : #include "h264idct.h"
      32             : 
      33    50822416 : void FUNCC(ff_h264_idct_add)(uint8_t *_dst, int16_t *_block, int stride)
      34             : {
      35             :     int i;
      36    50822416 :     pixel *dst = (pixel*)_dst;
      37    50822416 :     dctcoef *block = (dctcoef*)_block;
      38    50822416 :     stride >>= sizeof(pixel)-1;
      39             : 
      40    50822416 :     block[0] += 1 << 5;
      41             : 
      42   254112080 :     for(i=0; i<4; i++){
      43   203289664 :         const SUINT z0=  block[i + 4*0]     +  (unsigned)block[i + 4*2];
      44   203289664 :         const SUINT z1=  block[i + 4*0]     -  (unsigned)block[i + 4*2];
      45   203289664 :         const SUINT z2= (block[i + 4*1]>>1) -  (unsigned)block[i + 4*3];
      46   203289664 :         const SUINT z3=  block[i + 4*1]     + (unsigned)(block[i + 4*3]>>1);
      47             : 
      48   203289664 :         block[i + 4*0]= z0 + z3;
      49   203289664 :         block[i + 4*1]= z1 + z2;
      50   203289664 :         block[i + 4*2]= z1 - z2;
      51   203289664 :         block[i + 4*3]= z0 - z3;
      52             :     }
      53             : 
      54   254112080 :     for(i=0; i<4; i++){
      55   203289664 :         const SUINT z0=  block[0 + 4*i]     +  (SUINT)block[2 + 4*i];
      56   203289664 :         const SUINT z1=  block[0 + 4*i]     -  (SUINT)block[2 + 4*i];
      57   203289664 :         const SUINT z2= (block[1 + 4*i]>>1) -  (SUINT)block[3 + 4*i];
      58   203289664 :         const SUINT z3=  block[1 + 4*i]     + (SUINT)(block[3 + 4*i]>>1);
      59             : 
      60   203289664 :         dst[i + 0*stride]= av_clip_pixel(dst[i + 0*stride] + ((int)(z0 + z3) >> 6));
      61   203289664 :         dst[i + 1*stride]= av_clip_pixel(dst[i + 1*stride] + ((int)(z1 + z2) >> 6));
      62   203289664 :         dst[i + 2*stride]= av_clip_pixel(dst[i + 2*stride] + ((int)(z1 - z2) >> 6));
      63   203289664 :         dst[i + 3*stride]= av_clip_pixel(dst[i + 3*stride] + ((int)(z0 - z3) >> 6));
      64             :     }
      65             : 
      66    50822416 :     memset(block, 0, 16 * sizeof(dctcoef));
      67    50822416 : }
      68             : 
      69     6523206 : void FUNCC(ff_h264_idct8_add)(uint8_t *_dst, int16_t *_block, int stride){
      70             :     int i;
      71     6523206 :     pixel *dst = (pixel*)_dst;
      72     6523206 :     dctcoef *block = (dctcoef*)_block;
      73     6523206 :     stride >>= sizeof(pixel)-1;
      74             : 
      75     6523206 :     block[0] += 32;
      76             : 
      77    58708854 :     for( i = 0; i < 8; i++ )
      78             :     {
      79    52185648 :         const unsigned int a0 =  block[i+0*8] + (unsigned)block[i+4*8];
      80    52185648 :         const unsigned int a2 =  block[i+0*8] - (unsigned)block[i+4*8];
      81    52185648 :         const unsigned int a4 = (block[i+2*8]>>1) - (unsigned)block[i+6*8];
      82    52185648 :         const unsigned int a6 = (block[i+6*8]>>1) + (unsigned)block[i+2*8];
      83             : 
      84    52185648 :         const unsigned int b0 = a0 + a6;
      85    52185648 :         const unsigned int b2 = a2 + a4;
      86    52185648 :         const unsigned int b4 = a2 - a4;
      87    52185648 :         const unsigned int b6 = a0 - a6;
      88             : 
      89    52185648 :         const int a1 = -block[i+3*8] + (unsigned)block[i+5*8] - block[i+7*8] - (block[i+7*8]>>1);
      90    52185648 :         const int a3 =  block[i+1*8] + (unsigned)block[i+7*8] - block[i+3*8] - (block[i+3*8]>>1);
      91    52185648 :         const int a5 = -block[i+1*8] + (unsigned)block[i+7*8] + block[i+5*8] + (block[i+5*8]>>1);
      92    52185648 :         const int a7 =  block[i+3*8] + (unsigned)block[i+5*8] + block[i+1*8] + (block[i+1*8]>>1);
      93             : 
      94    52185648 :         const int b1 = (a7>>2) + (unsigned)a1;
      95    52185648 :         const int b3 =  (unsigned)a3 + (a5>>2);
      96    52185648 :         const int b5 = (a3>>2) - (unsigned)a5;
      97    52185648 :         const int b7 =  (unsigned)a7 - (a1>>2);
      98             : 
      99    52185648 :         block[i+0*8] = b0 + b7;
     100    52185648 :         block[i+7*8] = b0 - b7;
     101    52185648 :         block[i+1*8] = b2 + b5;
     102    52185648 :         block[i+6*8] = b2 - b5;
     103    52185648 :         block[i+2*8] = b4 + b3;
     104    52185648 :         block[i+5*8] = b4 - b3;
     105    52185648 :         block[i+3*8] = b6 + b1;
     106    52185648 :         block[i+4*8] = b6 - b1;
     107             :     }
     108    58708854 :     for( i = 0; i < 8; i++ )
     109             :     {
     110    52185648 :         const unsigned a0 =  block[0+i*8] + (unsigned)block[4+i*8];
     111    52185648 :         const unsigned a2 =  block[0+i*8] - (unsigned)block[4+i*8];
     112    52185648 :         const unsigned a4 = (block[2+i*8]>>1) - (unsigned)block[6+i*8];
     113    52185648 :         const unsigned a6 = (block[6+i*8]>>1) + (unsigned)block[2+i*8];
     114             : 
     115    52185648 :         const unsigned b0 = a0 + a6;
     116    52185648 :         const unsigned b2 = a2 + a4;
     117    52185648 :         const unsigned b4 = a2 - a4;
     118    52185648 :         const unsigned b6 = a0 - a6;
     119             : 
     120    52185648 :         const int a1 = -(unsigned)block[3+i*8] + block[5+i*8] - block[7+i*8] - (block[7+i*8]>>1);
     121    52185648 :         const int a3 =  (unsigned)block[1+i*8] + block[7+i*8] - block[3+i*8] - (block[3+i*8]>>1);
     122    52185648 :         const int a5 = -(unsigned)block[1+i*8] + block[7+i*8] + block[5+i*8] + (block[5+i*8]>>1);
     123    52185648 :         const int a7 =  (unsigned)block[3+i*8] + block[5+i*8] + block[1+i*8] + (block[1+i*8]>>1);
     124             : 
     125    52185648 :         const unsigned b1 = (a7>>2) + (unsigned)a1;
     126    52185648 :         const unsigned b3 =  (unsigned)a3 + (a5>>2);
     127    52185648 :         const unsigned b5 = (a3>>2) - (unsigned)a5;
     128    52185648 :         const unsigned b7 =  (unsigned)a7 - (a1>>2);
     129             : 
     130    52185648 :         dst[i + 0*stride] = av_clip_pixel( dst[i + 0*stride] + ((int)(b0 + b7) >> 6) );
     131    52185648 :         dst[i + 1*stride] = av_clip_pixel( dst[i + 1*stride] + ((int)(b2 + b5) >> 6) );
     132    52185648 :         dst[i + 2*stride] = av_clip_pixel( dst[i + 2*stride] + ((int)(b4 + b3) >> 6) );
     133    52185648 :         dst[i + 3*stride] = av_clip_pixel( dst[i + 3*stride] + ((int)(b6 + b1) >> 6) );
     134    52185648 :         dst[i + 4*stride] = av_clip_pixel( dst[i + 4*stride] + ((int)(b6 - b1) >> 6) );
     135    52185648 :         dst[i + 5*stride] = av_clip_pixel( dst[i + 5*stride] + ((int)(b4 - b3) >> 6) );
     136    52185648 :         dst[i + 6*stride] = av_clip_pixel( dst[i + 6*stride] + ((int)(b2 - b5) >> 6) );
     137    52185648 :         dst[i + 7*stride] = av_clip_pixel( dst[i + 7*stride] + ((int)(b0 - b7) >> 6) );
     138             :     }
     139             : 
     140     6523206 :     memset(block, 0, 64 * sizeof(dctcoef));
     141     6523206 : }
     142             : 
     143             : // assumes all AC coefs are 0
     144    27704411 : void FUNCC(ff_h264_idct_dc_add)(uint8_t *_dst, int16_t *_block, int stride){
     145             :     int i, j;
     146    27704411 :     pixel *dst = (pixel*)_dst;
     147    27704411 :     dctcoef *block = (dctcoef*)_block;
     148    27704411 :     int dc = (block[0] + 32) >> 6;
     149    27704411 :     stride /= sizeof(pixel);
     150    27704411 :     block[0] = 0;
     151   138522055 :     for( j = 0; j < 4; j++ )
     152             :     {
     153   554088220 :         for( i = 0; i < 4; i++ )
     154   443270576 :             dst[i] = av_clip_pixel( dst[i] + dc );
     155   110817644 :         dst += stride;
     156             :     }
     157    27704411 : }
     158             : 
     159      531902 : void FUNCC(ff_h264_idct8_dc_add)(uint8_t *_dst, int16_t *_block, int stride){
     160             :     int i, j;
     161      531902 :     pixel *dst = (pixel*)_dst;
     162      531902 :     dctcoef *block = (dctcoef*)_block;
     163      531902 :     int dc = (block[0] + 32) >> 6;
     164      531902 :     block[0] = 0;
     165      531902 :     stride /= sizeof(pixel);
     166     4787118 :     for( j = 0; j < 8; j++ )
     167             :     {
     168    38296944 :         for( i = 0; i < 8; i++ )
     169    34041728 :             dst[i] = av_clip_pixel( dst[i] + dc );
     170     4255216 :         dst += stride;
     171             :     }
     172      531902 : }
     173             : 
     174     4321262 : void FUNCC(ff_h264_idct_add16)(uint8_t *dst, const int *block_offset, int16_t *block, int stride, const uint8_t nnzc[15*8]){
     175             :     int i;
     176    73461454 :     for(i=0; i<16; i++){
     177    69140192 :         int nnz = nnzc[ scan8[i] ];
     178    69140192 :         if(nnz){
     179    26185718 :             if(nnz==1 && ((dctcoef*)block)[i*16]) FUNCC(ff_h264_idct_dc_add)(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
     180    21811171 :             else                                  FUNCC(ff_h264_idct_add   )(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
     181             :         }
     182             :     }
     183     4321262 : }
     184             : 
     185      826233 : void FUNCC(ff_h264_idct_add16intra)(uint8_t *dst, const int *block_offset, int16_t *block, int stride, const uint8_t nnzc[15*8]){
     186             :     int i;
     187    14045961 :     for(i=0; i<16; i++){
     188    13219728 :         if(nnzc[ scan8[i] ])             FUNCC(ff_h264_idct_add   )(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
     189     9556329 :         else if(((dctcoef*)block)[i*16]) FUNCC(ff_h264_idct_dc_add)(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
     190             :     }
     191      826233 : }
     192             : 
     193      785198 : void FUNCC(ff_h264_idct8_add4)(uint8_t *dst, const int *block_offset, int16_t *block, int stride, const uint8_t nnzc[15*8]){
     194             :     int i;
     195     3925990 :     for(i=0; i<16; i+=4){
     196     3140792 :         int nnz = nnzc[ scan8[i] ];
     197     3140792 :         if(nnz){
     198     2040734 :             if(nnz==1 && ((dctcoef*)block)[i*16]) FUNCC(ff_h264_idct8_dc_add)(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
     199     1746221 :             else                                  FUNCC(ff_h264_idct8_add   )(dst + block_offset[i], block + i*16*sizeof(pixel), stride);
     200             :         }
     201             :     }
     202      785198 : }
     203             : 
     204     4103140 : void FUNCC(ff_h264_idct_add8)(uint8_t **dest, const int *block_offset, int16_t *block, int stride, const uint8_t nnzc[15*8]){
     205             :     int i, j;
     206    12309420 :     for(j=1; j<3; j++){
     207    41031400 :         for(i=j*16; i<j*16+4; i++){
     208    32825120 :             if(nnzc[ scan8[i] ])
     209     7891970 :                 FUNCC(ff_h264_idct_add   )(dest[j-1] + block_offset[i], block + i*16*sizeof(pixel), stride);
     210    24933150 :             else if(((dctcoef*)block)[i*16])
     211    11940052 :                 FUNCC(ff_h264_idct_dc_add)(dest[j-1] + block_offset[i], block + i*16*sizeof(pixel), stride);
     212             :         }
     213             :     }
     214     4103140 : }
     215             : 
     216      675318 : void FUNCC(ff_h264_idct_add8_422)(uint8_t **dest, const int *block_offset, int16_t *block, int stride, const uint8_t nnzc[15*8]){
     217             :     int i, j;
     218             : 
     219     2025954 :     for(j=1; j<3; j++){
     220     6753180 :         for(i=j*16; i<j*16+4; i++){
     221     5402544 :             if(nnzc[ scan8[i] ])
     222     1820857 :                 FUNCC(ff_h264_idct_add   )(dest[j-1] + block_offset[i], block + i*16*sizeof(pixel), stride);
     223     3581687 :             else if(((dctcoef*)block)[i*16])
     224     2290895 :                 FUNCC(ff_h264_idct_dc_add)(dest[j-1] + block_offset[i], block + i*16*sizeof(pixel), stride);
     225             :         }
     226             :     }
     227             : 
     228     2025954 :     for(j=1; j<3; j++){
     229     6753180 :         for(i=j*16+4; i<j*16+8; i++){
     230     5402544 :             if(nnzc[ scan8[i+4] ])
     231     1845890 :                 FUNCC(ff_h264_idct_add   )(dest[j-1] + block_offset[i+4], block + i*16*sizeof(pixel), stride);
     232     3556654 :             else if(((dctcoef*)block)[i*16])
     233     2323433 :                 FUNCC(ff_h264_idct_dc_add)(dest[j-1] + block_offset[i+4], block + i*16*sizeof(pixel), stride);
     234             :         }
     235             :     }
     236      675318 : }
     237             : 
     238             : /**
     239             :  * IDCT transforms the 16 dc values and dequantizes them.
     240             :  * @param qmul quantization parameter
     241             :  */
     242      567722 : void FUNCC(ff_h264_luma_dc_dequant_idct)(int16_t *_output, int16_t *_input, int qmul){
     243             : #define stride 16
     244             :     int i;
     245             :     int temp[16];
     246             :     static const uint8_t x_offset[4]={0, 2*stride, 8*stride, 10*stride};
     247      567722 :     dctcoef *input = (dctcoef*)_input;
     248      567722 :     dctcoef *output = (dctcoef*)_output;
     249             : 
     250     2838610 :     for(i=0; i<4; i++){
     251     2270888 :         const int z0= input[4*i+0] + input[4*i+1];
     252     2270888 :         const int z1= input[4*i+0] - input[4*i+1];
     253     2270888 :         const int z2= input[4*i+2] - input[4*i+3];
     254     2270888 :         const int z3= input[4*i+2] + input[4*i+3];
     255             : 
     256     2270888 :         temp[4*i+0]= z0+z3;
     257     2270888 :         temp[4*i+1]= z0-z3;
     258     2270888 :         temp[4*i+2]= z1-z2;
     259     2270888 :         temp[4*i+3]= z1+z2;
     260             :     }
     261             : 
     262     2838610 :     for(i=0; i<4; i++){
     263     2270888 :         const int offset= x_offset[i];
     264     2270888 :         const SUINT z0= temp[4*0+i] + temp[4*2+i];
     265     2270888 :         const SUINT z1= temp[4*0+i] - temp[4*2+i];
     266     2270888 :         const SUINT z2= temp[4*1+i] - temp[4*3+i];
     267     2270888 :         const SUINT z3= temp[4*1+i] + temp[4*3+i];
     268             : 
     269     2270888 :         output[stride* 0+offset]= (int)((z0 + z3)*qmul + 128 ) >> 8;
     270     2270888 :         output[stride* 1+offset]= (int)((z1 + z2)*qmul + 128 ) >> 8;
     271     2270888 :         output[stride* 4+offset]= (int)((z1 - z2)*qmul + 128 ) >> 8;
     272     2270888 :         output[stride* 5+offset]= (int)((z0 - z3)*qmul + 128 ) >> 8;
     273             :     }
     274             : #undef stride
     275      567722 : }
     276             : 
     277     1126031 : void FUNCC(ff_h264_chroma422_dc_dequant_idct)(int16_t *_block, int qmul){
     278     1126031 :     const int stride= 16*2;
     279     1126031 :     const int xStride= 16;
     280             :     int i;
     281             :     int temp[8];
     282             :     static const uint8_t x_offset[2]={0, 16};
     283     1126031 :     dctcoef *block = (dctcoef*)_block;
     284             : 
     285     5630155 :     for(i=0; i<4; i++){
     286     4504124 :         temp[2*i+0] = block[stride*i + xStride*0] + block[stride*i + xStride*1];
     287     4504124 :         temp[2*i+1] = block[stride*i + xStride*0] - block[stride*i + xStride*1];
     288             :     }
     289             : 
     290     3378093 :     for(i=0; i<2; i++){
     291     2252062 :         const int offset= x_offset[i];
     292     2252062 :         const SUINT z0= temp[2*0+i] + temp[2*2+i];
     293     2252062 :         const SUINT z1= temp[2*0+i] - temp[2*2+i];
     294     2252062 :         const SUINT z2= temp[2*1+i] - temp[2*3+i];
     295     2252062 :         const SUINT z3= temp[2*1+i] + temp[2*3+i];
     296             : 
     297     2252062 :         block[stride*0+offset]= (int)((z0 + z3)*qmul + 128) >> 8;
     298     2252062 :         block[stride*1+offset]= (int)((z1 + z2)*qmul + 128) >> 8;
     299     2252062 :         block[stride*2+offset]= (int)((z1 - z2)*qmul + 128) >> 8;
     300     2252062 :         block[stride*3+offset]= (int)((z0 - z3)*qmul + 128) >> 8;
     301             :     }
     302     1126031 : }
     303             : 
     304     5597124 : void FUNCC(ff_h264_chroma_dc_dequant_idct)(int16_t *_block, int qmul){
     305     5597124 :     const int stride= 16*2;
     306     5597124 :     const int xStride= 16;
     307             :     SUINT a,b,c,d,e;
     308     5597124 :     dctcoef *block = (dctcoef*)_block;
     309             : 
     310     5597124 :     a= block[stride*0 + xStride*0];
     311     5597124 :     b= block[stride*0 + xStride*1];
     312     5597124 :     c= block[stride*1 + xStride*0];
     313     5597124 :     d= block[stride*1 + xStride*1];
     314             : 
     315     5597124 :     e= a-b;
     316     5597124 :     a= a+b;
     317     5597124 :     b= c-d;
     318     5597124 :     c= c+d;
     319             : 
     320     5597124 :     block[stride*0 + xStride*0]= (int)((a+c)*qmul) >> 7;
     321     5597124 :     block[stride*0 + xStride*1]= (int)((e+b)*qmul) >> 7;
     322     5597124 :     block[stride*1 + xStride*0]= (int)((a-c)*qmul) >> 7;
     323     5597124 :     block[stride*1 + xStride*1]= (int)((e-b)*qmul) >> 7;
     324     5597124 : }

Generated by: LCOV version 1.13