LCOV - code coverage report
Current view: top level - libavcodec - wmv2dsp.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 152 156 97.4 %
Date: 2017-12-11 04:34:20 Functions: 13 14 92.9 %

          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 "libavutil/attributes.h"
      20             : #include "libavutil/common.h"
      21             : #include "avcodec.h"
      22             : #include "idctdsp.h"
      23             : #include "mathops.h"
      24             : #include "wmv2dsp.h"
      25             : 
      26             : #define W0 2048
      27             : #define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
      28             : #define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
      29             : #define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
      30             : #define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */
      31             : #define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
      32             : #define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
      33             : #define W7 565  /* 2048*sqrt (2)*cos (7*pi/16) */
      34             : 
      35     3017024 : static void wmv2_idct_row(short * b)
      36             : {
      37             :     int s1, s2;
      38             :     int a0, a1, a2, a3, a4, a5, a6, a7;
      39             : 
      40             :     /* step 1 */
      41     3017024 :     a1 = W1 * b[1] + W7 * b[7];
      42     3017024 :     a7 = W7 * b[1] - W1 * b[7];
      43     3017024 :     a5 = W5 * b[5] + W3 * b[3];
      44     3017024 :     a3 = W3 * b[5] - W5 * b[3];
      45     3017024 :     a2 = W2 * b[2] + W6 * b[6];
      46     3017024 :     a6 = W6 * b[2] - W2 * b[6];
      47     3017024 :     a0 = W0 * b[0] + W0 * b[4];
      48     3017024 :     a4 = W0 * b[0] - W0 * b[4];
      49             : 
      50             :     /* step 2 */
      51     3017024 :     s1 = (int)(181U * (a1 - a5 + a7 - a3) + 128) >> 8; // 1, 3, 5, 7
      52     3017024 :     s2 = (int)(181U * (a1 - a5 - a7 + a3) + 128) >> 8;
      53             : 
      54             :     /* step 3 */
      55     3017024 :     b[0] = (a0 + a2 + a1 + a5 + (1 << 7)) >> 8;
      56     3017024 :     b[1] = (a4 + a6 + s1      + (1 << 7)) >> 8;
      57     3017024 :     b[2] = (a4 - a6 + s2      + (1 << 7)) >> 8;
      58     3017024 :     b[3] = (a0 - a2 + a7 + a3 + (1 << 7)) >> 8;
      59     3017024 :     b[4] = (a0 - a2 - a7 - a3 + (1 << 7)) >> 8;
      60     3017024 :     b[5] = (a4 - a6 - s2      + (1 << 7)) >> 8;
      61     3017024 :     b[6] = (a4 + a6 - s1      + (1 << 7)) >> 8;
      62     3017024 :     b[7] = (a0 + a2 - a1 - a5 + (1 << 7)) >> 8;
      63     3017024 : }
      64             : 
      65     3017024 : static void wmv2_idct_col(short * b)
      66             : {
      67             :     int s1, s2;
      68             :     int a0, a1, a2, a3, a4, a5, a6, a7;
      69             : 
      70             :     /* step 1, with extended precision */
      71     3017024 :     a1 = (W1 * b[8 * 1] + W7 * b[8 * 7] + 4) >> 3;
      72     3017024 :     a7 = (W7 * b[8 * 1] - W1 * b[8 * 7] + 4) >> 3;
      73     3017024 :     a5 = (W5 * b[8 * 5] + W3 * b[8 * 3] + 4) >> 3;
      74     3017024 :     a3 = (W3 * b[8 * 5] - W5 * b[8 * 3] + 4) >> 3;
      75     3017024 :     a2 = (W2 * b[8 * 2] + W6 * b[8 * 6] + 4) >> 3;
      76     3017024 :     a6 = (W6 * b[8 * 2] - W2 * b[8 * 6] + 4) >> 3;
      77     3017024 :     a0 = (W0 * b[8 * 0] + W0 * b[8 * 4]    ) >> 3;
      78     3017024 :     a4 = (W0 * b[8 * 0] - W0 * b[8 * 4]    ) >> 3;
      79             : 
      80             :     /* step 2 */
      81     3017024 :     s1 = (int)(181U * (a1 - a5 + a7 - a3) + 128) >> 8;
      82     3017024 :     s2 = (int)(181U * (a1 - a5 - a7 + a3) + 128) >> 8;
      83             : 
      84             :     /* step 3 */
      85     3017024 :     b[8 * 0] = (a0 + a2 + a1 + a5 + (1 << 13)) >> 14;
      86     3017024 :     b[8 * 1] = (a4 + a6 + s1      + (1 << 13)) >> 14;
      87     3017024 :     b[8 * 2] = (a4 - a6 + s2      + (1 << 13)) >> 14;
      88     3017024 :     b[8 * 3] = (a0 - a2 + a7 + a3 + (1 << 13)) >> 14;
      89             : 
      90     3017024 :     b[8 * 4] = (a0 - a2 - a7 - a3 + (1 << 13)) >> 14;
      91     3017024 :     b[8 * 5] = (a4 - a6 - s2      + (1 << 13)) >> 14;
      92     3017024 :     b[8 * 6] = (a4 + a6 - s1      + (1 << 13)) >> 14;
      93     3017024 :     b[8 * 7] = (a0 + a2 - a1 - a5 + (1 << 13)) >> 14;
      94     3017024 : }
      95             : 
      96      262288 : static void wmv2_idct_add_c(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
      97             : {
      98             :     int i;
      99             : 
     100     2360592 :     for (i = 0; i < 64; i += 8)
     101     2098304 :         wmv2_idct_row(block + i);
     102     2360592 :     for (i = 0; i < 8; i++)
     103     2098304 :         wmv2_idct_col(block + i);
     104             : 
     105     2360592 :     for (i = 0; i < 8; i++) {
     106     2098304 :         dest[0] = av_clip_uint8(dest[0] + block[0]);
     107     2098304 :         dest[1] = av_clip_uint8(dest[1] + block[1]);
     108     2098304 :         dest[2] = av_clip_uint8(dest[2] + block[2]);
     109     2098304 :         dest[3] = av_clip_uint8(dest[3] + block[3]);
     110     2098304 :         dest[4] = av_clip_uint8(dest[4] + block[4]);
     111     2098304 :         dest[5] = av_clip_uint8(dest[5] + block[5]);
     112     2098304 :         dest[6] = av_clip_uint8(dest[6] + block[6]);
     113     2098304 :         dest[7] = av_clip_uint8(dest[7] + block[7]);
     114     2098304 :         dest += line_size;
     115     2098304 :         block += 8;
     116             :     }
     117      262288 : }
     118             : 
     119      114840 : static void wmv2_idct_put_c(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
     120             : {
     121             :     int i;
     122             : 
     123     1033560 :     for (i = 0; i < 64; i += 8)
     124      918720 :         wmv2_idct_row(block + i);
     125     1033560 :     for (i = 0; i < 8; i++)
     126      918720 :         wmv2_idct_col(block + i);
     127             : 
     128     1033560 :     for (i = 0; i < 8; i++) {
     129      918720 :         dest[0] = av_clip_uint8(block[0]);
     130      918720 :         dest[1] = av_clip_uint8(block[1]);
     131      918720 :         dest[2] = av_clip_uint8(block[2]);
     132      918720 :         dest[3] = av_clip_uint8(block[3]);
     133      918720 :         dest[4] = av_clip_uint8(block[4]);
     134      918720 :         dest[5] = av_clip_uint8(block[5]);
     135      918720 :         dest[6] = av_clip_uint8(block[6]);
     136      918720 :         dest[7] = av_clip_uint8(block[7]);
     137      918720 :         dest += line_size;
     138      918720 :         block += 8;
     139             :     }
     140      114840 : }
     141             : 
     142       71392 : static void wmv2_mspel8_h_lowpass(uint8_t *dst, const uint8_t *src,
     143             :                                   int dstStride, int srcStride, int h)
     144             : {
     145       71392 :     const uint8_t *cm = ff_crop_tab + MAX_NEG_CROP;
     146             :     int i;
     147             : 
     148      732216 :     for (i = 0; i < h; i++) {
     149      660824 :         dst[0] = cm[(9 * (src[0] + src[1]) - (src[-1] + src[2]) + 8) >> 4];
     150      660824 :         dst[1] = cm[(9 * (src[1] + src[2]) - (src[0]  + src[3]) + 8) >> 4];
     151      660824 :         dst[2] = cm[(9 * (src[2] + src[3]) - (src[1]  + src[4]) + 8) >> 4];
     152      660824 :         dst[3] = cm[(9 * (src[3] + src[4]) - (src[2]  + src[5]) + 8) >> 4];
     153      660824 :         dst[4] = cm[(9 * (src[4] + src[5]) - (src[3]  + src[6]) + 8) >> 4];
     154      660824 :         dst[5] = cm[(9 * (src[5] + src[6]) - (src[4]  + src[7]) + 8) >> 4];
     155      660824 :         dst[6] = cm[(9 * (src[6] + src[7]) - (src[5]  + src[8]) + 8) >> 4];
     156      660824 :         dst[7] = cm[(9 * (src[7] + src[8]) - (src[6]  + src[9]) + 8) >> 4];
     157      660824 :         dst   += dstStride;
     158      660824 :         src   += srcStride;
     159             :     }
     160       71392 : }
     161             : 
     162       55828 : static void wmv2_mspel8_v_lowpass(uint8_t *dst, const uint8_t *src,
     163             :                                   int dstStride, int srcStride, int w)
     164             : {
     165       55828 :     const uint8_t *cm = ff_crop_tab + MAX_NEG_CROP;
     166             :     int i;
     167             : 
     168      502452 :     for (i = 0; i < w; i++) {
     169      446624 :         const int src_1 = src[-srcStride];
     170      446624 :         const int src0  = src[0];
     171      446624 :         const int src1  = src[srcStride];
     172      446624 :         const int src2  = src[2 * srcStride];
     173      446624 :         const int src3  = src[3 * srcStride];
     174      446624 :         const int src4  = src[4 * srcStride];
     175      446624 :         const int src5  = src[5 * srcStride];
     176      446624 :         const int src6  = src[6 * srcStride];
     177      446624 :         const int src7  = src[7 * srcStride];
     178      446624 :         const int src8  = src[8 * srcStride];
     179      446624 :         const int src9  = src[9 * srcStride];
     180      446624 :         dst[0 * dstStride] = cm[(9 * (src0 + src1) - (src_1 + src2) + 8) >> 4];
     181      446624 :         dst[1 * dstStride] = cm[(9 * (src1 + src2) - (src0  + src3) + 8) >> 4];
     182      446624 :         dst[2 * dstStride] = cm[(9 * (src2 + src3) - (src1  + src4) + 8) >> 4];
     183      446624 :         dst[3 * dstStride] = cm[(9 * (src3 + src4) - (src2  + src5) + 8) >> 4];
     184      446624 :         dst[4 * dstStride] = cm[(9 * (src4 + src5) - (src3  + src6) + 8) >> 4];
     185      446624 :         dst[5 * dstStride] = cm[(9 * (src5 + src6) - (src4  + src7) + 8) >> 4];
     186      446624 :         dst[6 * dstStride] = cm[(9 * (src6 + src7) - (src5  + src8) + 8) >> 4];
     187      446624 :         dst[7 * dstStride] = cm[(9 * (src7 + src8) - (src6  + src9) + 8) >> 4];
     188      446624 :         src++;
     189      446624 :         dst++;
     190             :     }
     191       55828 : }
     192             : 
     193           0 : static void put_mspel8_mc10_c(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)
     194             : {
     195             :     uint8_t half[64];
     196             : 
     197           0 :     wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
     198           0 :     ff_put_pixels8_l2_8(dst, src, half, stride, stride, 8, 8);
     199           0 : }
     200             : 
     201       27436 : static void put_mspel8_mc20_c(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)
     202             : {
     203       27436 :     wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
     204       27436 : }
     205             : 
     206       14060 : static void put_mspel8_mc30_c(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)
     207             : {
     208             :     uint8_t half[64];
     209             : 
     210       14060 :     wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
     211       14060 :     ff_put_pixels8_l2_8(dst, src + 1, half, stride, stride, 8, 8);
     212       14060 : }
     213             : 
     214        6720 : static void put_mspel8_mc02_c(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)
     215             : {
     216        6720 :     wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
     217        6720 : }
     218             : 
     219        9800 : static void put_mspel8_mc12_c(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)
     220             : {
     221             :     uint8_t halfH[88];
     222             :     uint8_t halfV[64];
     223             :     uint8_t halfHV[64];
     224             : 
     225        9800 :     wmv2_mspel8_h_lowpass(halfH, src - stride, 8, stride, 11);
     226        9800 :     wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
     227        9800 :     wmv2_mspel8_v_lowpass(halfHV, halfH + 8, 8, 8, 8);
     228        9800 :     ff_put_pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8);
     229        9800 : }
     230             : 
     231        9412 : static void put_mspel8_mc32_c(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)
     232             : {
     233             :     uint8_t halfH[88];
     234             :     uint8_t halfV[64];
     235             :     uint8_t halfHV[64];
     236             : 
     237        9412 :     wmv2_mspel8_h_lowpass(halfH, src - stride, 8, stride, 11);
     238        9412 :     wmv2_mspel8_v_lowpass(halfV, src + 1, 8, stride, 8);
     239        9412 :     wmv2_mspel8_v_lowpass(halfHV, halfH + 8, 8, 8, 8);
     240        9412 :     ff_put_pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8);
     241        9412 : }
     242             : 
     243       10684 : static void put_mspel8_mc22_c(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)
     244             : {
     245             :     uint8_t halfH[88];
     246             : 
     247       10684 :     wmv2_mspel8_h_lowpass(halfH, src - stride, 8, stride, 11);
     248       10684 :     wmv2_mspel8_v_lowpass(dst, halfH + 8, stride, 8, 8);
     249       10684 : }
     250             : 
     251          64 : av_cold void ff_wmv2dsp_init(WMV2DSPContext *c)
     252             : {
     253          64 :     c->idct_add  = wmv2_idct_add_c;
     254          64 :     c->idct_put  = wmv2_idct_put_c;
     255          64 :     c->idct_perm = FF_IDCT_PERM_NONE;
     256             : 
     257          64 :     c->put_mspel_pixels_tab[0] = ff_put_pixels8x8_c;
     258          64 :     c->put_mspel_pixels_tab[1] = put_mspel8_mc10_c;
     259          64 :     c->put_mspel_pixels_tab[2] = put_mspel8_mc20_c;
     260          64 :     c->put_mspel_pixels_tab[3] = put_mspel8_mc30_c;
     261          64 :     c->put_mspel_pixels_tab[4] = put_mspel8_mc02_c;
     262          64 :     c->put_mspel_pixels_tab[5] = put_mspel8_mc12_c;
     263          64 :     c->put_mspel_pixels_tab[6] = put_mspel8_mc22_c;
     264          64 :     c->put_mspel_pixels_tab[7] = put_mspel8_mc32_c;
     265             : 
     266             :     if (ARCH_MIPS)
     267             :         ff_wmv2dsp_init_mips(c);
     268          64 : }

Generated by: LCOV version 1.13