-
Notifications
You must be signed in to change notification settings - Fork 61
/
ImageResolution.cpp
51 lines (41 loc) · 1.02 KB
/
ImageResolution.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* Image Resolution
*
* From: https://github.com/PokemonAutomation/Arduino-Source
*
*/
#include <ostream>
#include "ImageResolution.h"
namespace PokemonAutomation{
std::string Resolution::to_string() const{
return std::to_string(width) + " x " + std::to_string(height);
}
std::ostream& operator<<(std::ostream& os, const Resolution& resolution){
os << resolution.width << " x " << resolution.height;
return os;
}
std::string aspect_ratio_as_string(const Resolution& resolution){
size_t w = resolution.width;
size_t h = resolution.height;
if (w <= 0 || h <= 0){
return "";
}
size_t gcd;
while (true){
if (h == 0){
gcd = w;
break;
}
w %= h;
if (w == 0){
gcd = h;
break;
}
h %= w;
}
w = resolution.width;
h = resolution.height;
w /= gcd;
h /= gcd;
return "(" + std::to_string(w) + ":" + std::to_string(h) + ")";
}
}