From patchwork Sun Dec 9 13:38:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 11351 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id B4ED444D878 for ; Sun, 9 Dec 2018 15:39:09 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0F02668AA1F; Sun, 9 Dec 2018 15:39:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 71F3168AA10 for ; Sun, 9 Dec 2018 15:38:53 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id j10so7912774wru.4 for ; Sun, 09 Dec 2018 05:39:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=RUleFH8O9NzlaS627UUKbRDcPB8nc7kwOKOXnj/pFAM=; b=Cl7rfvi8mA9f7zAIgoBj0W8Zv/kweSihnWpRBtQLCXcfsMN6K36yLt1KUAnmRUVFKr cjaGVc8+TEkFswfoZ/wV8H/1TodZoDs0uPDroXylU4wdZdsKrDHzk0YAUJXpw+0G0UZF i6mvyCgJxQe+EoN2wT8FqMynfuyuU44A20MNrgMk2YiwbDU9qJCaph2wpYtnbuJp+kKX Glqliix+c5SH9ssBI+6xoaclLzWoe+mrciyBbG4ebi/mC0/q9tyyi2tiXmgQ83HXy56w 4p5spmkomTG35uMjrQ73IWM/km42EpYdRGKxZaL1tyWaM8NV+2LEv3LAT77gJ5okD/ps Gb/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=RUleFH8O9NzlaS627UUKbRDcPB8nc7kwOKOXnj/pFAM=; b=aigOcCsCvxvwlegbXxL9QiGM63uzA+psaO78kvCAcQVGhSm/A1M+5M8ZMCJnn6w+na CElr7pX+kyY4wx/0TNCyfCllTOjsrIzQTA7AVMZH3H3dKQ2Da0P8AjYmuv8VueVoZSXr e6+RR/xg7koG11RvzR1WX/GpNfCJFcPgvlX95tWh4ESv3hu+sMJ20wIT7ehncDeMNPrI 4JXdx3gTjcYI8G1ZWbfhjYbH0HDCDyp1xcW0CKLhWPsM5vfgFn848PK7r+9MlrhwBTbV Z7ss/E0qa9RQjT3vlPk6lTiEYALgXO1BvCp9WIMU+DLx4bchy35oSUU1AxSLuqRvxcaj X6LA== X-Gm-Message-State: AA+aEWbRfqV0fFmD2C1t67A+bl76LA3wqPHb96DM5haIoi9+mDP/RUMV zzTuYCSaNKThDq+pJ+QJRESmGwLF X-Google-Smtp-Source: AFSGD/V7FPCj7x0ALls41GOdh5vuaLxyQRdnPNkdfgp0hhWvK83gZVvspKqS5oMRWpPH0RLvsM8EkA== X-Received: by 2002:adf:e608:: with SMTP id p8mr7026840wrm.166.1544362743372; Sun, 09 Dec 2018 05:39:03 -0800 (PST) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id z206sm6061873wmc.18.2018.12.09.05.39.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Dec 2018 05:39:02 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Dec 2018 14:38:54 +0100 Message-Id: <20181209133855.28636-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/2] avutil/rational: add av_reduce_q() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- 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