| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of FFmpeg. | ||
| 3 | * | ||
| 4 | * FFmpeg is free software; you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation; either version 2 of the License, or | ||
| 7 | * (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 | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License along | ||
| 15 | * with FFmpeg; if not, write to the Free Software Foundation, Inc., | ||
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <string.h> | ||
| 20 | #include "checkasm.h" | ||
| 21 | |||
| 22 | #include "libavfilter/vf_colordetectdsp.h" | ||
| 23 | #include "libavutil/mem_internal.h" | ||
| 24 | |||
| 25 | #define WIDTH 540 | ||
| 26 | #define HEIGHT 16 | ||
| 27 | #define STRIDE FFALIGN(WIDTH, 32) | ||
| 28 | |||
| 29 | 28 | static void check_range_detect(int depth) | |
| 30 | { | ||
| 31 | 28 | const int mpeg_min = 16 << (depth - 8); | |
| 32 | 28 | const int mpeg_max = 235 << (depth - 8); | |
| 33 | |||
| 34 | 28 | FFColorDetectDSPContext dsp = {0}; | |
| 35 | 28 | ff_color_detect_dsp_init(&dsp, depth, 0, AVCOL_RANGE_UNSPECIFIED); | |
| 36 | |||
| 37 | 28 | declare_func(int, const uint8_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t, int, int); | |
| 38 | |||
| 39 | /* Initialize to 128, which should always return 0 */ | ||
| 40 | 28 | LOCAL_ALIGNED_32(uint8_t, in, [HEIGHT * STRIDE]); | |
| 41 | 28 | memset(in, 0x80, HEIGHT * STRIDE); | |
| 42 | |||
| 43 | /* Place an out-of-range value in a random position near the center */ | ||
| 44 | 28 | const int h2 = HEIGHT >> 1; | |
| 45 | 28 | int idx0 = ((rnd() % h2) + h2) * STRIDE + (rnd() % WIDTH); | |
| 46 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 14 times.
|
28 | if (depth > 8) { |
| 47 | 14 | idx0 &= ~1; | |
| 48 | 14 | in[idx0] = in[idx0 + 1] = 0; | |
| 49 | } else { | ||
| 50 | 14 | in[idx0] = 0; | |
| 51 | } | ||
| 52 | |||
| 53 | 28 | int w = WIDTH; | |
| 54 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 14 times.
|
28 | if (depth > 8) |
| 55 | 14 | w /= 2; | |
| 56 | |||
| 57 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 24 times.
|
28 | if (check_func(dsp.detect_range, "detect_range_%d", depth)) { |
| 58 | /* Test increasing height, to ensure we hit the placed 0 eventually */ | ||
| 59 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 4 times.
|
68 | for (int h = 1; h <= HEIGHT; h++) { |
| 60 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 64 times.
|
64 | int res_ref = call_ref(in, STRIDE, w, h, mpeg_min, mpeg_max); |
| 61 | 64 | int res_new = call_new(in, STRIDE, w, h, mpeg_min, mpeg_max); | |
| 62 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
|
64 | if (res_ref != res_new) |
| 63 | ✗ | fail(); | |
| 64 | } | ||
| 65 | |||
| 66 | /* Test performance of base case without any out-of-range values */ | ||
| 67 | 4 | memset(in, 0x80, HEIGHT * STRIDE); | |
| 68 |
1/18✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
|
4 | bench_new(in, STRIDE, (w & ~31), HEIGHT, mpeg_min, mpeg_max); |
| 69 | } | ||
| 70 | 28 | } | |
| 71 | |||
| 72 | 84 | static void check_alpha_detect(int depth, enum AVColorRange range, int offset) | |
| 73 | { | ||
| 74 | 84 | const int mpeg_min = 16 << (depth - 8); | |
| 75 | 84 | const int mpeg_max = 235 << (depth - 8); | |
| 76 | 84 | const int alpha_max = (1 << depth) - 1; | |
| 77 | 84 | const int mpeg_range = mpeg_max - mpeg_min; | |
| 78 | int res_ref, res_new; | ||
| 79 | |||
| 80 | 84 | int threshold = checkasm_rand() % FFMIN(HEIGHT, mpeg_min); | |
| 81 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 28 times.
|
84 | if (range == AVCOL_RANGE_JPEG) { |
| 82 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 28 times.
|
56 | offset = offset ? FFMAX(threshold, 1) : 0; |
| 83 | } else { | ||
| 84 | 28 | offset = alpha_max * (mpeg_min + threshold) + (1 << (depth - 1)); | |
| 85 | } | ||
| 86 | |||
| 87 | 84 | FFColorDetectDSPContext dsp = {0}; | |
| 88 | 84 | ff_color_detect_dsp_init(&dsp, depth, offset, range); | |
| 89 | |||
| 90 | 84 | declare_func(int, const uint8_t *, ptrdiff_t, const uint8_t *, ptrdiff_t, | |
| 91 | ptrdiff_t, ptrdiff_t, int p, int q, int k); | ||
| 92 | |||
| 93 | 84 | LOCAL_ALIGNED_32(uint8_t, luma, [HEIGHT * STRIDE]); | |
| 94 | 84 | LOCAL_ALIGNED_32(uint8_t, alpha, [HEIGHT * STRIDE]); | |
| 95 | 84 | memset(luma, 0x80, HEIGHT * STRIDE); | |
| 96 | 84 | memset(alpha, 0xF0, HEIGHT * STRIDE); | |
| 97 | |||
| 98 | /* Try and force overflow and edge cases */ | ||
| 99 |
4/4✓ Branch 0 taken 42 times.
✓ Branch 1 taken 42 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 28 times.
|
84 | if (depth > 8 && range == AVCOL_RANGE_MPEG) { |
| 100 |
2/2✓ Branch 0 taken 184 times.
✓ Branch 1 taken 14 times.
|
198 | for (int i = 0; i < threshold; i++) { |
| 101 | 184 | uint16_t *line = (uint16_t *) (luma + i * STRIDE); | |
| 102 | 184 | line[0] = (235 << (depth - 8)) + i; | |
| 103 | 184 | line[1] = ( 16 << (depth - 8)) - i; | |
| 104 | } | ||
| 105 | } else { | ||
| 106 |
2/2✓ Branch 0 taken 296 times.
✓ Branch 1 taken 70 times.
|
366 | for (int i = 0; i < threshold; i++) { |
| 107 | 296 | uint8_t *line = luma + i * STRIDE; | |
| 108 | 296 | line[0] = 235 + i; | |
| 109 | 296 | line[1] = 16 - i; | |
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | /* Place an out-of-range value in a random position near the center */ | ||
| 114 | 84 | const int h2 = HEIGHT >> 1; | |
| 115 | 84 | int idx0 = ((rnd() % h2) + h2) * STRIDE + (rnd() % WIDTH); | |
| 116 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 42 times.
|
84 | if (depth > 8) { |
| 117 | 42 | idx0 &= ~1; | |
| 118 | 42 | alpha[idx0] = alpha[idx0 + 1] = 0; | |
| 119 | } else { | ||
| 120 | 42 | alpha[idx0] = 0; | |
| 121 | } | ||
| 122 | |||
| 123 | 84 | int w = WIDTH; | |
| 124 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 42 times.
|
84 | if (depth > 8) |
| 125 | 42 | w /= 2; | |
| 126 | |||
| 127 | const char *name; | ||
| 128 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 28 times.
|
84 | if (range == AVCOL_RANGE_JPEG) |
| 129 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 28 times.
|
56 | name = offset ? "full_off" : "full"; |
| 130 | else | ||
| 131 | 28 | name = "limited"; | |
| 132 | |||
| 133 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 2 taken 72 times.
|
84 | if (check_func(dsp.detect_alpha, "detect_alpha_%d_%s", depth, name)) { |
| 134 | /* Test increasing height, to ensure we hit the placed 0 eventually */ | ||
| 135 |
2/2✓ Branch 0 taken 192 times.
✓ Branch 1 taken 12 times.
|
204 | for (int h = 1; h <= HEIGHT; h++) { |
| 136 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 192 times.
|
192 | res_ref = call_ref(luma, STRIDE, alpha, STRIDE, w, h, alpha_max, mpeg_range, offset); |
| 137 | 192 | res_new = call_new(luma, STRIDE, alpha, STRIDE, w, h, alpha_max, mpeg_range, offset); | |
| 138 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 192 times.
|
192 | if (res_ref != res_new) |
| 139 | ✗ | fail(); | |
| 140 | } | ||
| 141 | |||
| 142 | /* Test base case without any out-of-range values */ | ||
| 143 | 12 | memset(alpha, 0xFF, HEIGHT * STRIDE); | |
| 144 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
|
12 | res_ref = call_ref(luma, STRIDE, alpha, STRIDE, w, HEIGHT, alpha_max, mpeg_range, offset); |
| 145 | 12 | res_new = call_new(luma, STRIDE, alpha, STRIDE, w, HEIGHT, alpha_max, mpeg_range, offset); | |
| 146 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if (res_ref != res_new) |
| 147 | ✗ | fail(); | |
| 148 | |||
| 149 |
1/18✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
|
12 | bench_new(luma, STRIDE, alpha, STRIDE, (w & ~31), HEIGHT, alpha_max, mpeg_range, offset); |
| 150 | } | ||
| 151 | 84 | } | |
| 152 | |||
| 153 | 14 | void checkasm_check_colordetect(void) | |
| 154 | { | ||
| 155 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 14 times.
|
42 | for (int depth = 8; depth <= 16; depth += 8) { |
| 156 | 28 | check_range_detect(depth); | |
| 157 | 28 | report("detect_range_%d", depth); | |
| 158 | |||
| 159 | 28 | check_alpha_detect(depth, AVCOL_RANGE_JPEG, 0); | |
| 160 | 28 | check_alpha_detect(depth, AVCOL_RANGE_JPEG, 1); | |
| 161 | 28 | check_alpha_detect(depth, AVCOL_RANGE_MPEG, 1); | |
| 162 | 28 | report("detect_alpha_%d", depth); | |
| 163 | } | ||
| 164 | 14 | } | |
| 165 |