Line | Branch | Exec | Source |
---|---|---|---|
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 <stdio.h> | ||
20 | |||
21 | #include "libavutil/avassert.h" | ||
22 | #include "libavutil/internal.h" | ||
23 | #include "libavutil/log.h" | ||
24 | #include "libavutil/mem.h" | ||
25 | #include "libavutil/pixdesc.h" | ||
26 | #include "libavutil/pixelutils.c" | ||
27 | #include "libavutil/pixfmt.h" | ||
28 | |||
29 | #define W1 320 | ||
30 | #define H1 240 | ||
31 | #define W2 640 | ||
32 | #define H2 480 | ||
33 | |||
34 | 1 | static void check_pixfmt_descriptors(void) | |
35 | { | ||
36 | 1 | const AVPixFmtDescriptor *d, *last = NULL; | |
37 | int i; | ||
38 | |||
39 |
2/2✓ Branch 1 taken 228 times.
✓ Branch 2 taken 1 times.
|
229 | for (i = AV_PIX_FMT_NONE, d = NULL; i++, d = av_pix_fmt_desc_next(d);) { |
40 | 228 | uint8_t fill[4][8 + 6 + 3] = {{ 0 }}; | |
41 | 228 | uint8_t *data[4] = { fill[0], fill[1], fill[2], fill[3] }; | |
42 | 228 | int linesize[4] = { 0, 0, 0, 0 }; | |
43 | uint16_t tmp[2]; | ||
44 | |||
45 |
2/4✓ Branch 0 taken 228 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 228 times.
|
228 | av_assert0(d->name && d->name[0]); |
46 | 228 | av_log(NULL, AV_LOG_INFO, "Checking: %s\n", d->name); | |
47 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 228 times.
|
228 | av_assert0(d->log2_chroma_w <= 3); |
48 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 228 times.
|
228 | av_assert0(d->log2_chroma_h <= 3); |
49 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 228 times.
|
228 | av_assert0(d->nb_components <= 4); |
50 |
3/4✓ Branch 0 taken 14 times.
✓ Branch 1 taken 214 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
|
228 | av_assert0(d->nb_components || (d->flags & AV_PIX_FMT_FLAG_HWACCEL)); |
51 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 228 times.
|
228 | av_assert0(av_get_pix_fmt(d->name) == av_pix_fmt_desc_get_id(d)); |
52 | |||
53 | /* The following two checks as well as the one after the loop | ||
54 | * would need to be changed if we changed the way the descriptors | ||
55 | * are stored. */ | ||
56 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 228 times.
|
228 | av_assert0(i == av_pix_fmt_desc_get_id(d)); |
57 |
3/4✓ Branch 0 taken 227 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 227 times.
|
228 | av_assert0(!last || last + 1 == d); |
58 | |||
59 |
2/2✓ Branch 0 taken 912 times.
✓ Branch 1 taken 228 times.
|
1140 | for (int j = 0; j < FF_ARRAY_ELEMS(d->comp); j++) { |
60 | 912 | const AVComponentDescriptor *c = &d->comp[j]; | |
61 |
2/2✓ Branch 0 taken 254 times.
✓ Branch 1 taken 658 times.
|
912 | if (j >= d->nb_components) { |
62 |
5/10✓ Branch 0 taken 254 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 254 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 254 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 254 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 254 times.
|
254 | av_assert0(!c->plane && !c->step && !c->offset && !c->shift && !c->depth); |
63 | 254 | continue; | |
64 | } | ||
65 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 647 times.
|
658 | if (d->flags & AV_PIX_FMT_FLAG_BITSTREAM) { |
66 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | av_assert0(c->step >= c->depth); |
67 | } else { | ||
68 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 647 times.
|
647 | av_assert0(8*c->step >= c->depth); |
69 | } | ||
70 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 622 times.
|
658 | if (d->flags & AV_PIX_FMT_FLAG_BAYER) |
71 | 36 | continue; | |
72 | 622 | av_read_image_line(tmp, (void*)data, linesize, d, 0, 0, j, 2, 0); | |
73 |
2/4✓ Branch 0 taken 622 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 622 times.
|
622 | av_assert0(tmp[0] == 0 && tmp[1] == 0); |
74 | 622 | tmp[0] = tmp[1] = (1ULL << c->depth) - 1; | |
75 | 622 | av_write_image_line(tmp, data, linesize, d, 0, 0, j, 2); | |
76 | } | ||
77 | 228 | last = d; | |
78 | } | ||
79 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | av_assert0(i == AV_PIX_FMT_NB); |
80 | 1 | } | |
81 | |||
82 | 60 | static int run_single_test(const char *test, | |
83 | const uint8_t *block1, ptrdiff_t stride1, | ||
84 | const uint8_t *block2, ptrdiff_t stride2, | ||
85 | int align, int n) | ||
86 | { | ||
87 | int out, ref; | ||
88 | 60 | av_pixelutils_sad_fn f_ref = sad_c[n - 1]; | |
89 | 60 | av_pixelutils_sad_fn f_out = av_pixelutils_get_sad_fn(n, n, align, NULL); | |
90 | |||
91 |
3/4✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
60 | switch (align) { |
92 | 20 | case 0: block1++; block2++; break; | |
93 | 20 | case 1: block2++; break; | |
94 | 20 | case 2: break; | |
95 | } | ||
96 | |||
97 | 60 | out = f_out(block1, stride1, block2, stride2); | |
98 | 60 | ref = f_ref(block1, stride1, block2, stride2); | |
99 |
5/6✓ Branch 0 taken 20 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 20 times.
✓ Branch 4 taken 60 times.
✗ Branch 5 not taken.
|
60 | printf("[%s] [%c%c] SAD [%s] %dx%d=%d ref=%d\n", |
100 | out == ref ? "OK" : "FAIL", | ||
101 | align ? 'A' : 'U', align == 2 ? 'A' : 'U', | ||
102 | test, 1<<n, 1<<n, out, ref); | ||
103 | 60 | return out != ref; | |
104 | } | ||
105 | |||
106 | 3 | static int run_test(const char *test, | |
107 | const uint8_t *b1, const uint8_t *b2) | ||
108 | { | ||
109 | 3 | int i, a, ret = 0; | |
110 | |||
111 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
|
12 | for (a = 0; a < 3; a++) { |
112 |
2/2✓ Branch 0 taken 45 times.
✓ Branch 1 taken 9 times.
|
54 | for (i = 1; i <= FF_ARRAY_ELEMS(sad_c); i++) { |
113 | 45 | int r = run_single_test(test, b1, W1, b2, W2, a, i); | |
114 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
|
45 | if (r) |
115 | ✗ | ret = r; | |
116 | } | ||
117 | } | ||
118 | 3 | return ret; | |
119 | } | ||
120 | |||
121 | 1 | int main(void) | |
122 | { | ||
123 | int i, align, ret; | ||
124 | 1 | uint8_t *buf1 = av_malloc(W1*H1); | |
125 | 1 | uint8_t *buf2 = av_malloc(W2*H2); | |
126 | 1 | uint32_t state = 0; | |
127 | |||
128 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (!buf1 || !buf2) { |
129 | ✗ | fprintf(stderr, "malloc failure\n"); | |
130 | ✗ | ret = 1; | |
131 | ✗ | goto end; | |
132 | } | ||
133 | |||
134 | 1 | check_pixfmt_descriptors(); | |
135 | |||
136 | #define RANDOM_INIT(buf, size) do { \ | ||
137 | int k; \ | ||
138 | for (k = 0; k < size; k++) { \ | ||
139 | state = state * 1664525 + 1013904223; \ | ||
140 | buf[k] = state>>24; \ | ||
141 | } \ | ||
142 | } while (0) | ||
143 | |||
144 | /* Normal test with different strides */ | ||
145 |
2/2✓ Branch 0 taken 76800 times.
✓ Branch 1 taken 1 times.
|
76801 | RANDOM_INIT(buf1, W1*H1); |
146 |
2/2✓ Branch 0 taken 307200 times.
✓ Branch 1 taken 1 times.
|
307201 | RANDOM_INIT(buf2, W2*H2); |
147 | 1 | ret = run_test("random", buf1, buf2); | |
148 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ret < 0) |
149 | ✗ | goto end; | |
150 | |||
151 | /* Check for maximum SAD */ | ||
152 | 1 | memset(buf1, 0xff, W1*H1); | |
153 | 1 | memset(buf2, 0x00, W2*H2); | |
154 | 1 | ret = run_test("max", buf1, buf2); | |
155 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ret < 0) |
156 | ✗ | goto end; | |
157 | |||
158 | /* Check for minimum SAD */ | ||
159 | 1 | memset(buf1, 0x90, W1*H1); | |
160 | 1 | memset(buf2, 0x90, W2*H2); | |
161 | 1 | ret = run_test("min", buf1, buf2); | |
162 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ret < 0) |
163 | ✗ | goto end; | |
164 | |||
165 | /* Exact buffer sizes, to check for overreads */ | ||
166 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
|
6 | for (i = 1; i <= 5; i++) { |
167 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 5 times.
|
20 | for (align = 0; align < 3; align++) { |
168 | int size1, size2; | ||
169 | |||
170 | 15 | av_freep(&buf1); | |
171 | 15 | av_freep(&buf2); | |
172 | |||
173 | 15 | size1 = size2 = 1 << (i << 1); | |
174 | |||
175 |
3/4✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
15 | switch (align) { |
176 | 5 | case 0: size1++; size2++; break; | |
177 | 5 | case 1: size2++; break; | |
178 | 5 | case 2: break; | |
179 | } | ||
180 | |||
181 | 15 | buf1 = av_malloc(size1); | |
182 | 15 | buf2 = av_malloc(size2); | |
183 |
2/4✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15 times.
|
15 | if (!buf1 || !buf2) { |
184 | ✗ | fprintf(stderr, "malloc failure\n"); | |
185 | ✗ | ret = 1; | |
186 | ✗ | goto end; | |
187 | } | ||
188 |
2/2✓ Branch 0 taken 4097 times.
✓ Branch 1 taken 15 times.
|
4112 | RANDOM_INIT(buf1, size1); |
189 |
2/2✓ Branch 0 taken 4102 times.
✓ Branch 1 taken 15 times.
|
4117 | RANDOM_INIT(buf2, size2); |
190 | 15 | ret = run_single_test("small", buf1, 1<<i, buf2, 1<<i, align, i); | |
191 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
|
15 | if (ret < 0) |
192 | ✗ | goto end; | |
193 | } | ||
194 | } | ||
195 | |||
196 | 1 | end: | |
197 | 1 | av_free(buf1); | |
198 | 1 | av_free(buf2); | |
199 | 1 | return ret; | |
200 | } | ||
201 |