Mercurial > libavutil.hg
annotate rational.h @ 499:67ea650d4590 libavutil
Enhance documentation for AVClass
Patch by Stefano Sabatini stefanodotsabatini-lalaatpostedotit
author | benoit |
---|---|
date | Thu, 24 Apr 2008 10:13:38 +0000 |
parents | f4187c1c15a6 |
children | bd4052d9050c |
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 | 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 | 28 #ifndef FFMPEG_RATIONAL_H |
29 #define FFMPEG_RATIONAL_H | |
0
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
30 |
343 | 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 | 33 |
0
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
34 /** |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
35 * Rational number num/den. |
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 /** |
253 | 43 * Compare two rationals. |
44 * @param a first rational | |
45 * @param b second rational | |
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 /** |
254
77e39bbb7219
move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents:
253
diff
changeset
|
56 * Rational to double conversion. |
253 | 57 * @param a rational to convert |
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 /** |
253 | 65 * Reduce a fraction. |
248 | 66 * This is useful for framerate calculations. |
253 | 67 * @param dst_nom destination numerator |
68 * @param dst_den destination denominator | |
69 * @param nom source numerator | |
70 * @param den source denominator | |
0
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
71 * @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
|
72 * @return 1 if exact, 0 otherwise |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
73 */ |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
74 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
|
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. |
77e39bbb7219
move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents:
253
diff
changeset
|
78 * @param b first rational. |
77e39bbb7219
move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents:
253
diff
changeset
|
79 * @param c second rational. |
77e39bbb7219
move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents:
253
diff
changeset
|
80 * @return b*c. |
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. |
254
77e39bbb7219
move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents:
253
diff
changeset
|
86 * @param b first rational. |
77e39bbb7219
move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents:
253
diff
changeset
|
87 * @param c second rational. |
77e39bbb7219
move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents:
253
diff
changeset
|
88 * @return b/c. |
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. |
77e39bbb7219
move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents:
253
diff
changeset
|
94 * @param b first rational. |
77e39bbb7219
move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents:
253
diff
changeset
|
95 * @param c second rational. |
77e39bbb7219
move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents:
253
diff
changeset
|
96 * @return b+c. |
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. |
254
77e39bbb7219
move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents:
253
diff
changeset
|
102 * @param b first rational. |
77e39bbb7219
move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents:
253
diff
changeset
|
103 * @param c second rational. |
364 | 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 |
77e39bbb7219
move doxy comments from rational.c to rational.h and add some new comments
gpoirier
parents:
253
diff
changeset
|
112 * @return (AVRational) d. |
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 |
392 | 116 #endif /* FFMPEG_RATIONAL_H */ |