From e0490d6ebfa236c27716bb52bc692ede4455f9ad Mon Sep 17 00:00:00 2001 From: Fabio Pellacini Date: Mon, 21 Jun 2021 00:52:26 +0200 Subject: [PATCH 1/4] fix --- libs/yocto/yocto_commonio.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/yocto/yocto_commonio.h b/libs/yocto/yocto_commonio.h index f5e6d0566..c9affcda6 100644 --- a/libs/yocto/yocto_commonio.h +++ b/libs/yocto/yocto_commonio.h @@ -40,6 +40,7 @@ // ----------------------------------------------------------------------------- #include +#include #include #include #include From 744bc95f36dfdbcd6195f62a4d874756e8ecd594 Mon Sep 17 00:00:00 2001 From: Fabio Pellacini Date: Mon, 21 Jun 2021 00:58:48 +0200 Subject: [PATCH 2/4] updated --- libs/yocto/yocto_sceneio.cpp | 69 ++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/libs/yocto/yocto_sceneio.cpp b/libs/yocto/yocto_sceneio.cpp index 92d26bf45..665b01383 100644 --- a/libs/yocto/yocto_sceneio.cpp +++ b/libs/yocto/yocto_sceneio.cpp @@ -67,41 +67,42 @@ using namespace std::string_literals; // ----------------------------------------------------------------------------- namespace yocto { -// Pfm load -static float* load_pfm( - const string& filename, int* width, int* height, int* components, int req) { - auto swap_endian = [](auto value) { - // https://stackoverflow.com/questions/105252/how-do-i-convert-between-big-endian-and-little-endian-values-in-c - static_assert(sizeof(char) == 1, "sizeof(char) == 1"); - using T = decltype(value); - union { - T value; - unsigned char bytes[sizeof(T)]; - } source, dest; - source.value = value; - for (auto k = (size_t)0; k < sizeof(T); k++) - dest.bytes[k] = source.bytes[sizeof(T) - k - 1]; - return dest.value; - }; +template +static T _load_pfm_swap_endian(T value) { + // https://stackoverflow.com/questions/105252/how-do-i-convert-between-big-endian-and-little-endian-values-in-c + static_assert(sizeof(char) == 1, "sizeof(char) == 1"); + using T = decltype(value); + union { + T value; + unsigned char bytes[sizeof(T)]; + } source, dest; + source.value = value; + for (auto k = (size_t)0; k < sizeof(T); k++) + dest.bytes[k] = source.bytes[sizeof(T) - k - 1]; + return dest.value; +} - // Split a string - auto split_string = [](const string& str) -> vector { - auto ret = vector(); - if (str.empty()) return ret; - auto lpos = (size_t)0; - while (lpos != string::npos) { - auto pos = str.find_first_of(" \t\n\r", lpos); - if (pos != string::npos) { - if (pos > lpos) ret.push_back(str.substr(lpos, pos - lpos)); - lpos = pos + 1; - } else { - if (lpos < str.size()) ret.push_back(str.substr(lpos)); - lpos = pos; - } +// Split a string +static vector _load_pfm_split_string(const string& str) { + auto ret = vector(); + if (str.empty()) return ret; + auto lpos = (size_t)0; + while (lpos != string::npos) { + auto pos = str.find_first_of(" \t\n\r", lpos); + if (pos != string::npos) { + if (pos > lpos) ret.push_back(str.substr(lpos, pos - lpos)); + lpos = pos + 1; + } else { + if (lpos < str.size()) ret.push_back(str.substr(lpos)); + lpos = pos; } - return ret; - }; + } + return ret; +} +// Pfm load +static float* load_pfm( + const string& filename, int* width, int* height, int* components, int req) { auto fs = fopen_utf8(filename, "rb"); auto fs_guard = unique_ptr(fs, &fclose); if (!fs) return nullptr; @@ -112,7 +113,7 @@ static float* load_pfm( // read magic if (!fgets(buffer.data(), (int)buffer.size(), fs)) return nullptr; - toks = split_string(buffer.data()); + toks = _load_pfm_split_string(buffer.data()); if (toks[0] == "Pf") { *components = 1; } else if (toks[0] == "PF") { @@ -144,7 +145,7 @@ static float* load_pfm( // endian conversion if (s > 0) { for (auto i = (size_t)0; i < nvalues; ++i) { - pixels[i] = swap_endian(pixels[i]); + pixels[i] = _load_pfm_swap_endian(pixels[i]); } } From 5159e2b1f83b53d1bfd1632b150cb852b1239b82 Mon Sep 17 00:00:00 2001 From: Fabio Pellacini Date: Mon, 21 Jun 2021 01:00:39 +0200 Subject: [PATCH 3/4] updatedd --- libs/yocto/yocto_sceneio.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/yocto/yocto_sceneio.cpp b/libs/yocto/yocto_sceneio.cpp index 665b01383..19f602946 100644 --- a/libs/yocto/yocto_sceneio.cpp +++ b/libs/yocto/yocto_sceneio.cpp @@ -71,7 +71,6 @@ template static T _load_pfm_swap_endian(T value) { // https://stackoverflow.com/questions/105252/how-do-i-convert-between-big-endian-and-little-endian-values-in-c static_assert(sizeof(char) == 1, "sizeof(char) == 1"); - using T = decltype(value); union { T value; unsigned char bytes[sizeof(T)]; @@ -124,13 +123,13 @@ static float* load_pfm( // read width, height if (!fgets(buffer.data(), (int)buffer.size(), fs)) return nullptr; - toks = split_string(buffer.data()); + toks = _load_pfm_split_string(buffer.data()); *width = atoi(toks[0].c_str()); *height = atoi(toks[1].c_str()); // read scale if (!fgets(buffer.data(), (int)buffer.size(), fs)) return nullptr; - toks = split_string(buffer.data()); + toks = _load_pfm_split_string(buffer.data()); auto s = (float)atof(toks[0].c_str()); // read the data (flip y) From 8b71940123312ecea6d1cbec52866309eea4f6fa Mon Sep 17 00:00:00 2001 From: Fabio Pellacini Date: Mon, 21 Jun 2021 01:05:53 +0200 Subject: [PATCH 4/4] updated --- libs/yocto/yocto_cli.cpp | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/libs/yocto/yocto_cli.cpp b/libs/yocto/yocto_cli.cpp index e1656008c..8dd957f76 100644 --- a/libs/yocto/yocto_cli.cpp +++ b/libs/yocto/yocto_cli.cpp @@ -32,31 +32,9 @@ #include "yocto_cli.h" -#include -#include +#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include - -// ----------------------------------------------------------------------------- -// USING DIRECTIVES -// ----------------------------------------------------------------------------- -namespace yocto { - -// using directives -using std::array; -using std::pair; -using std::string; -using namespace std::string_literals; - -} // namespace yocto // ----------------------------------------------------------------------------- // PRINT/FORMATTING UTILITIES