Line | Branch | Exec | Source |
---|---|---|---|
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_init.h" | ||
23 | #include "libavutil/avassert.h" | ||
24 | #include "libavutil/mem.h" | ||
25 | |||
26 | #define randomize_buffer(buf, size) do { \ | ||
27 | int i; \ | ||
28 | for (i = 0; i < size / 4; i++) \ | ||
29 | ((uint32_t *)buf)[i] = rnd(); \ | ||
30 | } while (0) | ||
31 | |||
32 | 13 | void checkasm_check_nlmeans(void) | |
33 | { | ||
34 | 13 | NLMeansDSPContext dsp = {0}; | |
35 | |||
36 | 13 | const int w = 123; // source width | |
37 | 13 | const int h = 45; // source height | |
38 | 13 | const int p = 3; // patch half size | |
39 | 13 | const int r = 2; // research window half size | |
40 | |||
41 | 13 | ff_nlmeans_init(&dsp); | |
42 | |||
43 | /* See the filter's code for the explanations on the variables */ | ||
44 |
2/2✓ Branch 3 taken 1 times.
✓ Branch 4 taken 12 times.
|
13 | if (check_func(dsp.compute_safe_ssd_integral_image, "ssd_integral_image")) { |
45 | int offx, offy; | ||
46 | 1 | const int e = p + r; | |
47 | 1 | const int ii_w = w + e*2; | |
48 | 1 | const int ii_h = h + e*2; | |
49 | 1 | const int ii_lz_32 = FFALIGN(ii_w + 1, 4); | |
50 | 1 | uint32_t *ii_orig_ref = av_calloc(ii_h + 1, ii_lz_32 * sizeof(*ii_orig_ref)); | |
51 | 1 | uint32_t *ii_ref = ii_orig_ref + ii_lz_32 + 1; | |
52 | 1 | uint32_t *ii_orig_new = av_calloc(ii_h + 1, ii_lz_32 * sizeof(*ii_orig_new)); | |
53 | 1 | uint32_t *ii_new = ii_orig_new + ii_lz_32 + 1; | |
54 | 1 | const int src_lz = FFALIGN(w, 16); | |
55 | 1 | uint8_t *src = av_calloc(h, src_lz); | |
56 | |||
57 | 1 | declare_func(void, uint32_t *dst, ptrdiff_t dst_linesize_32, | |
58 | const uint8_t *s1, ptrdiff_t linesize1, | ||
59 | const uint8_t *s2, ptrdiff_t linesize2, | ||
60 | int w, int h); | ||
61 | |||
62 |
2/2✓ Branch 1 taken 1440 times.
✓ Branch 2 taken 1 times.
|
1441 | randomize_buffer(src, h * src_lz); |
63 | |||
64 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
|
6 | for (offy = -r; offy <= r; offy++) { |
65 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 5 times.
|
30 | for (offx = -r; offx <= r; offx++) { |
66 |
4/4✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 1 times.
|
25 | if (offx || offy) { |
67 | 24 | const int s1x = e; | |
68 | 24 | const int s1y = e; | |
69 | 24 | const int s2x = e + offx; | |
70 | 24 | const int s2y = e + offy; | |
71 | 24 | const int startx_safe = FFMAX(s1x, s2x); | |
72 | 24 | const int starty_safe = FFMAX(s1y, s2y); | |
73 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 14 times.
|
24 | const int u_endx_safe = FFMIN(s1x + w, s2x + w); |
74 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 14 times.
|
24 | const int endy_safe = FFMIN(s1y + h, s2y + h); |
75 | 24 | const int safe_pw = (u_endx_safe - startx_safe) & ~0xf; | |
76 | 24 | const int safe_ph = endy_safe - starty_safe; | |
77 | |||
78 |
2/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
|
24 | av_assert0(safe_pw && safe_ph); |
79 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 24 times.
|
24 | av_assert0(startx_safe - s1x >= 0); av_assert0(startx_safe - s1x < w); |
80 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 24 times.
|
24 | av_assert0(starty_safe - s1y >= 0); av_assert0(starty_safe - s1y < h); |
81 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 24 times.
|
24 | av_assert0(startx_safe - s2x >= 0); av_assert0(startx_safe - s2x < w); |
82 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 24 times.
|
24 | av_assert0(starty_safe - s2y >= 0); av_assert0(starty_safe - s2y < h); |
83 | |||
84 | 24 | memset(ii_ref, 0, (ii_lz_32 * ii_h - 1) * sizeof(*ii_ref)); | |
85 | 24 | memset(ii_new, 0, (ii_lz_32 * ii_h - 1) * sizeof(*ii_new)); | |
86 | |||
87 | 24 | call_ref(ii_ref + starty_safe*ii_lz_32 + startx_safe, ii_lz_32, | |
88 | src + (starty_safe - s1y) * src_lz + (startx_safe - s1x), src_lz, | ||
89 | src + (starty_safe - s2y) * src_lz + (startx_safe - s2x), src_lz, | ||
90 | safe_pw, safe_ph); | ||
91 | 24 | call_new(ii_new + starty_safe*ii_lz_32 + startx_safe, ii_lz_32, | |
92 | src + (starty_safe - s1y) * src_lz + (startx_safe - s1x), src_lz, | ||
93 | src + (starty_safe - s2y) * src_lz + (startx_safe - s2x), src_lz, | ||
94 | safe_pw, safe_ph); | ||
95 | |||
96 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | if (memcmp(ii_ref, ii_new, (ii_lz_32 * ii_h - 1) * sizeof(*ii_ref))) |
97 | ✗ | fail(); | |
98 | |||
99 | 24 | memset(ii_new, 0, (ii_lz_32 * ii_h - 1) * sizeof(*ii_new)); | |
100 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
|
24 | bench_new(ii_new + starty_safe*ii_lz_32 + startx_safe, ii_lz_32, |
101 | src + (starty_safe - s1y) * src_lz + (startx_safe - s1x), src_lz, | ||
102 | src + (starty_safe - s2y) * src_lz + (startx_safe - s2x), src_lz, | ||
103 | safe_pw, safe_ph); | ||
104 | } | ||
105 | } | ||
106 | } | ||
107 | |||
108 | 1 | av_freep(&ii_orig_ref); | |
109 | 1 | av_freep(&ii_orig_new); | |
110 | 1 | av_freep(&src); | |
111 | } | ||
112 | |||
113 | 13 | report("dsp"); | |
114 | 13 | } | |
115 |