| 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 | 216 | static void randomize_buffers(int16_t *buf0, int16_t *buf1, int bit_depth, int width) | |
| 41 | { | ||
| 42 | 216 | int32_t *buf0_32 = (int32_t *) buf0; | |
| 43 | 216 | int32_t *buf1_32 = (int32_t *) buf1; | |
| 44 | 216 | int mask = (1 << bit_depth) - 1; | |
| 45 |
2/2✓ Branch 0 taken 180 times.
✓ Branch 1 taken 36 times.
|
216 | int src_shift = bit_depth <= 14 ? 15 - bit_depth : 19 - bit_depth; |
| 46 |
2/2✓ Branch 0 taken 208224 times.
✓ Branch 1 taken 216 times.
|
208440 | for (int i = 0; i < width; i++) { |
| 47 | 208224 | int32_t r = rnd() & mask; | |
| 48 |
2/2✓ Branch 0 taken 34704 times.
✓ Branch 1 taken 173520 times.
|
208224 | if (bit_depth == 16) { |
| 49 | 34704 | buf0_32[i] = r << src_shift; | |
| 50 | 34704 | 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 | 216 | } | |
| 57 | |||
| 58 | 28 | static void check_lumConvertRange(int from) | |
| 59 | { | ||
| 60 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 14 times.
|
28 | 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 | 28 | LOCAL_ALIGNED_32(int16_t, dst0, [LARGEST_INPUT_SIZE * 2]); | |
| 67 | 28 | LOCAL_ALIGNED_32(int16_t, dst1, [LARGEST_INPUT_SIZE * 2]); | |
| 68 | 28 | int32_t *dst0_32 = (int32_t *) dst0; | |
| 69 | 28 | int32_t *dst1_32 = (int32_t *) dst1; | |
| 70 | |||
| 71 | 28 | declare_func(void, int16_t *dst, int width, | |
| 72 | uint32_t coeff, int64_t offset); | ||
| 73 | |||
| 74 | 28 | sws = sws_alloc_context(); | |
| 75 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
|
28 | if (sws_init_context(sws, NULL, NULL) < 0) |
| 76 | ✗ | fail(); | |
| 77 | |||
| 78 | 28 | c = sws_internal(sws); | |
| 79 | 28 | sws->src_range = from; | |
| 80 | 28 | sws->dst_range = !from; | |
| 81 | |||
| 82 |
2/2✓ Branch 0 taken 168 times.
✓ Branch 1 taken 28 times.
|
196 | for (int pfi = 0; pfi < FF_ARRAY_ELEMS(pixel_formats); pfi++) { |
| 83 | 168 | enum AVPixelFormat pix_fmt = pixel_formats[pfi]; | |
| 84 | 168 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 85 | 168 | int bit_depth = desc->comp[0].depth; | |
| 86 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 140 times.
|
168 | int sample_size = bit_depth == 16 ? sizeof(int32_t) : sizeof(int16_t); |
| 87 |
2/2✓ Branch 0 taken 140 times.
✓ Branch 1 taken 28 times.
|
168 | int src_shift = bit_depth <= 14 ? 15 - bit_depth : 19 - bit_depth; |
| 88 | 168 | int mpeg_min = 16 << (bit_depth - 8); | |
| 89 | 168 | int mpeg_max = 235 << (bit_depth - 8); | |
| 90 | 168 | int jpeg_max = (1 << bit_depth) - 1; | |
| 91 | 168 | sws->src_format = pix_fmt; | |
| 92 | 168 | sws->dst_format = pix_fmt; | |
| 93 | 168 | c->dstBpc = bit_depth; | |
| 94 | 168 | ff_sws_init_scale(c); | |
| 95 |
2/2✓ Branch 0 taken 336 times.
✓ Branch 1 taken 168 times.
|
504 | for (int dstWi = 0; dstWi < FF_ARRAY_ELEMS(input_sizes); dstWi++) { |
| 96 | 336 | int width = input_sizes[dstWi]; | |
| 97 |
2/2✓ Branch 3 taken 72 times.
✓ Branch 4 taken 264 times.
|
336 | if (check_func(c->lumConvertRange, "%s%d_%d", func_str, bit_depth, width)) { |
| 98 | 72 | randomize_buffers(dst0, dst1, bit_depth, width); | |
| 99 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 60 times.
|
72 | if (bit_depth == 16) { |
| 100 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (!from) { |
| 101 | 6 | dst1_32[0] = dst0_32[0] = mpeg_min << src_shift; | |
| 102 | 6 | dst1_32[1] = dst0_32[1] = mpeg_max << src_shift; | |
| 103 | } | ||
| 104 | 12 | dst1_32[2] = dst0_32[2] = -1; | |
| 105 | } else { | ||
| 106 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 30 times.
|
60 | if (!from) { |
| 107 | 30 | dst1[0] = dst0[0] = mpeg_min << src_shift; | |
| 108 | 30 | dst1[1] = dst0[1] = mpeg_max << src_shift; | |
| 109 | } | ||
| 110 | 60 | dst1[2] = dst0[2] = -1; | |
| 111 | } | ||
| 112 | 72 | call_ref(dst0, width, | |
| 113 | c->lumConvertRange_coeff, c->lumConvertRange_offset); | ||
| 114 | 72 | call_new(dst1, width, | |
| 115 | c->lumConvertRange_coeff, c->lumConvertRange_offset); | ||
| 116 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
|
72 | if (memcmp(dst0, dst1, width * sample_size)) |
| 117 | ✗ | fail(); | |
| 118 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
|
72 | if (!from) { |
| 119 | /* check that the mpeg range is respected */ | ||
| 120 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 30 times.
|
36 | if (bit_depth == 16) { |
| 121 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
|
6 | if ((dst1_32[0] >> src_shift) > 0 || (dst1_32[1] >> src_shift) != jpeg_max) |
| 122 | ✗ | fail(); | |
| 123 | } else { | ||
| 124 |
2/4✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 30 times.
|
30 | if ((dst1[0] >> src_shift) > 0 || (dst1[1] >> src_shift) != jpeg_max) |
| 125 | ✗ | fail(); | |
| 126 | } | ||
| 127 | } | ||
| 128 |
6/6✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 24 times.
|
72 | if (width == LARGEST_INPUT_SIZE && (bit_depth == 8 || bit_depth == 16)) |
| 129 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 12 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.
|
12 | bench_new(dst1, width, |
| 130 | c->lumConvertRange_coeff, c->lumConvertRange_offset); | ||
| 131 | } | ||
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 135 | 28 | sws_freeContext(sws); | |
| 136 | 28 | } | |
| 137 | #undef LARGEST_INPUT_SIZE | ||
| 138 | |||
| 139 | 28 | static void check_chrConvertRange(int from) | |
| 140 | { | ||
| 141 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 14 times.
|
28 | const char *func_str = from ? "chrRangeFromJpeg" : "chrRangeToJpeg"; |
| 142 | #define LARGEST_INPUT_SIZE 1920 | ||
| 143 | static const int input_sizes[] = {8, LARGEST_INPUT_SIZE}; | ||
| 144 | SwsContext *sws; | ||
| 145 | SwsInternal *c; | ||
| 146 | |||
| 147 | 28 | LOCAL_ALIGNED_32(int16_t, dstU0, [LARGEST_INPUT_SIZE * 2]); | |
| 148 | 28 | LOCAL_ALIGNED_32(int16_t, dstV0, [LARGEST_INPUT_SIZE * 2]); | |
| 149 | 28 | LOCAL_ALIGNED_32(int16_t, dstU1, [LARGEST_INPUT_SIZE * 2]); | |
| 150 | 28 | LOCAL_ALIGNED_32(int16_t, dstV1, [LARGEST_INPUT_SIZE * 2]); | |
| 151 | 28 | int32_t *dstU0_32 = (int32_t *) dstU0; | |
| 152 | 28 | int32_t *dstU1_32 = (int32_t *) dstU1; | |
| 153 | |||
| 154 | 28 | declare_func(void, int16_t *dstU, int16_t *dstV, int width, | |
| 155 | uint32_t coeff, int64_t offset); | ||
| 156 | |||
| 157 | 28 | sws = sws_alloc_context(); | |
| 158 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
|
28 | if (sws_init_context(sws, NULL, NULL) < 0) |
| 159 | ✗ | fail(); | |
| 160 | |||
| 161 | 28 | c = sws_internal(sws); | |
| 162 | 28 | sws->src_range = from; | |
| 163 | 28 | sws->dst_range = !from; | |
| 164 | |||
| 165 |
2/2✓ Branch 0 taken 168 times.
✓ Branch 1 taken 28 times.
|
196 | for (int pfi = 0; pfi < FF_ARRAY_ELEMS(pixel_formats); pfi++) { |
| 166 | 168 | enum AVPixelFormat pix_fmt = pixel_formats[pfi]; | |
| 167 | 168 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 168 | 168 | int bit_depth = desc->comp[0].depth; | |
| 169 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 140 times.
|
168 | int sample_size = bit_depth == 16 ? sizeof(int32_t) : sizeof(int16_t); |
| 170 |
2/2✓ Branch 0 taken 140 times.
✓ Branch 1 taken 28 times.
|
168 | int src_shift = bit_depth <= 14 ? 15 - bit_depth : 19 - bit_depth; |
| 171 | 168 | int mpeg_min = 16 << (bit_depth - 8); | |
| 172 | 168 | int mpeg_max = 240 << (bit_depth - 8); | |
| 173 | 168 | int jpeg_max = (1 << bit_depth) - 1; | |
| 174 | 168 | sws->src_format = pix_fmt; | |
| 175 | 168 | sws->dst_format = pix_fmt; | |
| 176 | 168 | c->dstBpc = bit_depth; | |
| 177 | 168 | ff_sws_init_scale(c); | |
| 178 |
2/2✓ Branch 0 taken 336 times.
✓ Branch 1 taken 168 times.
|
504 | for (int dstWi = 0; dstWi < FF_ARRAY_ELEMS(input_sizes); dstWi++) { |
| 179 | 336 | int width = input_sizes[dstWi]; | |
| 180 |
2/2✓ Branch 3 taken 72 times.
✓ Branch 4 taken 264 times.
|
336 | if (check_func(c->chrConvertRange, "%s%d_%d", func_str, bit_depth, width)) { |
| 181 | 72 | randomize_buffers(dstU0, dstU1, bit_depth, width); | |
| 182 | 72 | randomize_buffers(dstV0, dstV1, bit_depth, width); | |
| 183 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 60 times.
|
72 | if (bit_depth == 16) { |
| 184 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (!from) { |
| 185 | 6 | dstU1_32[0] = dstU0_32[0] = mpeg_min << src_shift; | |
| 186 | 6 | dstU1_32[1] = dstU0_32[1] = mpeg_max << src_shift; | |
| 187 | } | ||
| 188 | 12 | dstU1_32[2] = dstU0_32[2] = -1; | |
| 189 | } else { | ||
| 190 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 30 times.
|
60 | if (!from) { |
| 191 | 30 | dstU1[0] = dstU0[0] = mpeg_min << src_shift; | |
| 192 | 30 | dstU1[1] = dstU0[1] = mpeg_max << src_shift; | |
| 193 | } | ||
| 194 | 60 | dstU1[2] = dstU0[2] = -1; | |
| 195 | } | ||
| 196 | 72 | call_ref(dstU0, dstV0, width, | |
| 197 | c->chrConvertRange_coeff, c->chrConvertRange_offset); | ||
| 198 | 72 | call_new(dstU1, dstV1, width, | |
| 199 | c->chrConvertRange_coeff, c->chrConvertRange_offset); | ||
| 200 |
1/2✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
|
72 | if (memcmp(dstU0, dstU1, width * sample_size) || |
| 201 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
|
72 | memcmp(dstV0, dstV1, width * sample_size)) |
| 202 | ✗ | fail(); | |
| 203 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
|
72 | if (!from) { |
| 204 | /* check that the mpeg range is respected */ | ||
| 205 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 30 times.
|
36 | if (bit_depth == 16) { |
| 206 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
|
6 | if ((dstU1_32[0] >> src_shift) > 0 || (dstU1_32[1] >> src_shift) != jpeg_max) |
| 207 | ✗ | fail(); | |
| 208 | } else { | ||
| 209 |
2/4✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 30 times.
|
30 | if ((dstU1[0] >> src_shift) > 0 || (dstU1[1] >> src_shift) != jpeg_max) |
| 210 | ✗ | fail(); | |
| 211 | } | ||
| 212 | } | ||
| 213 |
6/6✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 24 times.
|
72 | if (width == LARGEST_INPUT_SIZE && (bit_depth == 8 || bit_depth == 16)) |
| 214 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 12 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.
|
12 | bench_new(dstU1, dstV1, width, |
| 215 | c->chrConvertRange_coeff, c->chrConvertRange_offset); | ||
| 216 | } | ||
| 217 | } | ||
| 218 | } | ||
| 219 | |||
| 220 | 28 | sws_freeContext(sws); | |
| 221 | 28 | } | |
| 222 | #undef LARGEST_INPUT_SIZE | ||
| 223 | |||
| 224 | 14 | void checkasm_check_sw_range_convert(void) | |
| 225 | { | ||
| 226 | 14 | check_lumConvertRange(1); | |
| 227 | 14 | report("lumRangeFromJpeg"); | |
| 228 | 14 | check_chrConvertRange(1); | |
| 229 | 14 | report("chrRangeFromJpeg"); | |
| 230 | 14 | check_lumConvertRange(0); | |
| 231 | 14 | report("lumRangeToJpeg"); | |
| 232 | 14 | check_chrConvertRange(0); | |
| 233 | 14 | report("chrRangeToJpeg"); | |
| 234 | 14 | } | |
| 235 |