/src/ffmpeg/libswscale/rational64.h
Line | Count | Source |
1 | | /* |
2 | | * 64-bit rational numbers |
3 | | * Copyright (c) 2025 Niklas Haas |
4 | | * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> |
5 | | * |
6 | | * This file is part of FFmpeg. |
7 | | * |
8 | | * FFmpeg is free software; you can redistribute it and/or |
9 | | * modify it under the terms of the GNU Lesser General Public |
10 | | * License as published by the Free Software Foundation; either |
11 | | * version 2.1 of the License, or (at your option) any later version. |
12 | | * |
13 | | * FFmpeg is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | | * Lesser General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public |
19 | | * License along with FFmpeg; if not, write to the Free Software |
20 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21 | | */ |
22 | | |
23 | | /** |
24 | | * @file |
25 | | * @ingroup lavu_math_rational |
26 | | * 64-bit extension of AVRational. |
27 | | * @author Niklas Haas |
28 | | */ |
29 | | |
30 | | #ifndef SWSCALE_RATIONAL64_H |
31 | | #define SWSCALE_RATIONAL64_H |
32 | | |
33 | | #include <stdint.h> |
34 | | #include <limits.h> |
35 | | |
36 | | #include "libavutil/attributes.h" |
37 | | |
38 | | /** |
39 | | * @defgroup AVRational64 |
40 | | * 64-bit extension of AVRational |
41 | | * |
42 | | * Offers a 64-bit extended version of AVRational. This is less efficient (and |
43 | | * may revolve around emulated 128-bit multiplications internally), but allows |
44 | | * to represent a much larger range of rational numbers without overflow. |
45 | | * |
46 | | * @{ |
47 | | */ |
48 | | |
49 | | /** |
50 | | * 64-bit Rational number (pair of numerator and denominator). |
51 | | */ |
52 | | typedef struct AVRational64 { |
53 | | int64_t num; ///< Numerator |
54 | | int64_t den; ///< Denominator |
55 | | } AVRational64; |
56 | | |
57 | | /** |
58 | | * Create an AVRational64. |
59 | | * |
60 | | * Useful for compilers that do not support compound literals. |
61 | | * |
62 | | * @note The return value is not reduced. |
63 | | */ |
64 | | static inline AVRational64 av_make_q64(int64_t num, int64_t den) |
65 | 0 | { |
66 | 0 | AVRational64 r = { num, den }; |
67 | 0 | return r; |
68 | 0 | } Unexecuted instantiation: format.c:av_make_q64 Unexecuted instantiation: graph.c:av_make_q64 Unexecuted instantiation: ops.c:av_make_q64 Unexecuted instantiation: ops_dispatch.c:av_make_q64 Unexecuted instantiation: ops_memcpy.c:av_make_q64 Unexecuted instantiation: ops_optimizer.c:av_make_q64 Unexecuted instantiation: rational64.c:av_make_q64 Unexecuted instantiation: uops.c:av_make_q64 Unexecuted instantiation: uops_backend.c:av_make_q64 Unexecuted instantiation: ops_chain.c:av_make_q64 |
69 | | |
70 | | /** |
71 | | * Compare two 64-bit rationals. |
72 | | * |
73 | | * @param a First rational |
74 | | * @param b Second rational |
75 | | * |
76 | | * @return One of the following values: |
77 | | * - 0 if `a == b` |
78 | | * - 1 if `a > b` |
79 | | * - -1 if `a < b` |
80 | | * - `INT_MIN` if one of the values is of the form `0 / 0` |
81 | | */ |
82 | | int av_cmp_q64(AVRational64 a, AVRational64 b); |
83 | | |
84 | | /** |
85 | | * Convert an AVRational64 to a `double`. |
86 | | * @param a AVRational64 to convert |
87 | | * @return `a` in floating-point form |
88 | | * @see av_d2q() |
89 | | */ |
90 | 0 | static inline double av_q2d_64(AVRational64 a){ |
91 | 0 | return a.num / (double) a.den; |
92 | 0 | } Unexecuted instantiation: format.c:av_q2d_64 Unexecuted instantiation: graph.c:av_q2d_64 Unexecuted instantiation: ops.c:av_q2d_64 Unexecuted instantiation: ops_dispatch.c:av_q2d_64 Unexecuted instantiation: ops_memcpy.c:av_q2d_64 Unexecuted instantiation: ops_optimizer.c:av_q2d_64 Unexecuted instantiation: rational64.c:av_q2d_64 Unexecuted instantiation: uops.c:av_q2d_64 Unexecuted instantiation: uops_backend.c:av_q2d_64 Unexecuted instantiation: ops_chain.c:av_q2d_64 |
93 | | |
94 | | /** |
95 | | * Multiply two 64-bit rationals. |
96 | | * @param b First multiplicant |
97 | | * @param c Second multiplicant |
98 | | * @return b*c |
99 | | */ |
100 | | AVRational64 av_mul_q64(AVRational64 b, AVRational64 c) av_const; |
101 | | |
102 | | /** |
103 | | * Divide one 64-bit rational by another. |
104 | | * @param b Dividend |
105 | | * @param c Divisor |
106 | | * @return b/c |
107 | | */ |
108 | | AVRational64 av_div_q64(AVRational64 b, AVRational64 c) av_const; |
109 | | |
110 | | /** |
111 | | * Add two 64-bit rationals. |
112 | | * @param b First addend |
113 | | * @param c Second addend |
114 | | * @return b+c |
115 | | */ |
116 | | AVRational64 av_add_q64(AVRational64 b, AVRational64 c) av_const; |
117 | | |
118 | | /** |
119 | | * Subtract one 64-bit rational from another. |
120 | | * @param b Minuend |
121 | | * @param c Subtrahend |
122 | | * @return b-c |
123 | | */ |
124 | | AVRational64 av_sub_q64(AVRational64 b, AVRational64 c) av_const; |
125 | | |
126 | | /** |
127 | | * Invert a 64-bit rational. |
128 | | * @param q value |
129 | | * @return 1 / q |
130 | | */ |
131 | | static av_always_inline AVRational64 av_inv_q64(AVRational64 q) |
132 | 0 | { |
133 | 0 | AVRational64 r = { q.den, q.num }; |
134 | 0 | return r; |
135 | 0 | } Unexecuted instantiation: format.c:av_inv_q64 Unexecuted instantiation: graph.c:av_inv_q64 Unexecuted instantiation: ops.c:av_inv_q64 Unexecuted instantiation: ops_dispatch.c:av_inv_q64 Unexecuted instantiation: ops_memcpy.c:av_inv_q64 Unexecuted instantiation: ops_optimizer.c:av_inv_q64 Unexecuted instantiation: rational64.c:av_inv_q64 Unexecuted instantiation: uops.c:av_inv_q64 Unexecuted instantiation: uops_backend.c:av_inv_q64 Unexecuted instantiation: ops_chain.c:av_inv_q64 |
136 | | |
137 | | /** |
138 | | * @} |
139 | | */ |
140 | | |
141 | | #endif /* SWSCALE_RATIONAL64_H */ |