| 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, 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 3 taken 4 times.
✓ Branch 4 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 | 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/8✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
|
4 | bench_new(in, STRIDE, w, HEIGHT, mpeg_min, mpeg_max); |
| 69 | } | ||
| 70 | 28 | } | |
| 71 | |||
| 72 | 56 | static void check_alpha_detect(int depth, enum AVColorRange range) | |
| 73 | { | ||
| 74 | 56 | const int mpeg_min = 16 << (depth - 8); | |
| 75 | 56 | const int mpeg_max = 235 << (depth - 8); | |
| 76 | 56 | const int alpha_max = (1 << depth) - 1; | |
| 77 | 56 | const int mpeg_range = mpeg_max - mpeg_min; | |
| 78 | 56 | const int offset = alpha_max * mpeg_min + (1 << (depth - 1)); | |
| 79 | int res_ref, res_new; | ||
| 80 | |||
| 81 | 56 | FFColorDetectDSPContext dsp = {0}; | |
| 82 | 56 | ff_color_detect_dsp_init(&dsp, depth, range); | |
| 83 | |||
| 84 | 56 | declare_func(int, const uint8_t *, ptrdiff_t, const uint8_t *, ptrdiff_t, | |
| 85 | ptrdiff_t, ptrdiff_t, int p, int q, int k); | ||
| 86 | |||
| 87 | 56 | LOCAL_ALIGNED_32(uint8_t, luma, [HEIGHT * STRIDE]); | |
| 88 | 56 | LOCAL_ALIGNED_32(uint8_t, alpha, [HEIGHT * STRIDE]); | |
| 89 | 56 | memset(luma, 0x80, HEIGHT * STRIDE); | |
| 90 | 56 | memset(alpha, 0xF0, HEIGHT * STRIDE); | |
| 91 | |||
| 92 | /* Try and force overflow */ | ||
| 93 |
4/4✓ Branch 0 taken 28 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 14 times.
|
56 | if (depth > 8 && range == AVCOL_RANGE_MPEG) { |
| 94 | 14 | ((uint16_t *) luma)[0] = 235 << (depth - 8); | |
| 95 | 14 | ((uint16_t *) luma)[1] = 16 << (depth - 8); | |
| 96 | } else { | ||
| 97 | 42 | luma[0] = 235; | |
| 98 | 42 | luma[1] = 16; | |
| 99 | } | ||
| 100 | |||
| 101 | /* Place an out-of-range value in a random position near the center */ | ||
| 102 | 56 | const int h2 = HEIGHT >> 1; | |
| 103 | 56 | int idx0 = ((rnd() % h2) + h2) * STRIDE + (rnd() % WIDTH); | |
| 104 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 28 times.
|
56 | if (depth > 8) { |
| 105 | 28 | idx0 &= ~1; | |
| 106 | 28 | alpha[idx0] = alpha[idx0 + 1] = 0; | |
| 107 | } else { | ||
| 108 | 28 | alpha[idx0] = 0; | |
| 109 | } | ||
| 110 | |||
| 111 | 56 | int w = WIDTH; | |
| 112 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 28 times.
|
56 | if (depth > 8) |
| 113 | 28 | w /= 2; | |
| 114 | |||
| 115 |
4/4✓ Branch 2 taken 28 times.
✓ Branch 3 taken 28 times.
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 48 times.
|
56 | if (check_func(dsp.detect_alpha, "detect_alpha_%d_%s", depth, range == AVCOL_RANGE_JPEG ? "full" : "limited")) { |
| 116 | /* Test increasing height, to ensure we hit the placed 0 eventually */ | ||
| 117 |
2/2✓ Branch 0 taken 128 times.
✓ Branch 1 taken 8 times.
|
136 | for (int h = 1; h <= HEIGHT; h++) { |
| 118 | 128 | res_ref = call_ref(luma, STRIDE, alpha, STRIDE, w, h, alpha_max, mpeg_range, offset); | |
| 119 | 128 | res_new = call_new(luma, STRIDE, alpha, STRIDE, w, h, alpha_max, mpeg_range, offset); | |
| 120 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 128 times.
|
128 | if (res_ref != res_new) |
| 121 | ✗ | fail(); | |
| 122 | } | ||
| 123 | |||
| 124 | /* Test base case without any out-of-range values */ | ||
| 125 | 8 | memset(alpha, 0xFF, HEIGHT * STRIDE); | |
| 126 | 8 | res_ref = call_ref(luma, STRIDE, alpha, STRIDE, w, HEIGHT, alpha_max, mpeg_range, offset); | |
| 127 | 8 | res_new = call_new(luma, STRIDE, alpha, STRIDE, w, HEIGHT, alpha_max, mpeg_range, offset); | |
| 128 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (res_ref != res_new) |
| 129 | ✗ | fail(); | |
| 130 | |||
| 131 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
|
8 | bench_new(luma, STRIDE, alpha, STRIDE, w, HEIGHT, alpha_max, mpeg_range, offset); |
| 132 | } | ||
| 133 | 56 | } | |
| 134 | |||
| 135 | 14 | void checkasm_check_colordetect(void) | |
| 136 | { | ||
| 137 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 14 times.
|
42 | for (int depth = 8; depth <= 16; depth += 8) { |
| 138 | 28 | check_range_detect(depth); | |
| 139 | 28 | report("detect_range_%d", depth); | |
| 140 | |||
| 141 | 28 | check_alpha_detect(depth, AVCOL_RANGE_JPEG); | |
| 142 | 28 | check_alpha_detect(depth, AVCOL_RANGE_MPEG); | |
| 143 | 28 | report("detect_alpha_%d", depth); | |
| 144 | } | ||
| 145 | 14 | } | |
| 146 |