1#include "Foundation/Logging/Logger.h"
4#include "Serialization/JsonParser.h"
6#include "Image360System.h"
10 using namespace Cogs::Core::Image360;
14 bool parseJsonChannel(
Config& config,
const Value& channelJson)
16 if (!channelJson.IsObject()) {
17 LOG_ERROR(logger,
"json: channel item not an object");
23 for (
const auto& channelMemberJson : channelJson.GetObject()) {
25 switch (channelMemberName.
hash()) {
29 if (channelMemberJson.value.IsString()) {
31 switch (dataTypeJson.
hash()) {
33 channel.dataType =
Config::Channel::DataType::SRGB8_JPEG;
36 channel.dataType =
Config::Channel::DataType::SRGB8_PNG;
39 channel.dataType =
Config::Channel::DataType::SRGBA8_PNG;
42 channel.dataType =
Config::Channel::DataType::U16;
45 channel.dataType =
Config::Channel::DataType::U16_ZST;
48 LOG_ERROR(logger,
"json: unrecognized channel item member 'dataType' value '%.*s'", StringViewFormat(dataTypeJson));
53 LOG_ERROR(logger,
"json: channel item member 'dataType' is not a string");
59 if (channelMemberJson.value.IsString() && channelMemberJson.value.GetStringLength() != 0) {
60 channel.prefix = channelMemberJson.value.GetString();
61 if (Cogs::IO::isRelative(channel.prefix)) {
62 channel.prefix = Cogs::IO::combine(config.rootPath, channel.prefix);
66 LOG_ERROR(logger,
"json: channel item member 'prefix' is not a nonempty string");
72 if (channelMemberJson.value.IsFloat()) {
73 channel.scale = channelMemberJson.value.GetFloat();
76 LOG_ERROR(logger,
"json: channel item member 'scale' is not a float");
82 if (channelMemberJson.value.IsFloat()) {
83 channel.bias = channelMemberJson.value.GetFloat();
86 LOG_ERROR(logger,
"json: channel item member 'bias' is not a float");
92 LOG_ERROR(logger,
"json: unexpected channel member %.*s", StringViewFormat(channelMemberName));
97 if (channel.dataType == Config::Channel::DataType::None) {
98 LOG_ERROR(logger,
"json: channel missing compulsory member 'dataType");
101 if (channel.prefix.empty()) {
102 LOG_ERROR(logger,
"json: channel missing compulsory member 'prefix");
106 config.
channels.emplace_back(std::move(channel));
116 if (doc.HasParseError()) {
117 LOG_ERROR(logger,
"json: malformed document");
121 if (!doc.IsObject()) {
122 LOG_ERROR(logger,
"json: document root is not an object");
126 rootPath = IO::parentPath(contents->origin());
128 for (
const auto& rootMemberJson : doc.GetObject()) {
130 switch (rootMemberName.
hash()) {
132 if (rootMemberJson.value.IsUint() && rootMemberJson.value.GetUint() != 0) {
133 baseSize = rootMemberJson.value.GetUint();
136 LOG_ERROR(logger,
"json: root member 'baseSize' not a nonzero uint");
141 if (rootMemberJson.value.IsUint() && rootMemberJson.value.GetUint() != 0) {
142 treeDepth = rootMemberJson.value.GetUint();
145 LOG_ERROR(logger,
"json: root member 'treeDepth' not a nonzero uint");
150 if (rootMemberJson.value.IsFloat() && 0.f < rootMemberJson.value.GetFloat()) {
151 extent = rootMemberJson.value.GetFloat();
154 LOG_ERROR(logger,
"json: root member 'extent' not a positive float");
159 if (rootMemberJson.value.IsUint() && rootMemberJson.value.GetUint() < 256) {
160 depthChannel = uint8_t(rootMemberJson.value.GetUint());
163 LOG_ERROR(logger,
"json: root member 'depthChannel' not a byte-valued uint");
168 if (rootMemberJson.value.IsUint()) {
169 noDataDepth = rootMemberJson.value.GetUint();
172 LOG_ERROR(logger,
"json: root member 'noDataDepth' not an uint");
177 if (rootMemberJson.value.IsBool()) {
178 discardNoDepth = rootMemberJson.value.GetBool();
181 LOG_ERROR(logger,
"json: root member 'discardNoDepth' not a bool");
186 if (rootMemberJson.value.IsArray()) {
187 for (
const auto& channelJson : rootMemberJson.value.GetArray()) {
188 if (!parseJsonChannel(*
this, channelJson))
return false;
192 LOG_ERROR(logger,
"json: root member 'channels' not an array");
197 LOG_ERROR(logger,
"json: unexpected root member %.*s", StringViewFormat(rootMemberName));
203 LOG_ERROR(logger,
"json: root missing compulsory member 'baseSize");
206 if (treeDepth == 0) {
207 LOG_ERROR(logger,
"json: root missing compulsory member 'treeDepth");
210 if (channels.empty()) {
211 LOG_ERROR(logger,
"json: root missing compulsory member 'channels");
Log implementation class.
Provides a weakly referenced view over the contents of a string.
constexpr size_t hash() const noexcept
Get the hash code of the string.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
constexpr Log getLogger(const char(&name)[LEN]) noexcept
constexpr size_t hash() noexcept
Simple getter function that returns the initial value for fnv1a hashing.
std::vector< Channel > channels
Data channels to use. From json.
Abstract base class storing data read from a file.
size_t size
Number of data bytes.
const uint8_t * ptr
Start of buffer storing file data. Use.