Util: Factor out gcd code
Vicki Pfau vi@endrift.com
Thu, 23 Jul 2020 21:42:35 -0700
2 files changed,
16 insertions(+),
9 deletions(-)
M
include/mgba-util/math.h
→
include/mgba-util/math.h
@@ -58,6 +58,19 @@ unsigned lz = clz32(bits - 1);
return 1 << (32 - lz); } +static inline int reduceFraction(int* num, int* den) { + int n = *num; + int d = *den; + while (d != 0) { + int temp = n % d; + n = d; + d = temp; + } + *num /= n; + *den /= n; + return n; +} + CXX_GUARD_END #endif
M
src/platform/qt/VideoView.cpp
→
src/platform/qt/VideoView.cpp
@@ -10,6 +10,8 @@
#include "GBAApp.h" #include "LogController.h" +#include <mgba-util/math.h> + #include <QMap> using namespace QGBA;@@ -396,15 +398,7 @@ safelySet(m_ui.height, m_height);
} else { int w = m_width; int h = m_height; - // Get greatest common divisor - while (w != 0) { - int temp = h % w; - h = w; - w = temp; - } - int gcd = h; - w = m_width / gcd; - h = m_height / gcd; + reduceFraction(&h, &w); safelySet(m_ui.wratio, w); safelySet(m_ui.hratio, h); }