FFmpeg  4.3
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 <= 5; 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 }
out
FILE * out
Definition: movenc.c:54
end
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
av_pixelutils_sad_fn
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
H2
#define H2
Definition: pixelutils.c:24
W2
#define W2
Definition: pixelutils.c:23
run_single_test
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
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
b1
static double b1(void *priv, double x, double y)
Definition: vf_xfade.c:1332
NULL
#define NULL
Definition: coverity.c:32
state
static struct @314 state
main
int main(void)
Definition: pixelutils.c:73
test
FFmpeg Automated Testing Environment ************************************Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server Uploading new samples to the fate suite FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg’s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg’s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the test
Definition: fate.txt:76
printf
printf("static const uint8_t my_array[100] = {\n")
b2
static double b2(void *priv, double x, double y)
Definition: vf_xfade.c:1333
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
r
#define r
Definition: input.c:40
ff_check_pixfmt_descriptors
void ff_check_pixfmt_descriptors(void)
Definition: pixdesc.c:2604
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
uint8_t
uint8_t
Definition: audio_convert.c:194
W1
#define W1
Definition: pixelutils.c:21
ret
ret
Definition: filter_design.txt:187
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen_template.c:38
av_pixelutils_get_sad_fn
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:66
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
H1
#define H1
Definition: pixelutils.c:22
RANDOM_INIT
#define RANDOM_INIT(buf, size)
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
pixelutils.c
block1
static int16_t block1[64]
Definition: dct.c:116
run_test
static int run_test(const char *test, const uint8_t *b1, const uint8_t *b2)
Definition: pixelutils.c:50