From b842bf6cddc71f5104f127f984a2bcefe6640943 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 6 Jul 2021 10:17:10 +0200 Subject: [PATCH] Theora parser: use rationals for calculation of display dimensions --- src/common/theora.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/common/theora.cpp b/src/common/theora.cpp index 77ce9badb..d9352c6ce 100644 --- a/src/common/theora.cpp +++ b/src/common/theora.cpp @@ -13,9 +13,8 @@ #include "common/common_pch.h" -#include - #include "common/bit_reader.h" +#include "common/math_fwd.h" #include "common/theora.h" namespace mtx::theora { @@ -65,12 +64,12 @@ parse_identification_header(unsigned char *buffer, header.pf = bc.get_bits(2); if ((0 != header.parn) && (0 != header.pard)) { - if ((static_cast(header.fmbw) / header.fmbh) < (static_cast(header.parn) / header.pard)) { - header.display_width = std::llround(static_cast(header.fmbw) * header.parn / header.pard); + if (mtx::rational(header.fmbw, header.fmbh) < mtx::rational(header.parn, header.pard)) { + header.display_width = mtx::to_int_rounded(mtx::rational(header.fmbw * header.parn, header.pard)); header.display_height = header.fmbh; } else { header.display_width = header.fmbw; - header.display_height = std::llround(static_cast(header.fmbh) * header.pard / header.parn); + header.display_height = mtx::to_int_rounded(mtx::rational(header.fmbh * header.pard, header.parn)); } } }