LCOV - code coverage report
Current view: top level - libavcodec - mpegvideoencdsp.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 59 127 46.5 %
Date: 2017-12-15 11:05:35 Functions: 4 9 44.4 %

          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 <assert.h>
      20             : #include <stdint.h>
      21             : #include <string.h>
      22             : 
      23             : #include "config.h"
      24             : #include "libavutil/avassert.h"
      25             : #include "libavutil/attributes.h"
      26             : #include "libavutil/imgutils.h"
      27             : #include "avcodec.h"
      28             : #include "me_cmp.h"
      29             : #include "mpegvideoencdsp.h"
      30             : 
      31           0 : static int try_8x8basis_c(int16_t rem[64], int16_t weight[64],
      32             :                           int16_t basis[64], int scale)
      33             : {
      34             :     int i;
      35           0 :     unsigned int sum = 0;
      36             : 
      37           0 :     for (i = 0; i < 8 * 8; i++) {
      38           0 :         int b = rem[i] + ((basis[i] * scale +
      39           0 :                            (1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >>
      40             :                           (BASIS_SHIFT - RECON_SHIFT));
      41           0 :         int w = weight[i];
      42           0 :         b >>= RECON_SHIFT;
      43             :         av_assert2(-512 < b && b < 512);
      44             : 
      45           0 :         sum += (w * b) * (w * b) >> 4;
      46             :     }
      47           0 :     return sum >> 2;
      48             : }
      49             : 
      50           0 : static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale)
      51             : {
      52             :     int i;
      53             : 
      54           0 :     for (i = 0; i < 8 * 8; i++)
      55           0 :         rem[i] += (basis[i] * scale +
      56           0 :                    (1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >>
      57             :                   (BASIS_SHIFT - RECON_SHIFT);
      58           0 : }
      59             : 
      60     3740957 : static int pix_sum_c(uint8_t *pix, int line_size)
      61             : {
      62     3740957 :     int s = 0, i, j;
      63             : 
      64    63596269 :     for (i = 0; i < 16; i++) {
      65   179565936 :         for (j = 0; j < 16; j += 8) {
      66   119710624 :             s   += pix[0];
      67   119710624 :             s   += pix[1];
      68   119710624 :             s   += pix[2];
      69   119710624 :             s   += pix[3];
      70   119710624 :             s   += pix[4];
      71   119710624 :             s   += pix[5];
      72   119710624 :             s   += pix[6];
      73   119710624 :             s   += pix[7];
      74   119710624 :             pix += 8;
      75             :         }
      76    59855312 :         pix += line_size - 16;
      77             :     }
      78     3740957 :     return s;
      79             : }
      80             : 
      81     3740957 : static int pix_norm1_c(uint8_t *pix, int line_size)
      82             : {
      83     3740957 :     int s = 0, i, j;
      84     3740957 :     uint32_t *sq = ff_square_tab + 256;
      85             : 
      86    63596269 :     for (i = 0; i < 16; i++) {
      87   179565936 :         for (j = 0; j < 16; j += 8) {
      88             : #if HAVE_FAST_64BIT
      89   119710624 :             register uint64_t x = *(uint64_t *) pix;
      90   119710624 :             s += sq[x         & 0xff];
      91   119710624 :             s += sq[(x >>  8) & 0xff];
      92   119710624 :             s += sq[(x >> 16) & 0xff];
      93   119710624 :             s += sq[(x >> 24) & 0xff];
      94   119710624 :             s += sq[(x >> 32) & 0xff];
      95   119710624 :             s += sq[(x >> 40) & 0xff];
      96   119710624 :             s += sq[(x >> 48) & 0xff];
      97   119710624 :             s += sq[(x >> 56) & 0xff];
      98             : #else
      99             :             register uint32_t x = *(uint32_t *) pix;
     100             :             s += sq[x         & 0xff];
     101             :             s += sq[(x >>  8) & 0xff];
     102             :             s += sq[(x >> 16) & 0xff];
     103             :             s += sq[(x >> 24) & 0xff];
     104             :             x  = *(uint32_t *) (pix + 4);
     105             :             s += sq[x         & 0xff];
     106             :             s += sq[(x >>  8) & 0xff];
     107             :             s += sq[(x >> 16) & 0xff];
     108             :             s += sq[(x >> 24) & 0xff];
     109             : #endif
     110   119710624 :             pix += 8;
     111             :         }
     112    59855312 :         pix += line_size - 16;
     113             :     }
     114     3740957 :     return s;
     115             : }
     116             : 
     117             : /* draw the edges of width 'w' of an image of size width, height */
     118             : // FIXME: Check that this is OK for MPEG-4 interlaced.
     119       17298 : static void draw_edges_8_c(uint8_t *buf, int wrap, int width, int height,
     120             :                            int w, int h, int sides)
     121             : {
     122       17298 :     uint8_t *ptr = buf, *last_line;
     123             :     int i;
     124             : 
     125             :     /* left and right */
     126     2054398 :     for (i = 0; i < height; i++) {
     127     2037100 :         memset(ptr - w, ptr[0], w);
     128     2037100 :         memset(ptr + width, ptr[width - 1], w);
     129     2037100 :         ptr += wrap;
     130             :     }
     131             : 
     132             :     /* top and bottom + corners */
     133       17298 :     buf -= w;
     134       17298 :     last_line = buf + (height - 1) * wrap;
     135       17298 :     if (sides & EDGE_TOP)
     136      144479 :         for (i = 0; i < h; i++)
     137             :             // top
     138      132056 :             memcpy(buf - (i + 1) * wrap, buf, width + w + w);
     139       17298 :     if (sides & EDGE_BOTTOM)
     140      210954 :         for (i = 0; i < h; i++)
     141             :             // bottom
     142      193656 :             memcpy(last_line + (i + 1) * wrap, last_line, width + w + w);
     143       17298 : }
     144             : 
     145             : /* 2x2 -> 1x1 */
     146           0 : static void shrink22(uint8_t *dst, int dst_wrap,
     147             :                      const uint8_t *src, int src_wrap,
     148             :                      int width, int height)
     149             : {
     150             :     int w;
     151             :     const uint8_t *s1, *s2;
     152             :     uint8_t *d;
     153             : 
     154           0 :     for (; height > 0; height--) {
     155           0 :         s1 = src;
     156           0 :         s2 = s1 + src_wrap;
     157           0 :         d = dst;
     158           0 :         for (w = width; w >= 4; w -= 4) {
     159           0 :             d[0] = (s1[0] + s1[1] + s2[0] + s2[1] + 2) >> 2;
     160           0 :             d[1] = (s1[2] + s1[3] + s2[2] + s2[3] + 2) >> 2;
     161           0 :             d[2] = (s1[4] + s1[5] + s2[4] + s2[5] + 2) >> 2;
     162           0 :             d[3] = (s1[6] + s1[7] + s2[6] + s2[7] + 2) >> 2;
     163           0 :             s1 += 8;
     164           0 :             s2 += 8;
     165           0 :             d += 4;
     166             :         }
     167           0 :         for (; w > 0; w--) {
     168           0 :             d[0] = (s1[0] + s1[1] + s2[0] + s2[1] + 2) >> 2;
     169           0 :             s1 += 2;
     170           0 :             s2 += 2;
     171           0 :             d++;
     172             :         }
     173           0 :         src += 2 * src_wrap;
     174           0 :         dst += dst_wrap;
     175             :     }
     176           0 : }
     177             : 
     178             : /* 4x4 -> 1x1 */
     179           0 : static void shrink44(uint8_t *dst, int dst_wrap,
     180             :                      const uint8_t *src, int src_wrap,
     181             :                      int width, int height)
     182             : {
     183             :     int w;
     184             :     const uint8_t *s1, *s2, *s3, *s4;
     185             :     uint8_t *d;
     186             : 
     187           0 :     for (; height > 0; height--) {
     188           0 :         s1 = src;
     189           0 :         s2 = s1 + src_wrap;
     190           0 :         s3 = s2 + src_wrap;
     191           0 :         s4 = s3 + src_wrap;
     192           0 :         d = dst;
     193           0 :         for (w = width; w > 0; w--) {
     194           0 :             d[0] = (s1[0] + s1[1] + s1[2] + s1[3] +
     195           0 :                     s2[0] + s2[1] + s2[2] + s2[3] +
     196           0 :                     s3[0] + s3[1] + s3[2] + s3[3] +
     197           0 :                     s4[0] + s4[1] + s4[2] + s4[3] + 8) >> 4;
     198           0 :             s1 += 4;
     199           0 :             s2 += 4;
     200           0 :             s3 += 4;
     201           0 :             s4 += 4;
     202           0 :             d++;
     203             :         }
     204           0 :         src += 4 * src_wrap;
     205           0 :         dst += dst_wrap;
     206             :     }
     207           0 : }
     208             : 
     209             : /* 8x8 -> 1x1 */
     210           0 : static void shrink88(uint8_t *dst, int dst_wrap,
     211             :                      const uint8_t *src, int src_wrap,
     212             :                      int width, int height)
     213             : {
     214             :     int w, i;
     215             : 
     216           0 :     for (; height > 0; height--) {
     217           0 :         for(w = width;w > 0; w--) {
     218           0 :             int tmp = 0;
     219           0 :             for (i = 0; i < 8; i++) {
     220           0 :                 tmp += src[0] + src[1] + src[2] + src[3] +
     221           0 :                        src[4] + src[5] + src[6] + src[7];
     222           0 :                 src += src_wrap;
     223             :             }
     224           0 :             *(dst++) = (tmp + 32) >> 6;
     225           0 :             src += 8 - 8 * src_wrap;
     226             :         }
     227           0 :         src += 8 * src_wrap - 8 * width;
     228           0 :         dst += dst_wrap - width;
     229             :     }
     230           0 : }
     231             : 
     232         329 : av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c,
     233             :                                      AVCodecContext *avctx)
     234             : {
     235         329 :     c->try_8x8basis = try_8x8basis_c;
     236         329 :     c->add_8x8basis = add_8x8basis_c;
     237             : 
     238         329 :     c->shrink[0] = av_image_copy_plane;
     239         329 :     c->shrink[1] = shrink22;
     240         329 :     c->shrink[2] = shrink44;
     241         329 :     c->shrink[3] = shrink88;
     242             : 
     243         329 :     c->pix_sum   = pix_sum_c;
     244         329 :     c->pix_norm1 = pix_norm1_c;
     245             : 
     246         329 :     c->draw_edges = draw_edges_8_c;
     247             : 
     248             :     if (ARCH_ARM)
     249             :         ff_mpegvideoencdsp_init_arm(c, avctx);
     250             :     if (ARCH_PPC)
     251             :         ff_mpegvideoencdsp_init_ppc(c, avctx);
     252             :     if (ARCH_X86)
     253         329 :         ff_mpegvideoencdsp_init_x86(c, avctx);
     254             :     if (ARCH_MIPS)
     255             :         ff_mpegvideoencdsp_init_mips(c, avctx);
     256         329 : }

Generated by: LCOV version 1.13