diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-10-03 18:49:22 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-10-03 18:49:22 -0400 |
commit | bbe36a8246041544d6ebe420dfa1b695b6c74521 (patch) | |
tree | aa2c607b812c04afd2ef4a240489e7c8adec7c3b /util.hpp | |
parent | c7a958a3bb241b28c766faa3db6f4ff1876bd065 (diff) | |
download | abaddon-portaudio-bbe36a8246041544d6ebe420dfa1b695b6c74521.tar.gz abaddon-portaudio-bbe36a8246041544d6ebe420dfa1b695b6c74521.zip |
maybe slightly better image loading maybe hopefully
Diffstat (limited to 'util.hpp')
-rw-r--r-- | util.hpp | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -29,6 +29,37 @@ inline void LaunchBrowser(std::string url) { #endif } +inline void GetImageDimensions(int inw, int inh, int &outw, int &outh, int clampw = 400, int clamph = 300) { + const auto frac = static_cast<float>(inw) / inh; + + outw = inw; + outh = inh; + + if (outw > clampw) { + outw = clampw; + outh = clampw / frac; + } + + if (outh > clamph) { + outh = clamph; + outw = clamph * frac; + } +} + +inline std::vector<uint8_t> ReadWholeFile(std::string path) { + std::vector<uint8_t> ret; + FILE *fp = std::fopen(path.c_str(), "rb"); + if (fp == nullptr) + return ret; + std::fseek(fp, 0, SEEK_END); + int len = std::ftell(fp); + std::rewind(fp); + ret.resize(len); + std::fread(ret.data(), 1, ret.size(), fp); + std::fclose(fp); + return ret; +} + inline std::string HumanReadableBytes(uint64_t bytes) { constexpr static const char *x[] = { "B", "KB", "MB", "GB", "TB" }; int order = 0; |