annotate rational.h @ 837:fb1a89b9ae54 libavutil

Add alias-safe union typedefs
author mru
date Thu, 18 Feb 2010 13:40:19 +0000
parents 4f98a323598c
children 4d9ad0ed07d0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
1 /*
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
2 * rational numbers
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
4 *
116
d76a36742464 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 15
diff changeset
5 * This file is part of FFmpeg.
d76a36742464 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 15
diff changeset
6 *
d76a36742464 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 15
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
116
d76a36742464 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 15
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
11 *
116
d76a36742464 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 15
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
15 * Lesser General Public License for more details.
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
16 *
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
116
d76a36742464 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 15
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
15
af59e84e283d Update licensing information: The FSF changed postal address.
diego
parents: 12
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
20 */
12
ce8f9f4390c3 COSMETICS: Remove all trailing whitespace.
diego
parents: 0
diff changeset
21
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
22 /**
642
70bdd5501662 Use full internal pathname in doxygen @file directives.
diego
parents: 641
diff changeset
23 * @file libavutil/rational.h
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
24 * rational numbers
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
25 * @author Michael Niedermayer <michaelni@gmx.at>
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
26 */
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
27
567
bd4052d9050c Globally rename the header inclusion guard names.
stefano
parents: 481
diff changeset
28 #ifndef AVUTIL_RATIONAL_H
bd4052d9050c Globally rename the header inclusion guard names.
stefano
parents: 481
diff changeset
29 #define AVUTIL_RATIONAL_H
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
30
343
f21d1907d47c include all prerequisites in header files
mru
parents: 255
diff changeset
31 #include <stdint.h>
481
f4187c1c15a6 Reapply r12489: Add pure, const and malloc attributes to proper functions
zuxy
parents: 478
diff changeset
32 #include "common.h"
343
f21d1907d47c include all prerequisites in header files
mru
parents: 255
diff changeset
33
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
34 /**
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
35 * rational number numerator/denominator
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
36 */
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
37 typedef struct AVRational{
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
38 int num; ///< numerator
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
39 int den; ///< denominator
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
40 } AVRational;
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
41
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
42 /**
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
43 * Compares two rationals.
253
5647be712b27 Doxygenize some comments
gpoirier
parents: 248
diff changeset
44 * @param a first rational
5647be712b27 Doxygenize some comments
gpoirier
parents: 248
diff changeset
45 * @param b second rational
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
46 * @return 0 if a==b, 1 if a>b and -1 if a<b
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
47 */
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
48 static inline int av_cmp_q(AVRational a, AVRational b){
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
49 const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den;
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
50
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
51 if(tmp) return (tmp>>63)|1;
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
52 else return 0;
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
53 }
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
54
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
55 /**
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
56 * Converts rational to double.
253
5647be712b27 Doxygenize some comments
gpoirier
parents: 248
diff changeset
57 * @param a rational to convert
5647be712b27 Doxygenize some comments
gpoirier
parents: 248
diff changeset
58 * @return (double) a
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
59 */
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
60 static inline double av_q2d(AVRational a){
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
61 return a.num / (double) a.den;
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
62 }
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
63
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
64 /**
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
65 * Reduces a fraction.
248
5feb5bb5d89f cosmetics: fix usefuLL --> usefuL typo
diego
parents: 116
diff changeset
66 * This is useful for framerate calculations.
641
41e4544b228b cosmetics: Use 'num' instead of 'nom' as abbreviation for numerator.
diego
parents: 633
diff changeset
67 * @param dst_num destination numerator
253
5647be712b27 Doxygenize some comments
gpoirier
parents: 248
diff changeset
68 * @param dst_den destination denominator
641
41e4544b228b cosmetics: Use 'num' instead of 'nom' as abbreviation for numerator.
diego
parents: 633
diff changeset
69 * @param num source numerator
253
5647be712b27 Doxygenize some comments
gpoirier
parents: 248
diff changeset
70 * @param den source denominator
641
41e4544b228b cosmetics: Use 'num' instead of 'nom' as abbreviation for numerator.
diego
parents: 633
diff changeset
71 * @param max the maximum allowed for dst_num & dst_den
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
72 * @return 1 if exact, 0 otherwise
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
73 */
641
41e4544b228b cosmetics: Use 'num' instead of 'nom' as abbreviation for numerator.
diego
parents: 633
diff changeset
74 int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max);
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
75
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
76 /**
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
77 * Multiplies two rationals.
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
78 * @param b first rational
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
79 * @param c second rational
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
80 * @return b*c
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
81 */
481
f4187c1c15a6 Reapply r12489: Add pure, const and malloc attributes to proper functions
zuxy
parents: 478
diff changeset
82 AVRational av_mul_q(AVRational b, AVRational c) av_const;
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
83
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
84 /**
255
add2141ed7b0 fix 2 mistakes in doxy comments, spotted by Michael
gpoirier
parents: 254
diff changeset
85 * Divides one rational by another.
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
86 * @param b first rational
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
87 * @param c second rational
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
88 * @return b/c
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
89 */
481
f4187c1c15a6 Reapply r12489: Add pure, const and malloc attributes to proper functions
zuxy
parents: 478
diff changeset
90 AVRational av_div_q(AVRational b, AVRational c) av_const;
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
91
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
92 /**
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
93 * Adds two rationals.
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
94 * @param b first rational
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
95 * @param c second rational
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
96 * @return b+c
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
97 */
481
f4187c1c15a6 Reapply r12489: Add pure, const and malloc attributes to proper functions
zuxy
parents: 478
diff changeset
98 AVRational av_add_q(AVRational b, AVRational c) av_const;
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
99
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
100 /**
255
add2141ed7b0 fix 2 mistakes in doxy comments, spotted by Michael
gpoirier
parents: 254
diff changeset
101 * Subtracts one rational from another.
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
102 * @param b first rational
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
103 * @param c second rational
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
104 * @return b-c
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
105 */
481
f4187c1c15a6 Reapply r12489: Add pure, const and malloc attributes to proper functions
zuxy
parents: 478
diff changeset
106 AVRational av_sub_q(AVRational b, AVRational c) av_const;
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
107
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
108 /**
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
109 * Converts a double precision floating point number to a rational.
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
110 * @param d double to convert
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
111 * @param max the maximum allowed numerator and denominator
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 573
diff changeset
112 * @return (AVRational) d
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
113 */
481
f4187c1c15a6 Reapply r12489: Add pure, const and malloc attributes to proper functions
zuxy
parents: 478
diff changeset
114 AVRational av_d2q(double d, int max) av_const;
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
115
573
1f4b70bcd610 Implement av_nearer_q() and av_find_nearest_q_idx() functions.
stefano
parents: 567
diff changeset
116 /**
738
4f98a323598c Remove '\p', '\c' and '\e' doxygen markup from doxy, as it should
stefano
parents: 642
diff changeset
117 * @return 1 if q1 is nearer to q than q2, -1 if q2 is nearer
4f98a323598c Remove '\p', '\c' and '\e' doxygen markup from doxy, as it should
stefano
parents: 642
diff changeset
118 * than q1, 0 if they have the same distance.
573
1f4b70bcd610 Implement av_nearer_q() and av_find_nearest_q_idx() functions.
stefano
parents: 567
diff changeset
119 */
1f4b70bcd610 Implement av_nearer_q() and av_find_nearest_q_idx() functions.
stefano
parents: 567
diff changeset
120 int av_nearer_q(AVRational q, AVRational q1, AVRational q2);
1f4b70bcd610 Implement av_nearer_q() and av_find_nearest_q_idx() functions.
stefano
parents: 567
diff changeset
121
1f4b70bcd610 Implement av_nearer_q() and av_find_nearest_q_idx() functions.
stefano
parents: 567
diff changeset
122 /**
738
4f98a323598c Remove '\p', '\c' and '\e' doxygen markup from doxy, as it should
stefano
parents: 642
diff changeset
123 * Finds the nearest value in q_list to q.
573
1f4b70bcd610 Implement av_nearer_q() and av_find_nearest_q_idx() functions.
stefano
parents: 567
diff changeset
124 * @param q_list an array of rationals terminated by {0, 0}
1f4b70bcd610 Implement av_nearer_q() and av_find_nearest_q_idx() functions.
stefano
parents: 567
diff changeset
125 * @return the index of the nearest value found in the array
1f4b70bcd610 Implement av_nearer_q() and av_find_nearest_q_idx() functions.
stefano
parents: 567
diff changeset
126 */
1f4b70bcd610 Implement av_nearer_q() and av_find_nearest_q_idx() functions.
stefano
parents: 567
diff changeset
127 int av_find_nearest_q_idx(AVRational q, const AVRational* q_list);
1f4b70bcd610 Implement av_nearer_q() and av_find_nearest_q_idx() functions.
stefano
parents: 567
diff changeset
128
567
bd4052d9050c Globally rename the header inclusion guard names.
stefano
parents: 481
diff changeset
129 #endif /* AVUTIL_RATIONAL_H */