annotate rational.h @ 478:8d2c05ebf5f1 libavutil

revert r12489.
author benoit
date Tue, 18 Mar 2008 16:29:47 +0000
parents 8d25a4b50588
children f4187c1c15a6
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 /*
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
2 * Rational numbers
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 /**
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
23 * @file rational.h
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
24 * Rational numbers.
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
392
d0f3bb6e367e Add FFMPEG_ prefix to all multiple inclusion guards.
diego
parents: 364
diff changeset
28 #ifndef FFMPEG_RATIONAL_H
d0f3bb6e367e Add FFMPEG_ prefix to all multiple inclusion guards.
diego
parents: 364
diff changeset
29 #define FFMPEG_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>
f21d1907d47c include all prerequisites in header files
mru
parents: 255
diff changeset
32
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
33 /**
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
34 * Rational number num/den.
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
35 */
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
36 typedef struct AVRational{
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
37 int num; ///< numerator
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
38 int den; ///< denominator
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
39 } AVRational;
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
40
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
41 /**
253
5647be712b27 Doxygenize some comments
gpoirier
parents: 248
diff changeset
42 * Compare two rationals.
5647be712b27 Doxygenize some comments
gpoirier
parents: 248
diff changeset
43 * @param a first rational
5647be712b27 Doxygenize some comments
gpoirier
parents: 248
diff changeset
44 * @param b second rational
5647be712b27 Doxygenize some comments
gpoirier
parents: 248
diff changeset
45 * @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
46 */
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
47 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
48 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
49
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
50 if(tmp) return (tmp>>63)|1;
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
51 else return 0;
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
52 }
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 /**
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
55 * Rational to double conversion.
253
5647be712b27 Doxygenize some comments
gpoirier
parents: 248
diff changeset
56 * @param a rational to convert
5647be712b27 Doxygenize some comments
gpoirier
parents: 248
diff changeset
57 * @return (double) a
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
58 */
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
59 static inline double av_q2d(AVRational a){
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
60 return a.num / (double) a.den;
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
61 }
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 /**
253
5647be712b27 Doxygenize some comments
gpoirier
parents: 248
diff changeset
64 * Reduce a fraction.
248
5feb5bb5d89f cosmetics: fix usefuLL --> usefuL typo
diego
parents: 116
diff changeset
65 * This is useful for framerate calculations.
253
5647be712b27 Doxygenize some comments
gpoirier
parents: 248
diff changeset
66 * @param dst_nom destination numerator
5647be712b27 Doxygenize some comments
gpoirier
parents: 248
diff changeset
67 * @param dst_den destination denominator
5647be712b27 Doxygenize some comments
gpoirier
parents: 248
diff changeset
68 * @param nom source numerator
5647be712b27 Doxygenize some comments
gpoirier
parents: 248
diff changeset
69 * @param den source denominator
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
70 * @param max the maximum allowed for dst_nom & dst_den
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
71 * @return 1 if exact, 0 otherwise
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
72 */
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
73 int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max);
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
74
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
75 /**
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
76 * Multiplies two rationals.
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
77 * @param b first rational.
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
78 * @param c second rational.
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
79 * @return b*c.
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
80 */
478
8d2c05ebf5f1 revert r12489.
benoit
parents: 477
diff changeset
81 AVRational av_mul_q(AVRational b, AVRational c);
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
82
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
83 /**
255
add2141ed7b0 fix 2 mistakes in doxy comments, spotted by Michael
gpoirier
parents: 254
diff changeset
84 * Divides one rational by another.
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
85 * @param b first rational.
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
86 * @param c second rational.
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
87 * @return b/c.
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
88 */
478
8d2c05ebf5f1 revert r12489.
benoit
parents: 477
diff changeset
89 AVRational av_div_q(AVRational b, AVRational c);
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
90
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 * Adds two rationals.
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
93 * @param b first rational.
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
94 * @param c second rational.
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
95 * @return b+c.
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
96 */
478
8d2c05ebf5f1 revert r12489.
benoit
parents: 477
diff changeset
97 AVRational av_add_q(AVRational b, AVRational c);
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
98
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
99 /**
255
add2141ed7b0 fix 2 mistakes in doxy comments, spotted by Michael
gpoirier
parents: 254
diff changeset
100 * Subtracts one rational from another.
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
101 * @param b first rational.
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
102 * @param c second rational.
364
d83531dda292 match doxygen comment with other parts of the file
alex
parents: 358
diff changeset
103 * @return b-c.
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
104 */
478
8d2c05ebf5f1 revert r12489.
benoit
parents: 477
diff changeset
105 AVRational av_sub_q(AVRational b, AVRational c);
254
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
106
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 * 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
109 * @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
110 * @param max the maximum allowed numerator and denominator
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
111 * @return (AVRational) d.
77e39bbb7219 move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents: 253
diff changeset
112 */
478
8d2c05ebf5f1 revert r12489.
benoit
parents: 477
diff changeset
113 AVRational av_d2q(double d, int max);
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
114
392
d0f3bb6e367e Add FFMPEG_ prefix to all multiple inclusion guards.
diego
parents: 364
diff changeset
115 #endif /* FFMPEG_RATIONAL_H */