LCOV - code coverage report
Current view: top level - libavcodec - simple_idct.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 87 93 93.5 %
Date: 2017-12-16 13:57:32 Functions: 7 8 87.5 %

          Line data    Source code
       1             : /*
       2             :  * Simple IDCT
       3             :  *
       4             :  * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
       5             :  *
       6             :  * This file is part of FFmpeg.
       7             :  *
       8             :  * FFmpeg is free software; you can redistribute it and/or
       9             :  * modify it under the terms of the GNU Lesser General Public
      10             :  * License as published by the Free Software Foundation; either
      11             :  * version 2.1 of the License, or (at your option) any later version.
      12             :  *
      13             :  * FFmpeg is distributed in the hope that it will be useful,
      14             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16             :  * Lesser General Public License for more details.
      17             :  *
      18             :  * You should have received a copy of the GNU Lesser General Public
      19             :  * License along with FFmpeg; if not, write to the Free Software
      20             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      21             :  */
      22             : 
      23             : /**
      24             :  * @file
      25             :  * simpleidct in C.
      26             :  */
      27             : 
      28             : #include "libavutil/intreadwrite.h"
      29             : #include "avcodec.h"
      30             : #include "mathops.h"
      31             : #include "simple_idct.h"
      32             : 
      33             : #define BIT_DEPTH 8
      34             : #include "simple_idct_template.c"
      35             : #undef BIT_DEPTH
      36             : 
      37             : #define BIT_DEPTH 10
      38             : #include "simple_idct_template.c"
      39             : 
      40             : #define EXTRA_SHIFT  2
      41             : #include "simple_idct_template.c"
      42             : 
      43             : #undef EXTRA_SHIFT
      44             : #undef BIT_DEPTH
      45             : 
      46             : #define BIT_DEPTH 12
      47             : #include "simple_idct_template.c"
      48             : #undef BIT_DEPTH
      49             : 
      50             : /* 2x4x8 idct */
      51             : 
      52             : #define CN_SHIFT 12
      53             : #define C_FIX(x) ((int)((x) * (1 << CN_SHIFT) + 0.5))
      54             : #define C1 C_FIX(0.6532814824)
      55             : #define C2 C_FIX(0.2705980501)
      56             : 
      57             : /* row idct is multiple by 16 * sqrt(2.0), col idct4 is normalized,
      58             :    and the butterfly must be multiplied by 0.5 * sqrt(2.0) */
      59             : #define C_SHIFT (4+1+12)
      60             : 
      61      324544 : static inline void idct4col_put(uint8_t *dest, ptrdiff_t line_size, const int16_t *col)
      62             : {
      63             :     int c0, c1, c2, c3, a0, a1, a2, a3;
      64             : 
      65      324544 :     a0 = col[8*0];
      66      324544 :     a1 = col[8*2];
      67      324544 :     a2 = col[8*4];
      68      324544 :     a3 = col[8*6];
      69      324544 :     c0 = ((a0 + a2) * (1 << CN_SHIFT - 1)) + (1 << (C_SHIFT - 1));
      70      324544 :     c2 = ((a0 - a2) * (1 << CN_SHIFT - 1)) + (1 << (C_SHIFT - 1));
      71      324544 :     c1 = a1 * C1 + a3 * C2;
      72      324544 :     c3 = a1 * C2 - a3 * C1;
      73      324544 :     dest[0] = av_clip_uint8((c0 + c1) >> C_SHIFT);
      74      324544 :     dest += line_size;
      75      324544 :     dest[0] = av_clip_uint8((c2 + c3) >> C_SHIFT);
      76      324544 :     dest += line_size;
      77      324544 :     dest[0] = av_clip_uint8((c2 - c3) >> C_SHIFT);
      78      324544 :     dest += line_size;
      79      324544 :     dest[0] = av_clip_uint8((c0 - c1) >> C_SHIFT);
      80      324544 : }
      81             : 
      82             : #define BF(k) \
      83             : {\
      84             :     int a0, a1;\
      85             :     a0 = ptr[k];\
      86             :     a1 = ptr[8 + k];\
      87             :     ptr[k] = a0 + a1;\
      88             :     ptr[8 + k] = a0 - a1;\
      89             : }
      90             : 
      91             : /* only used by DV codec. The input must be interlaced. 128 is added
      92             :    to the pixels before clamping to avoid systematic error
      93             :    (1024*sqrt(2)) offset would be needed otherwise. */
      94             : /* XXX: I think a 1.0/sqrt(2) normalization should be needed to
      95             :    compensate the extra butterfly stage - I don't have the full DV
      96             :    specification */
      97       20284 : void ff_simple_idct248_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
      98             : {
      99             :     int i;
     100             :     int16_t *ptr;
     101             : 
     102             :     /* butterfly */
     103       20284 :     ptr = block;
     104      101420 :     for(i=0;i<4;i++) {
     105       81136 :         BF(0);
     106       81136 :         BF(1);
     107       81136 :         BF(2);
     108       81136 :         BF(3);
     109       81136 :         BF(4);
     110       81136 :         BF(5);
     111       81136 :         BF(6);
     112       81136 :         BF(7);
     113       81136 :         ptr += 2 * 8;
     114             :     }
     115             : 
     116             :     /* IDCT8 on each line */
     117      182556 :     for(i=0; i<8; i++) {
     118      162272 :         idctRowCondDC_8(block + i*8, 0);
     119             :     }
     120             : 
     121             :     /* IDCT4 and store */
     122      182556 :     for(i=0;i<8;i++) {
     123      162272 :         idct4col_put(dest + i, 2 * line_size, block + i);
     124      162272 :         idct4col_put(dest + line_size + i, 2 * line_size, block + 8 + i);
     125             :     }
     126       20284 : }
     127             : 
     128             : /* 8x4 & 4x8 WMV2 IDCT */
     129             : #undef CN_SHIFT
     130             : #undef C_SHIFT
     131             : #undef C_FIX
     132             : #undef C1
     133             : #undef C2
     134             : #define CN_SHIFT 12
     135             : #define C_FIX(x) ((int)((x) * M_SQRT2 * (1 << CN_SHIFT) + 0.5))
     136             : #define C1 C_FIX(0.6532814824)
     137             : #define C2 C_FIX(0.2705980501)
     138             : #define C3 C_FIX(0.5)
     139             : #define C_SHIFT (4+1+12)
     140      263504 : static inline void idct4col_add(uint8_t *dest, ptrdiff_t line_size, const int16_t *col)
     141             : {
     142             :     int c0, c1, c2, c3, a0, a1, a2, a3;
     143             : 
     144      263504 :     a0 = col[8*0];
     145      263504 :     a1 = col[8*1];
     146      263504 :     a2 = col[8*2];
     147      263504 :     a3 = col[8*3];
     148      263504 :     c0 = (a0 + a2)*C3 + (1 << (C_SHIFT - 1));
     149      263504 :     c2 = (a0 - a2)*C3 + (1 << (C_SHIFT - 1));
     150      263504 :     c1 = a1 * C1 + a3 * C2;
     151      263504 :     c3 = a1 * C2 - a3 * C1;
     152      263504 :     dest[0] = av_clip_uint8(dest[0] + ((c0 + c1) >> C_SHIFT));
     153      263504 :     dest += line_size;
     154      263504 :     dest[0] = av_clip_uint8(dest[0] + ((c2 + c3) >> C_SHIFT));
     155      263504 :     dest += line_size;
     156      263504 :     dest[0] = av_clip_uint8(dest[0] + ((c2 - c3) >> C_SHIFT));
     157      263504 :     dest += line_size;
     158      263504 :     dest[0] = av_clip_uint8(dest[0] + ((c0 - c1) >> C_SHIFT));
     159      263504 : }
     160             : 
     161             : #define RN_SHIFT 15
     162             : #define R_FIX(x) ((int)((x) * M_SQRT2 * (1 << RN_SHIFT) + 0.5))
     163             : #define R1 R_FIX(0.6532814824)
     164             : #define R2 R_FIX(0.2705980501)
     165             : #define R3 R_FIX(0.5)
     166             : #define R_SHIFT 11
     167      239648 : static inline void idct4row(int16_t *row)
     168             : {
     169             :     int c0, c1, c2, c3, a0, a1, a2, a3;
     170             : 
     171      239648 :     a0 = row[0];
     172      239648 :     a1 = row[1];
     173      239648 :     a2 = row[2];
     174      239648 :     a3 = row[3];
     175      239648 :     c0 = (a0 + a2)*R3 + (1 << (R_SHIFT - 1));
     176      239648 :     c2 = (a0 - a2)*R3 + (1 << (R_SHIFT - 1));
     177      239648 :     c1 = a1 * R1 + a3 * R2;
     178      239648 :     c3 = a1 * R2 - a3 * R1;
     179      239648 :     row[0]= (c0 + c1) >> R_SHIFT;
     180      239648 :     row[1]= (c2 + c3) >> R_SHIFT;
     181      239648 :     row[2]= (c2 - c3) >> R_SHIFT;
     182      239648 :     row[3]= (c0 - c1) >> R_SHIFT;
     183      239648 : }
     184             : 
     185       32938 : void ff_simple_idct84_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
     186             : {
     187             :     int i;
     188             : 
     189             :     /* IDCT8 on each line */
     190      164690 :     for(i=0; i<4; i++) {
     191      131752 :         idctRowCondDC_8(block + i*8, 0);
     192             :     }
     193             : 
     194             :     /* IDCT4 and store */
     195      296442 :     for(i=0;i<8;i++) {
     196      263504 :         idct4col_add(dest + i, line_size, block + i);
     197             :     }
     198       32938 : }
     199             : 
     200       29956 : void ff_simple_idct48_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
     201             : {
     202             :     int i;
     203             : 
     204             :     /* IDCT4 on each line */
     205      269604 :     for(i=0; i<8; i++) {
     206      239648 :         idct4row(block + i*8);
     207             :     }
     208             : 
     209             :     /* IDCT8 and store */
     210      149780 :     for(i=0; i<4; i++){
     211      119824 :         idctSparseColAdd_8(dest + i, line_size, block + i);
     212             :     }
     213       29956 : }
     214             : 
     215           0 : void ff_simple_idct44_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
     216             : {
     217             :     int i;
     218             : 
     219             :     /* IDCT4 on each line */
     220           0 :     for(i=0; i<4; i++) {
     221           0 :         idct4row(block + i*8);
     222             :     }
     223             : 
     224             :     /* IDCT4 and store */
     225           0 :     for(i=0; i<4; i++){
     226           0 :         idct4col_add(dest + i, line_size, block + i);
     227             :     }
     228           0 : }
     229             : 
     230     2818752 : void ff_prores_idct(int16_t *block, const int16_t *qmat)
     231             : {
     232             :     int i;
     233             : 
     234   183218880 :     for (i = 0; i < 64; i++)
     235   180400128 :         block[i] *= qmat[i];
     236             : 
     237    25368768 :     for (i = 0; i < 8; i++)
     238    22550016 :         idctRowCondDC_extrashift_10(block + i*8, 2);
     239             : 
     240    25368768 :     for (i = 0; i < 8; i++) {
     241    22550016 :         block[i] += 8192;
     242    22550016 :         idctSparseCol_extrashift_10(block + i);
     243             :     }
     244     2818752 : }

Generated by: LCOV version 1.13