Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation fix #1250

Merged
merged 4 commits into from
Jun 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions libs/yocto/yocto_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,9 @@

#include "yocto_cli.h"

#include <array>
#include <charconv>
#include <algorithm>
#include <chrono>
#include <cstdio>
#include <filesystem>
#include <fstream>
#include <memory>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

// -----------------------------------------------------------------------------
// 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
Expand Down
1 change: 1 addition & 0 deletions libs/yocto/yocto_commonio.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
// -----------------------------------------------------------------------------

#include <array>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <vector>
Expand Down
72 changes: 36 additions & 36 deletions libs/yocto/yocto_sceneio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,41 +67,41 @@ 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 <typename T>
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");
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<string> {
auto ret = vector<string>();
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<string> _load_pfm_split_string(const string& str) {
auto ret = vector<string>();
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<FILE, int (*)(FILE*)>(fs, &fclose);
if (!fs) return nullptr;
Expand All @@ -112,7 +112,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") {
Expand All @@ -123,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)
Expand All @@ -144,7 +144,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]);
}
}

Expand Down