LCOV - code coverage report
Current view: top level - libavutil/tests - pixelutils.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 62 73 84.9 %
Date: 2017-12-17 23:02:56 Functions: 3 3 100.0 %

          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/pixelutils.c"
      20             : 
      21             : #define W1 320
      22             : #define H1 240
      23             : #define W2 640
      24             : #define H2 480
      25             : 
      26          48 : static int run_single_test(const char *test,
      27             :                            const uint8_t *block1, ptrdiff_t stride1,
      28             :                            const uint8_t *block2, ptrdiff_t stride2,
      29             :                            int align, int n)
      30             : {
      31             :     int out, ref;
      32          48 :     av_pixelutils_sad_fn f_ref = sad_c[n - 1];
      33          48 :     av_pixelutils_sad_fn f_out = av_pixelutils_get_sad_fn(n, n, align, NULL);
      34             : 
      35          48 :     switch (align) {
      36          16 :     case 0: block1++; block2++; break;
      37          16 :     case 1:           block2++; break;
      38          16 :     case 2:                     break;
      39             :     }
      40             : 
      41          48 :     out = f_out(block1, stride1, block2, stride2);
      42          48 :     ref = f_ref(block1, stride1, block2, stride2);
      43          48 :     printf("[%s] [%c%c] SAD [%s] %dx%d=%d ref=%d\n",
      44             :            out == ref ? "OK" : "FAIL",
      45             :            align ? 'A' : 'U', align == 2 ? 'A' : 'U',
      46             :            test, 1<<n, 1<<n, out, ref);
      47          48 :     return out != ref;
      48             : }
      49             : 
      50           3 : static int run_test(const char *test,
      51             :                     const uint8_t *b1, const uint8_t *b2)
      52             : {
      53           3 :     int i, a, ret = 0;
      54             : 
      55          12 :     for (a = 0; a < 3; a++) {
      56           9 :         const uint8_t *block1 = b1;
      57           9 :         const uint8_t *block2 = b2;
      58             : 
      59           9 :         switch (a) {
      60           3 :         case 0: block1++; block2++; break;
      61           3 :         case 1:           block2++; break;
      62           3 :         case 2:                     break;
      63             :         }
      64          45 :         for (i = 1; i <= FF_ARRAY_ELEMS(sad_c); i++) {
      65          36 :             int r = run_single_test(test, b1, W1, b2, W2, a, i);
      66          36 :             if (r)
      67           0 :                 ret = r;
      68             :         }
      69             :     }
      70           3 :     return ret;
      71             : }
      72             : 
      73           1 : int main(void)
      74             : {
      75             :     int i, align, ret;
      76           1 :     uint8_t *buf1 = av_malloc(W1*H1);
      77           1 :     uint8_t *buf2 = av_malloc(W2*H2);
      78           1 :     uint32_t state = 0;
      79             : 
      80           1 :     if (!buf1 || !buf2) {
      81           0 :         fprintf(stderr, "malloc failure\n");
      82           0 :         ret = 1;
      83           0 :         goto end;
      84             :     }
      85             : 
      86           1 :     ff_check_pixfmt_descriptors();
      87             : 
      88             : #define RANDOM_INIT(buf, size) do {             \
      89             :     int k;                                      \
      90             :     for (k = 0; k < size; k++) {                \
      91             :         state = state * 1664525 + 1013904223;   \
      92             :         buf[k] = state>>24;                     \
      93             :     }                                           \
      94             : } while (0)
      95             : 
      96             :     /* Normal test with different strides */
      97           1 :     RANDOM_INIT(buf1, W1*H1);
      98           1 :     RANDOM_INIT(buf2, W2*H2);
      99           1 :     ret = run_test("random", buf1, buf2);
     100           1 :     if (ret < 0)
     101           0 :         goto end;
     102             : 
     103             :     /* Check for maximum SAD */
     104           1 :     memset(buf1, 0xff, W1*H1);
     105           1 :     memset(buf2, 0x00, W2*H2);
     106           1 :     ret = run_test("max", buf1, buf2);
     107           1 :     if (ret < 0)
     108           0 :         goto end;
     109             : 
     110             :     /* Check for minimum SAD */
     111           1 :     memset(buf1, 0x90, W1*H1);
     112           1 :     memset(buf2, 0x90, W2*H2);
     113           1 :     ret = run_test("min", buf1, buf2);
     114           1 :     if (ret < 0)
     115           0 :         goto end;
     116             : 
     117             :     /* Exact buffer sizes, to check for overreads */
     118           5 :     for (i = 1; i <= 4; i++) {
     119          16 :         for (align = 0; align < 3; align++) {
     120             :             int size1, size2;
     121             : 
     122          12 :             av_freep(&buf1);
     123          12 :             av_freep(&buf2);
     124             : 
     125          12 :             size1 = size2 = 1 << (i << 1);
     126             : 
     127          12 :             switch (align) {
     128           4 :             case 0: size1++; size2++; break;
     129           4 :             case 1:          size2++; break;
     130           4 :             case 2:                   break;
     131             :             }
     132             : 
     133          12 :             buf1 = av_malloc(size1);
     134          12 :             buf2 = av_malloc(size2);
     135          12 :             if (!buf1 || !buf2) {
     136           0 :                 fprintf(stderr, "malloc failure\n");
     137           0 :                 ret = 1;
     138           0 :                 goto end;
     139             :             }
     140          12 :             RANDOM_INIT(buf1, size1);
     141          12 :             RANDOM_INIT(buf2, size2);
     142          12 :             ret = run_single_test("small", buf1, 1<<i, buf2, 1<<i, align, i);
     143          12 :             if (ret < 0)
     144           0 :                 goto end;
     145             :         }
     146             :     }
     147             : 
     148           1 : end:
     149           1 :     av_free(buf1);
     150           1 :     av_free(buf2);
     151           1 :     return ret;
     152             : }

Generated by: LCOV version 1.13