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 | |||
21 | #include "libavutil/common.h" | ||
22 | #include "libavutil/intreadwrite.h" | ||
23 | #include "libavutil/mem.h" | ||
24 | #include "libavutil/mem_internal.h" | ||
25 | |||
26 | #include "libswscale/swscale.h" | ||
27 | #include "libswscale/swscale_internal.h" | ||
28 | |||
29 | #include "checkasm.h" | ||
30 | |||
31 | static const enum AVPixelFormat pixel_formats[] = { | ||
32 | AV_PIX_FMT_YUV444P, | ||
33 | AV_PIX_FMT_YUV444P9, | ||
34 | AV_PIX_FMT_YUV444P10, | ||
35 | AV_PIX_FMT_YUV444P12, | ||
36 | AV_PIX_FMT_YUV444P14, | ||
37 | AV_PIX_FMT_YUV444P16, | ||
38 | }; | ||
39 | |||
40 | 192 | static void randomize_buffers(int16_t *buf0, int16_t *buf1, int bit_depth, int width) | |
41 | { | ||
42 | 192 | int32_t *buf0_32 = (int32_t *) buf0; | |
43 | 192 | int32_t *buf1_32 = (int32_t *) buf1; | |
44 | 192 | int mask = (1 << bit_depth) - 1; | |
45 |
2/2✓ Branch 0 taken 180 times.
✓ Branch 1 taken 12 times.
|
192 | int src_shift = bit_depth <= 14 ? 15 - bit_depth : 19 - bit_depth; |
46 |
2/2✓ Branch 0 taken 185088 times.
✓ Branch 1 taken 192 times.
|
185280 | for (int i = 0; i < width; i++) { |
47 | 185088 | int32_t r = rnd() & mask; | |
48 |
2/2✓ Branch 0 taken 11568 times.
✓ Branch 1 taken 173520 times.
|
185088 | if (bit_depth == 16) { |
49 | 11568 | buf0_32[i] = r << src_shift; | |
50 | 11568 | buf1_32[i] = r << src_shift; | |
51 | } else { | ||
52 | 173520 | buf0[i] = r << src_shift; | |
53 | 173520 | buf1[i] = r << src_shift; | |
54 | } | ||
55 | } | ||
56 | 192 | } | |
57 | |||
58 | 26 | static void check_lumConvertRange(int from) | |
59 | { | ||
60 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 13 times.
|
26 | const char *func_str = from ? "lumRangeFromJpeg" : "lumRangeToJpeg"; |
61 | #define LARGEST_INPUT_SIZE 1920 | ||
62 | static const int input_sizes[] = {8, LARGEST_INPUT_SIZE}; | ||
63 | SwsContext *sws; | ||
64 | SwsInternal *c; | ||
65 | |||
66 | 26 | LOCAL_ALIGNED_32(int16_t, dst0, [LARGEST_INPUT_SIZE * 2]); | |
67 | 26 | LOCAL_ALIGNED_32(int16_t, dst1, [LARGEST_INPUT_SIZE * 2]); | |
68 | |||
69 | 26 | declare_func(void, int16_t *dst, int width); | |
70 | |||
71 | 26 | sws = sws_alloc_context(); | |
72 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
|
26 | if (sws_init_context(sws, NULL, NULL) < 0) |
73 | ✗ | fail(); | |
74 | |||
75 | 26 | c = sws_internal(sws); | |
76 | 26 | c->srcRange = from; | |
77 | 26 | c->dstRange = !from; | |
78 | |||
79 |
2/2✓ Branch 0 taken 156 times.
✓ Branch 1 taken 26 times.
|
182 | for (int pfi = 0; pfi < FF_ARRAY_ELEMS(pixel_formats); pfi++) { |
80 | 156 | enum AVPixelFormat pix_fmt = pixel_formats[pfi]; | |
81 | 156 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
82 | 156 | int bit_depth = desc->comp[0].depth; | |
83 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 130 times.
|
156 | int sample_size = bit_depth == 16 ? sizeof(int32_t) : sizeof(int16_t); |
84 | 156 | c->srcFormat = pix_fmt; | |
85 | 156 | c->dstFormat = pix_fmt; | |
86 | 156 | c->dstBpc = bit_depth; | |
87 | 156 | ff_sws_init_scale(c); | |
88 |
2/2✓ Branch 0 taken 312 times.
✓ Branch 1 taken 156 times.
|
468 | for (int dstWi = 0; dstWi < FF_ARRAY_ELEMS(input_sizes); dstWi++) { |
89 | 312 | int width = input_sizes[dstWi]; | |
90 |
2/2✓ Branch 3 taken 64 times.
✓ Branch 4 taken 248 times.
|
312 | if (check_func(c->lumConvertRange, "%s%d_%d", func_str, bit_depth, width)) { |
91 | 64 | randomize_buffers(dst0, dst1, bit_depth, width); | |
92 | 64 | call_ref(dst0, width); | |
93 | 64 | call_new(dst1, width); | |
94 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
|
64 | if (memcmp(dst0, dst1, width * sample_size)) |
95 | ✗ | fail(); | |
96 |
6/6✓ Branch 0 taken 32 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 26 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 24 times.
|
64 | if (width == LARGEST_INPUT_SIZE && (bit_depth == 8 || bit_depth == 16)) |
97 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 8 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.
|
8 | bench_new(dst1, width); |
98 | } | ||
99 | } | ||
100 | } | ||
101 | |||
102 | 26 | sws_freeContext(sws); | |
103 | 26 | } | |
104 | #undef LARGEST_INPUT_SIZE | ||
105 | |||
106 | 26 | static void check_chrConvertRange(int from) | |
107 | { | ||
108 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 13 times.
|
26 | const char *func_str = from ? "chrRangeFromJpeg" : "chrRangeToJpeg"; |
109 | #define LARGEST_INPUT_SIZE 1920 | ||
110 | static const int input_sizes[] = {8, LARGEST_INPUT_SIZE}; | ||
111 | SwsContext *sws; | ||
112 | SwsInternal *c; | ||
113 | |||
114 | 26 | LOCAL_ALIGNED_32(int16_t, dstU0, [LARGEST_INPUT_SIZE * 2]); | |
115 | 26 | LOCAL_ALIGNED_32(int16_t, dstV0, [LARGEST_INPUT_SIZE * 2]); | |
116 | 26 | LOCAL_ALIGNED_32(int16_t, dstU1, [LARGEST_INPUT_SIZE * 2]); | |
117 | 26 | LOCAL_ALIGNED_32(int16_t, dstV1, [LARGEST_INPUT_SIZE * 2]); | |
118 | |||
119 | 26 | declare_func(void, int16_t *dstU, int16_t *dstV, int width); | |
120 | |||
121 | 26 | sws = sws_alloc_context(); | |
122 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
|
26 | if (sws_init_context(sws, NULL, NULL) < 0) |
123 | ✗ | fail(); | |
124 | |||
125 | 26 | c = sws_internal(sws); | |
126 | 26 | c->srcRange = from; | |
127 | 26 | c->dstRange = !from; | |
128 | |||
129 |
2/2✓ Branch 0 taken 156 times.
✓ Branch 1 taken 26 times.
|
182 | for (int pfi = 0; pfi < FF_ARRAY_ELEMS(pixel_formats); pfi++) { |
130 | 156 | enum AVPixelFormat pix_fmt = pixel_formats[pfi]; | |
131 | 156 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
132 | 156 | int bit_depth = desc->comp[0].depth; | |
133 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 130 times.
|
156 | int sample_size = bit_depth == 16 ? sizeof(int32_t) : sizeof(int16_t); |
134 | 156 | c->srcFormat = pix_fmt; | |
135 | 156 | c->dstFormat = pix_fmt; | |
136 | 156 | c->dstBpc = bit_depth; | |
137 | 156 | ff_sws_init_scale(c); | |
138 |
2/2✓ Branch 0 taken 312 times.
✓ Branch 1 taken 156 times.
|
468 | for (int dstWi = 0; dstWi < FF_ARRAY_ELEMS(input_sizes); dstWi++) { |
139 | 312 | int width = input_sizes[dstWi]; | |
140 |
2/2✓ Branch 3 taken 64 times.
✓ Branch 4 taken 248 times.
|
312 | if (check_func(c->chrConvertRange, "%s%d_%d", func_str, bit_depth, width)) { |
141 | 64 | randomize_buffers(dstU0, dstU1, bit_depth, width); | |
142 | 64 | randomize_buffers(dstV0, dstV1, bit_depth, width); | |
143 | 64 | call_ref(dstU0, dstV0, width); | |
144 | 64 | call_new(dstU1, dstV1, width); | |
145 |
1/2✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
|
64 | if (memcmp(dstU0, dstU1, width * sample_size) || |
146 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
|
64 | memcmp(dstV0, dstV1, width * sample_size)) |
147 | ✗ | fail(); | |
148 |
6/6✓ Branch 0 taken 32 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 26 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 24 times.
|
64 | if (width == LARGEST_INPUT_SIZE && (bit_depth == 8 || bit_depth == 16)) |
149 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 8 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.
|
8 | bench_new(dstU1, dstV1, width); |
150 | } | ||
151 | } | ||
152 | } | ||
153 | |||
154 | 26 | sws_freeContext(sws); | |
155 | 26 | } | |
156 | #undef LARGEST_INPUT_SIZE | ||
157 | |||
158 | 13 | void checkasm_check_sw_range_convert(void) | |
159 | { | ||
160 | 13 | check_lumConvertRange(1); | |
161 | 13 | report("lumRangeFromJpeg"); | |
162 | 13 | check_chrConvertRange(1); | |
163 | 13 | report("chrRangeFromJpeg"); | |
164 | 13 | check_lumConvertRange(0); | |
165 | 13 | report("lumRangeToJpeg"); | |
166 | 13 | check_chrConvertRange(0); | |
167 | 13 | report("chrRangeToJpeg"); | |
168 | 13 | } | |
169 |