FFmpeg  4.0
pixelutils.c
Go to the documentation of this file.
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 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  av_pixelutils_sad_fn f_ref = sad_c[n - 1];
34 
35  switch (align) {
36  case 0: block1++; block2++; break;
37  case 1: block2++; break;
38  case 2: break;
39  }
40 
41  out = f_out(block1, stride1, block2, stride2);
42  ref = f_ref(block1, stride1, block2, stride2);
43  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  return out != ref;
48 }
49 
50 static int run_test(const char *test,
51  const uint8_t *b1, const uint8_t *b2)
52 {
53  int i, a, ret = 0;
54 
55  for (a = 0; a < 3; a++) {
56  const uint8_t *block1 = b1;
57  const uint8_t *block2 = b2;
58 
59  switch (a) {
60  case 0: block1++; block2++; break;
61  case 1: block2++; break;
62  case 2: break;
63  }
64  for (i = 1; i <= FF_ARRAY_ELEMS(sad_c); i++) {
65  int r = run_single_test(test, b1, W1, b2, W2, a, i);
66  if (r)
67  ret = r;
68  }
69  }
70  return ret;
71 }
72 
73 int main(void)
74 {
75  int i, align, ret;
76  uint8_t *buf1 = av_malloc(W1*H1);
77  uint8_t *buf2 = av_malloc(W2*H2);
78  uint32_t state = 0;
79 
80  if (!buf1 || !buf2) {
81  fprintf(stderr, "malloc failure\n");
82  ret = 1;
83  goto end;
84  }
85 
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  RANDOM_INIT(buf1, W1*H1);
98  RANDOM_INIT(buf2, W2*H2);
99  ret = run_test("random", buf1, buf2);
100  if (ret < 0)
101  goto end;
102 
103  /* Check for maximum SAD */
104  memset(buf1, 0xff, W1*H1);
105  memset(buf2, 0x00, W2*H2);
106  ret = run_test("max", buf1, buf2);
107  if (ret < 0)
108  goto end;
109 
110  /* Check for minimum SAD */
111  memset(buf1, 0x90, W1*H1);
112  memset(buf2, 0x90, W2*H2);
113  ret = run_test("min", buf1, buf2);
114  if (ret < 0)
115  goto end;
116 
117  /* Exact buffer sizes, to check for overreads */
118  for (i = 1; i <= 4; i++) {
119  for (align = 0; align < 3; align++) {
120  int size1, size2;
121 
122  av_freep(&buf1);
123  av_freep(&buf2);
124 
125  size1 = size2 = 1 << (i << 1);
126 
127  switch (align) {
128  case 0: size1++; size2++; break;
129  case 1: size2++; break;
130  case 2: break;
131  }
132 
133  buf1 = av_malloc(size1);
134  buf2 = av_malloc(size2);
135  if (!buf1 || !buf2) {
136  fprintf(stderr, "malloc failure\n");
137  ret = 1;
138  goto end;
139  }
140  RANDOM_INIT(buf1, size1);
141  RANDOM_INIT(buf2, size2);
142  ret = run_single_test("small", buf1, 1<<i, buf2, 1<<i, align, i);
143  if (ret < 0)
144  goto end;
145  }
146  }
147 
148 end:
149  av_free(buf1);
150  av_free(buf2);
151  return ret;
152 }
#define NULL
Definition: coverity.c:32
uint8_t
#define av_malloc(s)
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
static int run_test(const char *test, const uint8_t *b1, const uint8_t *b2)
Definition: pixelutils.c:50
#define W2
Definition: pixelutils.c:23
const char * r
Definition: vf_curves.c:111
int(* av_pixelutils_sad_fn)(const uint8_t *src1, ptrdiff_t stride1, const uint8_t *src2, ptrdiff_t stride2)
Sum of abs(src1[x] - src2[x])
Definition: pixelutils.h:29
static int run_single_test(const char *test, const uint8_t *block1, ptrdiff_t stride1, const uint8_t *block2, ptrdiff_t stride2, int align, int n)
Definition: pixelutils.c:26
#define RANDOM_INIT(buf, size)
int n
Definition: avisynth_c.h:684
static struct @271 state
#define FF_ARRAY_ELEMS(a)
#define W1
Definition: pixelutils.c:21
const AVS_VideoInfo int align
Definition: avisynth_c.h:795
static void test(const char *pattern, const char *host)
Definition: noproxy.c:23
av_pixelutils_sad_fn av_pixelutils_get_sad_fn(int w_bits, int h_bits, int aligned, void *log_ctx)
Get a potentially optimized pointer to a Sum-of-absolute-differences function (see the av_pixelutils_...
Definition: pixelutils.c:64
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
void ff_check_pixfmt_descriptors(void)
Definition: pixdesc.c:2418
#define av_free(p)
int main(void)
Definition: pixelutils.c:73
static int16_t block1[64]
Definition: dct.c:116
FILE * out
Definition: movenc.c:54
#define av_freep(p)
#define H1
Definition: pixelutils.c:22
#define H2
Definition: pixelutils.c:24