From patchwork Sat Nov 24 23:37:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 11150 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 8E00044CF7A for ; Sun, 25 Nov 2018 01:37:45 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0C19D68A261; Sun, 25 Nov 2018 01:37:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3BEFF689B5E for ; Sun, 25 Nov 2018 01:37:39 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id D56EDE238D; Sun, 25 Nov 2018 00:37:42 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tCSY6lfZ1ISb; Sun, 25 Nov 2018 00:37:42 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 1A355E238C; Sun, 25 Nov 2018 00:37:42 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 25 Nov 2018 00:37:37 +0100 Message-Id: <20181124233738.31051-1-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 Subject: [FFmpeg-devel] [PATCH 1/2] ffplay: convert float math to int math in calculate_display_rect 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 Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- fftools/ffplay.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/fftools/ffplay.c b/fftools/ffplay.c index ab1f9faccf..af72fbcc38 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -861,24 +861,20 @@ static void calculate_display_rect(SDL_Rect *rect, int scr_xleft, int scr_ytop, int scr_width, int scr_height, int pic_width, int pic_height, AVRational pic_sar) { - float aspect_ratio; - int width, height, x, y; + AVRational aspect_ratio = pic_sar; + int64_t width, height, x, y; - if (pic_sar.num == 0) - aspect_ratio = 0; - else - aspect_ratio = av_q2d(pic_sar); + if (av_cmp_q(aspect_ratio, av_make_q(0, 1)) <= 0) + aspect_ratio = av_make_q(1, 1); - if (aspect_ratio <= 0.0) - aspect_ratio = 1.0; - aspect_ratio *= (float)pic_width / (float)pic_height; + aspect_ratio = av_mul_q(aspect_ratio, av_make_q(pic_width, pic_height)); /* XXX: we suppose the screen has a 1.0 pixel ratio */ height = scr_height; - width = lrint(height * aspect_ratio) & ~1; + width = av_rescale(height, aspect_ratio.num, aspect_ratio.den) & ~1; if (width > scr_width) { width = scr_width; - height = lrint(width / aspect_ratio) & ~1; + height = av_rescale(width, aspect_ratio.den, aspect_ratio.num) & ~1; } x = (scr_width - width) / 2; y = (scr_height - height) / 2;