[FFmpeg-devel] [PATCH 1/2] avutil/rational: add av_reduce_q()
Paul B Mahol
onemda at gmail.com
Sun Dec 9 15:38:54 EET 2018
Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
libavutil/rational.c | 5 +++++
libavutil/rational.h | 12 ++++++++++++
2 files changed, 17 insertions(+)
diff --git a/libavutil/rational.c b/libavutil/rational.c
index 35ee08877f..47f64e914e 100644
--- a/libavutil/rational.c
+++ b/libavutil/rational.c
@@ -77,6 +77,11 @@ int av_reduce(int *dst_num, int *dst_den,
return den == 0;
}
+int av_reduce_q(AVRational *dst, AVRational src, int64_t max)
+{
+ return av_reduce(&dst->num, &dst->den, src.num, src.den, max);
+}
+
AVRational av_mul_q(AVRational b, AVRational c)
{
av_reduce(&b.num, &b.den,
diff --git a/libavutil/rational.h b/libavutil/rational.h
index 5c6b67b4e9..a62b895fff 100644
--- a/libavutil/rational.h
+++ b/libavutil/rational.h
@@ -119,6 +119,18 @@ static inline double av_q2d(AVRational a){
*/
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max);
+/**
+ * Reduce a rational.
+ *
+ * This is useful for aspect ratio calculations.
+ *
+ * @param[out] dst Destination rational
+ * @param[in] src Source rational
+ * @param[in] max Maximum allowed values for `dst`
+ * @return 1 if the operation is exact, 0 otherwise
+ */
+int av_reduce_q(AVRational *dst, AVRational src, int64_t max);
+
/**
* Multiply two rationals.
* @param b First rational
--
2.17.1
More information about the ffmpeg-devel
mailing list