LCOV - code coverage report
Current view: top level - libavcodec - idctdsp.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 130 177 73.4 %
Date: 2018-05-20 11:54:08 Functions: 10 16 62.5 %

          Line data    Source code
       1             : /*
       2             :  * This file is part of FFmpeg.
       3             :  *
       4             :  * FFmpeg is free software; you can redistribute it and/or
       5             :  * modify it under the terms of the GNU Lesser General Public
       6             :  * License as published by the Free Software Foundation; either
       7             :  * version 2.1 of the License, or (at your option) any later version.
       8             :  *
       9             :  * FFmpeg is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             :  * Lesser General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU Lesser General Public
      15             :  * License along with FFmpeg; if not, write to the Free Software
      16             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      17             :  */
      18             : 
      19             : #include "config.h"
      20             : #include "libavutil/attributes.h"
      21             : #include "libavutil/common.h"
      22             : #include "avcodec.h"
      23             : #include "dct.h"
      24             : #include "faanidct.h"
      25             : #include "idctdsp.h"
      26             : #include "simple_idct.h"
      27             : #include "xvididct.h"
      28             : 
      29       40668 : av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st,
      30             :                                const uint8_t *src_scantable)
      31             : {
      32             :     int i, end;
      33             : 
      34       40668 :     st->scantable = src_scantable;
      35             : 
      36     2643420 :     for (i = 0; i < 64; i++) {
      37     2602752 :         int j = src_scantable[i];
      38     2602752 :         st->permutated[i] = permutation[j];
      39             :     }
      40             : 
      41       40668 :     end = -1;
      42     2643420 :     for (i = 0; i < 64; i++) {
      43     2602752 :         int j = st->permutated[i];
      44     2602752 :         if (j > end)
      45      547836 :             end = j;
      46     2602752 :         st->raster_end[i] = end;
      47             :     }
      48       40668 : }
      49             : 
      50        1661 : av_cold void ff_init_scantable_permutation(uint8_t *idct_permutation,
      51             :                                            enum idct_permutation_type perm_type)
      52             : {
      53             :     int i;
      54             : 
      55             :     if (ARCH_X86)
      56        1661 :         if (ff_init_scantable_permutation_x86(idct_permutation,
      57             :                                               perm_type))
      58           4 :             return;
      59             : 
      60        1657 :     switch (perm_type) {
      61        1389 :     case FF_IDCT_PERM_NONE:
      62       90285 :         for (i = 0; i < 64; i++)
      63       88896 :             idct_permutation[i] = i;
      64        1389 :         break;
      65           4 :     case FF_IDCT_PERM_LIBMPEG2:
      66         260 :         for (i = 0; i < 64; i++)
      67         256 :             idct_permutation[i] = (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
      68           4 :         break;
      69         264 :     case FF_IDCT_PERM_TRANSPOSE:
      70       17160 :         for (i = 0; i < 64; i++)
      71       16896 :             idct_permutation[i] = ((i & 7) << 3) | (i >> 3);
      72         264 :         break;
      73           0 :     case FF_IDCT_PERM_PARTTRANS:
      74           0 :         for (i = 0; i < 64; i++)
      75           0 :             idct_permutation[i] = (i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3);
      76           0 :         break;
      77           0 :     default:
      78           0 :         av_log(NULL, AV_LOG_ERROR,
      79             :                "Internal error, IDCT permutation not set\n");
      80             :     }
      81             : }
      82             : 
      83      123630 : void ff_put_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels,
      84             :                              ptrdiff_t line_size)
      85             : {
      86             :     int i;
      87             : 
      88             :     /* read the pixels */
      89     1112670 :     for (i = 0; i < 8; i++) {
      90      989040 :         pixels[0] = av_clip_uint8(block[0]);
      91      989040 :         pixels[1] = av_clip_uint8(block[1]);
      92      989040 :         pixels[2] = av_clip_uint8(block[2]);
      93      989040 :         pixels[3] = av_clip_uint8(block[3]);
      94      989040 :         pixels[4] = av_clip_uint8(block[4]);
      95      989040 :         pixels[5] = av_clip_uint8(block[5]);
      96      989040 :         pixels[6] = av_clip_uint8(block[6]);
      97      989040 :         pixels[7] = av_clip_uint8(block[7]);
      98             : 
      99      989040 :         pixels += line_size;
     100      989040 :         block  += 8;
     101             :     }
     102      123630 : }
     103             : 
     104       14262 : static void put_pixels_clamped4_c(const int16_t *block, uint8_t *av_restrict pixels,
     105             :                                  int line_size)
     106             : {
     107             :     int i;
     108             : 
     109             :     /* read the pixels */
     110       71310 :     for(i=0;i<4;i++) {
     111       57048 :         pixels[0] = av_clip_uint8(block[0]);
     112       57048 :         pixels[1] = av_clip_uint8(block[1]);
     113       57048 :         pixels[2] = av_clip_uint8(block[2]);
     114       57048 :         pixels[3] = av_clip_uint8(block[3]);
     115             : 
     116       57048 :         pixels += line_size;
     117       57048 :         block += 8;
     118             :     }
     119       14262 : }
     120             : 
     121           0 : static void put_pixels_clamped2_c(const int16_t *block, uint8_t *av_restrict pixels,
     122             :                                  int line_size)
     123             : {
     124             :     int i;
     125             : 
     126             :     /* read the pixels */
     127           0 :     for(i=0;i<2;i++) {
     128           0 :         pixels[0] = av_clip_uint8(block[0]);
     129           0 :         pixels[1] = av_clip_uint8(block[1]);
     130             : 
     131           0 :         pixels += line_size;
     132           0 :         block += 8;
     133             :     }
     134           0 : }
     135             : 
     136     1011462 : static void put_signed_pixels_clamped_c(const int16_t *block,
     137             :                                         uint8_t *av_restrict pixels,
     138             :                                         ptrdiff_t line_size)
     139             : {
     140             :     int i, j;
     141             : 
     142     9103158 :     for (i = 0; i < 8; i++) {
     143    72825264 :         for (j = 0; j < 8; j++) {
     144    64733568 :             if (*block < -128)
     145          73 :                 *pixels = 0;
     146    64733495 :             else if (*block > 127)
     147       43966 :                 *pixels = 255;
     148             :             else
     149    64689529 :                 *pixels = (uint8_t) (*block + 128);
     150    64733568 :             block++;
     151    64733568 :             pixels++;
     152             :         }
     153     8091696 :         pixels += (line_size - 8);
     154             :     }
     155     1011462 : }
     156             : 
     157      344790 : void ff_add_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels,
     158             :                              ptrdiff_t line_size)
     159             : {
     160             :     int i;
     161             : 
     162             :     /* read the pixels */
     163     3103110 :     for (i = 0; i < 8; i++) {
     164     2758320 :         pixels[0] = av_clip_uint8(pixels[0] + block[0]);
     165     2758320 :         pixels[1] = av_clip_uint8(pixels[1] + block[1]);
     166     2758320 :         pixels[2] = av_clip_uint8(pixels[2] + block[2]);
     167     2758320 :         pixels[3] = av_clip_uint8(pixels[3] + block[3]);
     168     2758320 :         pixels[4] = av_clip_uint8(pixels[4] + block[4]);
     169     2758320 :         pixels[5] = av_clip_uint8(pixels[5] + block[5]);
     170     2758320 :         pixels[6] = av_clip_uint8(pixels[6] + block[6]);
     171     2758320 :         pixels[7] = av_clip_uint8(pixels[7] + block[7]);
     172     2758320 :         pixels   += line_size;
     173     2758320 :         block    += 8;
     174             :     }
     175      344790 : }
     176             : 
     177       73763 : static void add_pixels_clamped4_c(const int16_t *block, uint8_t *av_restrict pixels,
     178             :                           int line_size)
     179             : {
     180             :     int i;
     181             : 
     182             :     /* read the pixels */
     183      368815 :     for(i=0;i<4;i++) {
     184      295052 :         pixels[0] = av_clip_uint8(pixels[0] + block[0]);
     185      295052 :         pixels[1] = av_clip_uint8(pixels[1] + block[1]);
     186      295052 :         pixels[2] = av_clip_uint8(pixels[2] + block[2]);
     187      295052 :         pixels[3] = av_clip_uint8(pixels[3] + block[3]);
     188      295052 :         pixels += line_size;
     189      295052 :         block += 8;
     190             :     }
     191       73763 : }
     192             : 
     193           0 : static void add_pixels_clamped2_c(const int16_t *block, uint8_t *av_restrict pixels,
     194             :                           int line_size)
     195             : {
     196             :     int i;
     197             : 
     198             :     /* read the pixels */
     199           0 :     for(i=0;i<2;i++) {
     200           0 :         pixels[0] = av_clip_uint8(pixels[0] + block[0]);
     201           0 :         pixels[1] = av_clip_uint8(pixels[1] + block[1]);
     202           0 :         pixels += line_size;
     203           0 :         block += 8;
     204             :     }
     205           0 : }
     206             : 
     207       14262 : static void ff_jref_idct4_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
     208             : {
     209       14262 :     ff_j_rev_dct4 (block);
     210       14262 :     put_pixels_clamped4_c(block, dest, line_size);
     211       14262 : }
     212       73763 : static void ff_jref_idct4_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
     213             : {
     214       73763 :     ff_j_rev_dct4 (block);
     215       73763 :     add_pixels_clamped4_c(block, dest, line_size);
     216       73763 : }
     217             : 
     218           0 : static void ff_jref_idct2_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
     219             : {
     220           0 :     ff_j_rev_dct2 (block);
     221           0 :     put_pixels_clamped2_c(block, dest, line_size);
     222           0 : }
     223           0 : static void ff_jref_idct2_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
     224             : {
     225           0 :     ff_j_rev_dct2 (block);
     226           0 :     add_pixels_clamped2_c(block, dest, line_size);
     227           0 : }
     228             : 
     229           0 : static void ff_jref_idct1_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
     230             : {
     231           0 :     dest[0] = av_clip_uint8((block[0] + 4)>>3);
     232           0 : }
     233           0 : static void ff_jref_idct1_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
     234             : {
     235           0 :     dest[0] = av_clip_uint8(dest[0] + ((block[0] + 4)>>3));
     236           0 : }
     237             : 
     238        1512 : av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
     239             : {
     240        1512 :     const unsigned high_bit_depth = avctx->bits_per_raw_sample > 8;
     241             : 
     242        1512 :     if (avctx->lowres==1) {
     243           2 :         c->idct_put  = ff_jref_idct4_put;
     244           2 :         c->idct_add  = ff_jref_idct4_add;
     245           2 :         c->idct      = ff_j_rev_dct4;
     246           2 :         c->perm_type = FF_IDCT_PERM_NONE;
     247        1510 :     } else if (avctx->lowres==2) {
     248           0 :         c->idct_put  = ff_jref_idct2_put;
     249           0 :         c->idct_add  = ff_jref_idct2_add;
     250           0 :         c->idct      = ff_j_rev_dct2;
     251           0 :         c->perm_type = FF_IDCT_PERM_NONE;
     252        1510 :     } else if (avctx->lowres==3) {
     253           0 :         c->idct_put  = ff_jref_idct1_put;
     254           0 :         c->idct_add  = ff_jref_idct1_add;
     255           0 :         c->idct      = ff_j_rev_dct1;
     256           0 :         c->perm_type = FF_IDCT_PERM_NONE;
     257             :     } else {
     258        1510 :         if (avctx->bits_per_raw_sample == 10 || avctx->bits_per_raw_sample == 9) {
     259             :             /* 10-bit MPEG-4 Simple Studio Profile requires a higher precision IDCT
     260             :                However, it only uses idct_put */
     261          23 :             if (avctx->codec_id == AV_CODEC_ID_MPEG4 && avctx->profile == FF_PROFILE_MPEG4_SIMPLE_STUDIO)
     262           0 :                 c->idct_put              = ff_simple_idct_put_int32_10bit;
     263             :             else {
     264          23 :                 c->idct_put              = ff_simple_idct_put_int16_10bit;
     265          23 :                 c->idct_add              = ff_simple_idct_add_int16_10bit;
     266          23 :                 c->idct                  = ff_simple_idct_int16_10bit;
     267             :             }
     268          23 :             c->perm_type             = FF_IDCT_PERM_NONE;
     269        1487 :         } else if (avctx->bits_per_raw_sample == 12) {
     270           4 :             c->idct_put              = ff_simple_idct_put_int16_12bit;
     271           4 :             c->idct_add              = ff_simple_idct_add_int16_12bit;
     272           4 :             c->idct                  = ff_simple_idct_int16_12bit;
     273           4 :             c->perm_type             = FF_IDCT_PERM_NONE;
     274             :         } else {
     275        1483 :             if (avctx->idct_algo == FF_IDCT_INT) {
     276           4 :                 c->idct_put  = ff_jref_idct_put;
     277           4 :                 c->idct_add  = ff_jref_idct_add;
     278           4 :                 c->idct      = ff_j_rev_dct;
     279           4 :                 c->perm_type = FF_IDCT_PERM_LIBMPEG2;
     280             : #if CONFIG_FAANIDCT
     281        1479 :             } else if (avctx->idct_algo == FF_IDCT_FAAN) {
     282           0 :                 c->idct_put  = ff_faanidct_put;
     283           0 :                 c->idct_add  = ff_faanidct_add;
     284           0 :                 c->idct      = ff_faanidct;
     285           0 :                 c->perm_type = FF_IDCT_PERM_NONE;
     286             : #endif /* CONFIG_FAANIDCT */
     287             :             } else { // accurate/default
     288             :                 /* Be sure FF_IDCT_NONE will select this one, since it uses FF_IDCT_PERM_NONE */
     289        1479 :                 c->idct_put  = ff_simple_idct_put_int16_8bit;
     290        1479 :                 c->idct_add  = ff_simple_idct_add_int16_8bit;
     291        1479 :                 c->idct      = ff_simple_idct_int16_8bit;
     292        1479 :                 c->perm_type = FF_IDCT_PERM_NONE;
     293             :             }
     294             :         }
     295             :     }
     296             : 
     297        1512 :     c->put_pixels_clamped        = ff_put_pixels_clamped_c;
     298        1512 :     c->put_signed_pixels_clamped = put_signed_pixels_clamped_c;
     299        1512 :     c->add_pixels_clamped        = ff_add_pixels_clamped_c;
     300             : 
     301        1512 :     if (CONFIG_MPEG4_DECODER && avctx->idct_algo == FF_IDCT_XVID)
     302           4 :         ff_xvid_idct_init(c, avctx);
     303             : 
     304             :     if (ARCH_AARCH64)
     305             :         ff_idctdsp_init_aarch64(c, avctx, high_bit_depth);
     306             :     if (ARCH_ALPHA)
     307             :         ff_idctdsp_init_alpha(c, avctx, high_bit_depth);
     308             :     if (ARCH_ARM)
     309             :         ff_idctdsp_init_arm(c, avctx, high_bit_depth);
     310             :     if (ARCH_PPC)
     311             :         ff_idctdsp_init_ppc(c, avctx, high_bit_depth);
     312             :     if (ARCH_X86)
     313        1512 :         ff_idctdsp_init_x86(c, avctx, high_bit_depth);
     314             :     if (ARCH_MIPS)
     315             :         ff_idctdsp_init_mips(c, avctx, high_bit_depth);
     316             : 
     317        1512 :     ff_init_scantable_permutation(c->idct_permutation,
     318             :                                   c->perm_type);
     319        1512 : }

Generated by: LCOV version 1.13