FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libswscale/tests/range_convert.c
Date: 2026-10-29 07:45:57
Exec Total Coverage
Lines: 40 41 97.6%
Functions: 1 1 100.0%
Branches: 31 32 96.9%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (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 GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <stdio.h>
20
21 #include "libavutil/common.h"
22 #include "libavutil/cpu.h"
23 #include "libavutil/mem_internal.h"
24 #include "libavutil/pixdesc.h"
25 #include "libswscale/swscale_internal.h"
26
27 1 int main(void)
28 {
29 static const enum AVPixelFormat formats[] = {
30 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV444P9,
31 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV444P12,
32 AV_PIX_FMT_YUV444P14, AV_PIX_FMT_YUV444P16,
33 };
34 1 const int cpu_flags = av_get_cpu_flags();
35 1 SwsContext *sws = sws_alloc_context();
36 SwsInternal *c;
37
38
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!sws)
39 ✗ return 1;
40 1 c = sws_internal(sws);
41
42
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (int native = 0; native < 2; native++) {
43
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 av_force_cpu_flags(native ? cpu_flags : 0);
44
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2 times.
14 for (int p = 0; p < FF_ARRAY_ELEMS(formats); p++) {
45 12 const int depth = av_pix_fmt_desc_get(formats[p])->comp[0].depth;
46
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
12 const int shift = (depth <= 14 ? 15 : 19) - depth;
47 12 const int center = 128 << (depth - 8);
48 12 const int samples[] = {
49 12 0, 16 << (depth - 8), center - 1, center,
50 12 center + 1, 235 << (depth - 8), 240 << (depth - 8),
51 12 (1 << depth) - 1,
52 };
53 DECLARE_ALIGNED(32, int16_t, u16)[16];
54 DECLARE_ALIGNED(32, int16_t, v16)[16];
55 DECLARE_ALIGNED(32, int32_t, u32)[16];
56 DECLARE_ALIGNED(32, int32_t, v32)[16];
57
58 12 sws->src_format = sws->dst_format = formats[p];
59 12 c->dstBpc = depth;
60
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
36 for (int from = 0; from < 2; from++) {
61 24 sws->src_range = from;
62 24 sws->dst_range = !from;
63 24 ff_sws_init_range_convert(c);
64
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 24 times.
408 for (int i = 0; i < 16; i++) {
65 384 const int u = samples[i % 8] << shift;
66 384 const int v = samples[7 - i % 8] << shift;
67
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 320 times.
384 if (depth == 16) {
68 64 u32[i] = u;
69 64 v32[i] = v;
70 } else {
71 320 u16[i] = u;
72 320 v16[i] = v;
73 }
74 }
75
4/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 20 times.
24 c->chrConvertRange(depth == 16 ? (int16_t *) u32 : u16,
76 depth == 16 ? (int16_t *) v32 : v16, 16,
77 c->chrConvertRange_coeff,
78 c->chrConvertRange_offset);
79
4/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 12 times.
24 printf("%s %2d-bit %s U:", native ? "native" : "c ",
80 depth, from ? "full-to-limited" : "limited-to-full");
81
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 24 times.
216 for (int i = 0; i < 8; i++)
82
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 160 times.
192 printf(" %d", depth == 16 ? u32[i] : u16[i]);
83 24 printf(" V:");
84
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 24 times.
216 for (int i = 0; i < 8; i++)
85
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 160 times.
192 printf(" %d", depth == 16 ? v32[i] : v16[i]);
86 24 printf("\n");
87 }
88 }
89 }
90
91 1 av_force_cpu_flags(cpu_flags);
92 1 sws_freeContext(sws);
93 1 return 0;
94 }
95