[FFmpeg-devel,1/2] avutil/rational: add av_reduce_q()

Submitted by Paul B Mahol on Dec. 9, 2018, 1:38 p.m.

Details

Message ID 20181209133855.28636-1-onemda@gmail.com
State New
Headers show

Commit Message

Paul B Mahol Dec. 9, 2018, 1:38 p.m.
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavutil/rational.c |  5 +++++
 libavutil/rational.h | 12 ++++++++++++
 2 files changed, 17 insertions(+)

Patch hide | download patch | download mbox

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