LCOV - code coverage report
Current view: top level - tests/checkasm - vf_nlmeans.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 51 0.0 %
Date: 2018-05-20 11:54:08 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2018 Clément Bœsch <u pkh me>
       3             :  *
       4             :  * This file is part of FFmpeg.
       5             :  *
       6             :  * FFmpeg is free software; you can redistribute it and/or
       7             :  * modify it under the terms of the GNU Lesser General Public
       8             :  * License as published by the Free Software Foundation; either
       9             :  * version 2.1 of the License, or (at your option) any later version.
      10             :  *
      11             :  * FFmpeg is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14             :  * Lesser General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU Lesser General Public
      17             :  * License along with FFmpeg; if not, write to the Free Software
      18             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      19             :  */
      20             : 
      21             : #include "checkasm.h"
      22             : #include "libavfilter/vf_nlmeans.h"
      23             : #include "libavutil/avassert.h"
      24             : 
      25             : #define randomize_buffer(buf, size) do {    \
      26             :     int i;                                  \
      27             :     for (i = 0; i < size / 4; i++)          \
      28             :         ((uint32_t *)buf)[i] = rnd();       \
      29             : } while (0)
      30             : 
      31           0 : void checkasm_check_nlmeans(void)
      32             : {
      33           0 :     NLMeansDSPContext dsp = {0};
      34             : 
      35           0 :     const int w = 123;  // source width
      36           0 :     const int h = 45;   // source height
      37           0 :     const int p = 3;    // patch half size
      38           0 :     const int r = 2;    // research window half size
      39             : 
      40           0 :     ff_nlmeans_init(&dsp);
      41             : 
      42             :     /* See the filter's code for the explanations on the variables */
      43           0 :     if (check_func(dsp.compute_safe_ssd_integral_image, "ssd_integral_image")) {
      44             :         int offx, offy;
      45           0 :         const int e = p + r;
      46           0 :         const int ii_w = w + e*2;
      47           0 :         const int ii_h = h + e*2;
      48           0 :         const int ii_lz_32 = FFALIGN(ii_w + 1, 4);
      49           0 :         uint32_t *ii_orig_ref = av_mallocz_array(ii_h + 1, ii_lz_32 * sizeof(*ii_orig_ref));
      50           0 :         uint32_t *ii_ref = ii_orig_ref + ii_lz_32 + 1;
      51           0 :         uint32_t *ii_orig_new = av_mallocz_array(ii_h + 1, ii_lz_32 * sizeof(*ii_orig_new));
      52           0 :         uint32_t *ii_new = ii_orig_new + ii_lz_32 + 1;
      53           0 :         const int src_lz = FFALIGN(w, 16);
      54           0 :         uint8_t *src = av_mallocz_array(h, src_lz);
      55             : 
      56           0 :         declare_func(void, uint32_t *dst, ptrdiff_t dst_linesize_32,
      57             :                      const uint8_t *s1, ptrdiff_t linesize1,
      58             :                      const uint8_t *s2, ptrdiff_t linesize2,
      59             :                      int w, int h);
      60             : 
      61           0 :         randomize_buffer(src, h * src_lz);
      62             : 
      63           0 :         for (offy = -r; offy <= r; offy++) {
      64           0 :             for (offx = -r; offx <= r; offx++) {
      65           0 :                 if (offx || offy) {
      66           0 :                     const int s1x = e;
      67           0 :                     const int s1y = e;
      68           0 :                     const int s2x = e + offx;
      69           0 :                     const int s2y = e + offy;
      70           0 :                     const int startx_safe = FFMAX(s1x, s2x);
      71           0 :                     const int starty_safe = FFMAX(s1y, s2y);
      72           0 :                     const int u_endx_safe = FFMIN(s1x + w, s2x + w);
      73           0 :                     const int endy_safe   = FFMIN(s1y + h, s2y + h);
      74           0 :                     const int safe_pw = (u_endx_safe - startx_safe) & ~0xf;
      75           0 :                     const int safe_ph = endy_safe - starty_safe;
      76             : 
      77           0 :                     av_assert0(safe_pw && safe_ph);
      78           0 :                     av_assert0(startx_safe - s1x >= 0); av_assert0(startx_safe - s1x < w);
      79           0 :                     av_assert0(starty_safe - s1y >= 0); av_assert0(starty_safe - s1y < h);
      80           0 :                     av_assert0(startx_safe - s2x >= 0); av_assert0(startx_safe - s2x < w);
      81           0 :                     av_assert0(starty_safe - s2y >= 0); av_assert0(starty_safe - s2y < h);
      82             : 
      83           0 :                     memset(ii_ref, 0, (ii_lz_32 * ii_h - 1) * sizeof(*ii_ref));
      84           0 :                     memset(ii_new, 0, (ii_lz_32 * ii_h - 1) * sizeof(*ii_new));
      85             : 
      86           0 :                     call_ref(ii_ref + starty_safe*ii_lz_32 + startx_safe, ii_lz_32,
      87             :                              src + (starty_safe - s1y) * src_lz + (startx_safe - s1x), src_lz,
      88             :                              src + (starty_safe - s2y) * src_lz + (startx_safe - s2x), src_lz,
      89             :                              safe_pw, safe_ph);
      90           0 :                     call_new(ii_new + starty_safe*ii_lz_32 + startx_safe, ii_lz_32,
      91             :                              src + (starty_safe - s1y) * src_lz + (startx_safe - s1x), src_lz,
      92             :                              src + (starty_safe - s2y) * src_lz + (startx_safe - s2x), src_lz,
      93             :                              safe_pw, safe_ph);
      94             : 
      95           0 :                     if (memcmp(ii_ref, ii_new, (ii_lz_32 * ii_h - 1) * sizeof(*ii_ref)))
      96           0 :                         fail();
      97             : 
      98           0 :                     memset(ii_new, 0, (ii_lz_32 * ii_h - 1) * sizeof(*ii_new));
      99           0 :                     bench_new(ii_new + starty_safe*ii_lz_32 + startx_safe, ii_lz_32,
     100             :                              src + (starty_safe - s1y) * src_lz + (startx_safe - s1x), src_lz,
     101             :                              src + (starty_safe - s2y) * src_lz + (startx_safe - s2x), src_lz,
     102             :                              safe_pw, safe_ph);
     103             :                 }
     104             :             }
     105             :         }
     106             : 
     107           0 :         av_freep(&ii_orig_ref);
     108           0 :         av_freep(&ii_orig_new);
     109           0 :         av_freep(&src);
     110             :     }
     111             : 
     112           0 :     report("dsp");
     113           0 : }

Generated by: LCOV version 1.13