FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libswscale/format.h
Date: 2025-06-01 09:29:47
Exec Total Coverage
Lines: 31 31 100.0%
Functions: 8 8 100.0%
Branches: 32 48 66.7%

Line Branch Exec Source
1 /*
2 * Copyright (C) 2024 Niklas Haas
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef SWSCALE_FORMAT_H
22 #define SWSCALE_FORMAT_H
23
24 #include <stdbool.h>
25
26 #include "libavutil/csp.h"
27 #include "libavutil/pixdesc.h"
28
29 #include "swscale.h"
30
31 2683604 static inline int ff_q_isnan(const AVRational a)
32 {
33
4/4
✓ Branch 0 taken 2486428 times.
✓ Branch 1 taken 197176 times.
✓ Branch 2 taken 2294376 times.
✓ Branch 3 taken 192052 times.
2683604 return !a.num && !a.den;
34 }
35
36 /* Like av_cmp_q but considers NaN == NaN */
37 1536416 static inline int ff_q_equal(const AVRational a, const AVRational b)
38 {
39
4/6
✓ Branch 1 taken 1147188 times.
✓ Branch 2 taken 389228 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1147188 times.
✓ Branch 7 taken 389228 times.
✗ Branch 8 not taken.
1536416 return (ff_q_isnan(a) && ff_q_isnan(b)) || !av_cmp_q(a, b);
40 }
41
42 576156 static inline int ff_cie_xy_equal(const AVCIExy a, const AVCIExy b)
43 {
44
2/4
✓ Branch 1 taken 576156 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 576156 times.
✗ Branch 5 not taken.
576156 return ff_q_equal(a.x, b.x) && ff_q_equal(a.y, b.y);
45 }
46
47 192052 static inline int ff_prim_equal(const AVPrimaryCoefficients *a,
48 const AVPrimaryCoefficients *b)
49 {
50
1/2
✓ Branch 1 taken 192052 times.
✗ Branch 2 not taken.
384104 return ff_cie_xy_equal(a->r, b->r) &&
51
2/4
✓ Branch 0 taken 192052 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 192052 times.
✗ Branch 4 not taken.
384104 ff_cie_xy_equal(a->g, b->g) &&
52 192052 ff_cie_xy_equal(a->b, b->b);
53 }
54
55 enum {
56 FIELD_TOP, /* top/even rows, or progressive */
57 FIELD_BOTTOM, /* bottom/odd rows */
58 };
59
60 typedef struct SwsColor {
61 enum AVColorPrimaries prim;
62 enum AVColorTransferCharacteristic trc;
63 AVPrimaryCoefficients gamut; /* mastering display gamut */
64 AVRational min_luma; /* minimum luminance in nits */
65 AVRational max_luma; /* maximum luminance in nits */
66 AVRational frame_peak; /* per-frame/scene peak luminance, or 0 */
67 AVRational frame_avg; /* per-frame/scene average luminance, or 0 */
68 } SwsColor;
69
70 93633 static inline void ff_color_update_dynamic(SwsColor *dst, const SwsColor *src)
71 {
72 93633 dst->frame_peak = src->frame_peak;
73 93633 dst->frame_avg = src->frame_avg;
74 93633 }
75
76 /* Subset of AVFrame parameters that uniquely determine pixel representation */
77 typedef struct SwsFormat {
78 int width, height;
79 int interlaced;
80 enum AVPixelFormat format;
81 enum AVColorRange range;
82 enum AVColorSpace csp;
83 enum AVChromaLocation loc;
84 const AVPixFmtDescriptor *desc; /* convenience */
85 SwsColor color;
86 } SwsFormat;
87
88 /**
89 * This function also sanitizes and strips the input data, removing irrelevant
90 * fields for certain formats.
91 */
92 SwsFormat ff_fmt_from_frame(const AVFrame *frame, int field);
93
94 192052 static inline int ff_color_equal(const SwsColor *c1, const SwsColor *c2)
95 {
96 384104 return c1->prim == c2->prim &&
97
2/4
✓ Branch 0 taken 192052 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 192052 times.
✗ Branch 3 not taken.
384104 c1->trc == c2->trc &&
98
1/2
✓ Branch 1 taken 192052 times.
✗ Branch 2 not taken.
384104 ff_q_equal(c1->min_luma, c2->min_luma) &&
99
2/4
✓ Branch 0 taken 192052 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 192052 times.
✗ Branch 4 not taken.
576156 ff_q_equal(c1->max_luma, c2->max_luma) &&
100 192052 ff_prim_equal(&c1->gamut, &c2->gamut);
101 }
102
103 /* Tests only the static components of a colorspace, ignoring dimensions and per-frame data */
104 291646 static inline int ff_props_equal(const SwsFormat *fmt1, const SwsFormat *fmt2)
105 {
106 583292 return fmt1->interlaced == fmt2->interlaced &&
107
2/2
✓ Branch 0 taken 192301 times.
✓ Branch 1 taken 99345 times.
291646 fmt1->format == fmt2->format &&
108
2/2
✓ Branch 0 taken 192052 times.
✓ Branch 1 taken 249 times.
192301 fmt1->range == fmt2->range &&
109
1/2
✓ Branch 0 taken 192052 times.
✗ Branch 1 not taken.
192052 fmt1->csp == fmt2->csp &&
110
3/6
✓ Branch 0 taken 291646 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 192052 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 192052 times.
✗ Branch 5 not taken.
775344 fmt1->loc == fmt2->loc &&
111 192052 ff_color_equal(&fmt1->color, &fmt2->color);
112 }
113
114 /* Tests only the static components of a colorspace, ignoring per-frame data */
115 298017 static inline int ff_fmt_equal(const SwsFormat *fmt1, const SwsFormat *fmt2)
116 {
117 589686 return fmt1->width == fmt2->width &&
118
6/6
✓ Branch 0 taken 291669 times.
✓ Branch 1 taken 6348 times.
✓ Branch 2 taken 291646 times.
✓ Branch 3 taken 23 times.
✓ Branch 4 taken 192052 times.
✓ Branch 5 taken 99594 times.
589663 fmt1->height == fmt2->height &&
119 291646 ff_props_equal(fmt1, fmt2);
120 }
121
122 static inline int ff_fmt_align(enum AVPixelFormat fmt)
123 {
124 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
125 if (desc->flags & AV_PIX_FMT_FLAG_BAYER) {
126 return 2;
127 } else {
128 return 1 << desc->log2_chroma_h;
129 }
130 }
131
132 int ff_test_fmt(const SwsFormat *fmt, int output);
133
134 /* Returns true if the formats are incomplete, false otherwise */
135 bool ff_infer_colors(SwsColor *src, SwsColor *dst);
136
137 #endif /* SWSCALE_FORMAT_H */
138