diff mbox

[FFmpeg-devel,1/2] ffplay: convert float math to int math in calculate_display_rect

Message ID 20181124233738.31051-1-cus@passwd.hu
State Accepted
Headers show

Commit Message

Marton Balint Nov. 24, 2018, 11:37 p.m. UTC
Signed-off-by: Marton Balint <cus@passwd.hu>
---
 fftools/ffplay.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

Comments

Marton Balint Dec. 2, 2018, 12:07 a.m. UTC | #1
On Sun, 25 Nov 2018, Marton Balint wrote:

> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
> fftools/ffplay.c | 18 +++++++-----------
> 1 file changed, 7 insertions(+), 11 deletions(-)

Pushed the series.

Regards,
Marton
diff mbox

Patch

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;