FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libswscale/utils.h
Date: 2025-01-20 09:27:23
Exec Total Coverage
Lines: 29 29 100.0%
Functions: 7 7 100.0%
Branches: 30 46 65.2%

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_UTILS_H
22 #define SWSCALE_UTILS_H
23
24 #include "libavutil/csp.h"
25 #include "libavutil/pixdesc.h"
26
27 #include "swscale.h"
28
29 2267294 static inline int ff_q_isnan(const AVRational a)
30 {
31
4/4
✓ Branch 0 taken 2100838 times.
✓ Branch 1 taken 166456 times.
✓ Branch 2 taken 1938588 times.
✓ Branch 3 taken 162250 times.
2267294 return !a.num && !a.den;
32 }
33
34 /* Like av_cmp_q but considers NaN == NaN */
35 1298000 static inline int ff_q_equal(const AVRational a, const AVRational b)
36 {
37
4/6
✓ Branch 1 taken 969294 times.
✓ Branch 2 taken 328706 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 969294 times.
✓ Branch 7 taken 328706 times.
✗ Branch 8 not taken.
1298000 return (ff_q_isnan(a) && ff_q_isnan(b)) || !av_cmp_q(a, b);
38 }
39
40 486750 static inline int ff_cie_xy_equal(const AVCIExy a, const AVCIExy b)
41 {
42
2/4
✓ Branch 1 taken 486750 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 486750 times.
✗ Branch 5 not taken.
486750 return ff_q_equal(a.x, b.x) && ff_q_equal(a.y, b.y);
43 }
44
45 162250 static inline int ff_prim_equal(const AVPrimaryCoefficients *a,
46 const AVPrimaryCoefficients *b)
47 {
48
1/2
✓ Branch 1 taken 162250 times.
✗ Branch 2 not taken.
324500 return ff_cie_xy_equal(a->r, b->r) &&
49
2/4
✓ Branch 0 taken 162250 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 162250 times.
✗ Branch 4 not taken.
324500 ff_cie_xy_equal(a->g, b->g) &&
50 162250 ff_cie_xy_equal(a->b, b->b);
51 }
52
53 enum {
54 FIELD_TOP, /* top/even rows, or progressive */
55 FIELD_BOTTOM, /* bottom/odd rows */
56 };
57
58 typedef struct SwsColor {
59 enum AVColorPrimaries prim;
60 enum AVColorTransferCharacteristic trc;
61 AVPrimaryCoefficients gamut; /* mastering display gamut */
62 AVRational min_luma; /* minimum luminance in nits */
63 AVRational max_luma; /* maximum luminance in nits */
64 AVRational frame_peak; /* per-frame/scene peak luminance, or 0 */
65 AVRational frame_avg; /* per-frame/scene average luminance, or 0 */
66 } SwsColor;
67
68 78773 static inline void ff_color_update_dynamic(SwsColor *dst, const SwsColor *src)
69 {
70 78773 dst->frame_peak = src->frame_peak;
71 78773 dst->frame_avg = src->frame_avg;
72 78773 }
73
74 /* Subset of AVFrame parameters that uniquely determine pixel representation */
75 typedef struct SwsFormat {
76 int width, height;
77 int interlaced;
78 enum AVPixelFormat format;
79 enum AVColorRange range;
80 enum AVColorSpace csp;
81 enum AVChromaLocation loc;
82 const AVPixFmtDescriptor *desc; /* convenience */
83 SwsColor color;
84 } SwsFormat;
85
86 /**
87 * This function also sanitizes and strips the input data, removing irrelevant
88 * fields for certain formats.
89 */
90 SwsFormat ff_fmt_from_frame(const AVFrame *frame, int field);
91
92 162250 static inline int ff_color_equal(const SwsColor *c1, const SwsColor *c2)
93 {
94 324500 return c1->prim == c2->prim &&
95
2/4
✓ Branch 0 taken 162250 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 162250 times.
✗ Branch 3 not taken.
324500 c1->trc == c2->trc &&
96
1/2
✓ Branch 1 taken 162250 times.
✗ Branch 2 not taken.
324500 ff_q_equal(c1->min_luma, c2->min_luma) &&
97
2/4
✓ Branch 0 taken 162250 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 162250 times.
✗ Branch 4 not taken.
486750 ff_q_equal(c1->max_luma, c2->max_luma) &&
98 162250 ff_prim_equal(&c1->gamut, &c2->gamut);
99 }
100
101 /* Tests only the static components of a colorspace, ignoring per-frame data */
102 252039 static inline int ff_fmt_equal(const SwsFormat *fmt1, const SwsFormat *fmt2)
103 {
104 497734 return fmt1->width == fmt2->width &&
105
2/2
✓ Branch 0 taken 245672 times.
✓ Branch 1 taken 23 times.
245695 fmt1->height == fmt2->height &&
106
1/2
✓ Branch 0 taken 245672 times.
✗ Branch 1 not taken.
245672 fmt1->interlaced == fmt2->interlaced &&
107
2/2
✓ Branch 0 taken 162391 times.
✓ Branch 1 taken 83281 times.
245672 fmt1->format == fmt2->format &&
108
2/2
✓ Branch 0 taken 162250 times.
✓ Branch 1 taken 141 times.
162391 fmt1->range == fmt2->range &&
109
1/2
✓ Branch 0 taken 162250 times.
✗ Branch 1 not taken.
162250 fmt1->csp == fmt2->csp &&
110
4/6
✓ Branch 0 taken 245695 times.
✓ Branch 1 taken 6344 times.
✓ Branch 2 taken 162250 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 162250 times.
✗ Branch 5 not taken.
659984 fmt1->loc == fmt2->loc &&
111 162250 ff_color_equal(&fmt1->color, &fmt2->color);
112 }
113
114 static inline int ff_fmt_align(enum AVPixelFormat fmt)
115 {
116 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
117 if (desc->flags & AV_PIX_FMT_FLAG_BAYER) {
118 return 2;
119 } else {
120 return 1 << desc->log2_chroma_h;
121 }
122 }
123
124 int ff_test_fmt(const SwsFormat *fmt, int output);
125
126 /* Returns 1 if the formats are incomplete, 0 otherwise */
127 int ff_infer_colors(SwsColor *src, SwsColor *dst);
128
129 #endif /* SWSCALE_UTILS_H */
130