Lines 30-1217
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Link Here
|
30 |
|
30 |
|
31 |
#include <OpenColorIO/OpenColorIO.h> |
31 |
#include <OpenColorIO/OpenColorIO.h> |
32 |
|
32 |
|
|
|
33 |
#ifndef WINDOWS |
34 |
|
35 |
// fwd declare yaml-cpp visibility |
36 |
#pragma GCC visibility push(hidden) |
37 |
namespace YAML { |
38 |
class Exception; |
39 |
class BadDereference; |
40 |
class RepresentationException; |
41 |
class EmitterException; |
42 |
class ParserException; |
43 |
class InvalidScalar; |
44 |
class KeyNotFound; |
45 |
template <typename T> class TypedKeyNotFound; |
46 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::ColorSpace>; |
47 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::Config>; |
48 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::Exception>; |
49 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::GpuShaderDesc>; |
50 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::ImageDesc>; |
51 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::Look>; |
52 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::Processor>; |
53 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::Transform>; |
54 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::AllocationTransform>; |
55 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::CDLTransform>; |
56 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::ColorSpaceTransform>; |
57 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::DisplayTransform>; |
58 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::ExponentTransform>; |
59 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::FileTransform>; |
60 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::GroupTransform>; |
61 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::LogTransform>; |
62 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::LookTransform>; |
63 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::MatrixTransform>; |
64 |
template <> class TypedKeyNotFound<OCIO_NAMESPACE::TruelightTransform>; |
65 |
} |
66 |
#pragma GCC visibility pop |
67 |
|
68 |
#endif |
69 |
|
70 |
#include <yaml-cpp/yaml.h> |
71 |
|
33 |
#include "Logging.h" |
72 |
#include "Logging.h" |
34 |
#include "MathUtils.h" |
73 |
#include "MathUtils.h" |
|
|
74 |
#include "pystring/pystring.h" |
75 |
#include "PathUtils.h" |
76 |
#include "ParseUtils.h" |
77 |
#include "Display.h" |
35 |
#include "OCIOYaml.h" |
78 |
#include "OCIOYaml.h" |
36 |
|
79 |
|
37 |
OCIO_NAMESPACE_ENTER |
80 |
OCIO_NAMESPACE_ENTER |
38 |
{ |
81 |
{ |
39 |
/////////////////////////////////////////////////////////////////////////// |
|
|
40 |
// Core |
41 |
|
82 |
|
42 |
void LogUnknownKeyWarning(const std::string & name, const YAML::Node& tag) |
83 |
namespace |
43 |
{ |
84 |
{ |
44 |
std::string key; |
|
|
45 |
tag >> key; |
46 |
|
47 |
std::ostringstream os; |
48 |
os << "Unknown key in " << name << ": "; |
49 |
os << "'" << key << "'. (line "; |
50 |
os << (tag.GetMark().line+1) << ", column "; // (yaml line numbers start at 0) |
51 |
os << tag.GetMark().column << ")"; |
52 |
LogWarning(os.str()); |
53 |
} |
54 |
|
85 |
|
55 |
void operator >> (const YAML::Node& node, ColorSpaceRcPtr& cs) |
86 |
#ifdef OLDYAML |
56 |
{ |
87 |
typedef YAML::Iterator Iterator; |
57 |
if(node.Tag() != "ColorSpace") |
88 |
#else |
58 |
return; // not a !<ColorSpace> tag |
89 |
typedef YAML::const_iterator Iterator; |
59 |
|
90 |
#endif |
60 |
std::string key, stringval; |
91 |
|
61 |
bool boolval; |
92 |
// Iterator access |
62 |
|
93 |
// Note: The ownership semantics have changed between yaml-cpp 0.3.x and 0.5.x . |
63 |
for (YAML::Iterator iter = node.begin(); |
94 |
// Returning a const reference to a yaml node screws with the internal yaml-cpp smart ptr |
64 |
iter != node.end(); |
95 |
// implementation in the newer version. Luckily, the compiler does not care if we maintain |
65 |
++iter) |
96 |
// const YAML::Node & = get_first(iter) syntax at the call site even when returning an actual object |
|
|
97 |
// (instead of the reference as expected). |
98 |
#ifdef OLDYAML |
99 |
inline const YAML::Node& get_first(const Iterator &it) |
66 |
{ |
100 |
{ |
67 |
iter.first() >> key; |
101 |
return it.first(); |
68 |
|
|
|
69 |
if(key == "name") |
70 |
{ |
71 |
if (iter.second().Type() != YAML::NodeType::Null && |
72 |
iter.second().Read<std::string>(stringval)) |
73 |
cs->setName(stringval.c_str()); |
74 |
} |
75 |
else if(key == "description") |
76 |
{ |
77 |
if (iter.second().Type() != YAML::NodeType::Null && |
78 |
iter.second().Read<std::string>(stringval)) |
79 |
cs->setDescription(stringval.c_str()); |
80 |
} |
81 |
else if(key == "family") |
82 |
{ |
83 |
if (iter.second().Type() != YAML::NodeType::Null && |
84 |
iter.second().Read<std::string>(stringval)) |
85 |
cs->setFamily(stringval.c_str()); |
86 |
} |
87 |
else if(key == "equalitygroup") |
88 |
{ |
89 |
if (iter.second().Type() != YAML::NodeType::Null && |
90 |
iter.second().Read<std::string>(stringval)) |
91 |
cs->setEqualityGroup(stringval.c_str()); |
92 |
} |
93 |
else if(key == "bitdepth") |
94 |
{ |
95 |
BitDepth ret; |
96 |
if (iter.second().Type() != YAML::NodeType::Null && |
97 |
iter.second().Read<BitDepth>(ret)) |
98 |
cs->setBitDepth(ret); |
99 |
} |
100 |
else if(key == "isdata") |
101 |
{ |
102 |
if (iter.second().Type() != YAML::NodeType::Null && |
103 |
iter.second().Read<bool>(boolval)) |
104 |
cs->setIsData(boolval); |
105 |
} |
106 |
else if(key == "allocation") |
107 |
{ |
108 |
Allocation val; |
109 |
if (iter.second().Type() != YAML::NodeType::Null && |
110 |
iter.second().Read<Allocation>(val)) |
111 |
cs->setAllocation(val); |
112 |
} |
113 |
else if(key == "allocationvars") |
114 |
{ |
115 |
std::vector<float> val; |
116 |
if (iter.second().Type() != YAML::NodeType::Null) |
117 |
{ |
118 |
iter.second() >> val; |
119 |
if(!val.empty()) |
120 |
{ |
121 |
cs->setAllocationVars(static_cast<int>(val.size()), &val[0]); |
122 |
} |
123 |
} |
124 |
} |
125 |
else if(key == "to_reference") |
126 |
{ |
127 |
TransformRcPtr val; |
128 |
if (iter.second().Type() != YAML::NodeType::Null && |
129 |
iter.second().Read<TransformRcPtr>(val)) |
130 |
cs->setTransform(val, COLORSPACE_DIR_TO_REFERENCE); |
131 |
} |
132 |
else if(key == "from_reference") |
133 |
{ |
134 |
TransformRcPtr val; |
135 |
if (iter.second().Type() != YAML::NodeType::Null && |
136 |
iter.second().Read<TransformRcPtr>(val)) |
137 |
cs->setTransform(val, COLORSPACE_DIR_FROM_REFERENCE); |
138 |
} |
139 |
else |
140 |
{ |
141 |
LogUnknownKeyWarning(node.Tag(), iter.first()); |
142 |
} |
143 |
} |
102 |
} |
144 |
} |
103 |
#else |
145 |
|
104 |
inline YAML::Node get_first(const Iterator &it) |
146 |
YAML::Emitter& operator << (YAML::Emitter& out, ColorSpaceRcPtr cs) |
|
|
147 |
{ |
148 |
out << YAML::VerbatimTag("ColorSpace"); |
149 |
out << YAML::BeginMap; |
150 |
|
151 |
out << YAML::Key << "name" << YAML::Value << cs->getName(); |
152 |
out << YAML::Key << "family" << YAML::Value << cs->getFamily(); |
153 |
out << YAML::Key << "equalitygroup" << YAML::Value << cs->getEqualityGroup(); |
154 |
out << YAML::Key << "bitdepth" << YAML::Value << cs->getBitDepth(); |
155 |
if(strlen(cs->getDescription()) > 0) |
156 |
{ |
105 |
{ |
157 |
out << YAML::Key << "description"; |
106 |
return it->first; |
158 |
out << YAML::Value << YAML::Literal << cs->getDescription(); |
|
|
159 |
} |
107 |
} |
160 |
out << YAML::Key << "isdata" << YAML::Value << cs->isData(); |
108 |
#endif |
161 |
|
109 |
|
162 |
out << YAML::Key << "allocation" << YAML::Value << cs->getAllocation(); |
110 |
#ifdef OLDYAML |
163 |
if(cs->getAllocationNumVars() > 0) |
111 |
inline const YAML::Node& get_second(const Iterator &it) |
164 |
{ |
112 |
{ |
165 |
std::vector<float> allocationvars(cs->getAllocationNumVars()); |
113 |
return it.second(); |
166 |
cs->getAllocationVars(&allocationvars[0]); |
|
|
167 |
out << YAML::Key << "allocationvars"; |
168 |
out << YAML::Flow << YAML::Value << allocationvars; |
169 |
} |
114 |
} |
|
|
115 |
#else |
116 |
inline YAML::Node get_second(const Iterator &it) |
117 |
{ |
118 |
return it->second; |
119 |
} |
120 |
#endif |
170 |
|
121 |
|
171 |
ConstTransformRcPtr toref = \ |
122 |
// Basic types |
172 |
cs->getTransform(COLORSPACE_DIR_TO_REFERENCE); |
|
|
173 |
if(toref) |
174 |
out << YAML::Key << "to_reference" << YAML::Value << toref; |
175 |
|
176 |
ConstTransformRcPtr fromref = \ |
177 |
cs->getTransform(COLORSPACE_DIR_FROM_REFERENCE); |
178 |
if(fromref) |
179 |
out << YAML::Key << "from_reference" << YAML::Value << fromref; |
180 |
|
181 |
out << YAML::EndMap; |
182 |
out << YAML::Newline; |
183 |
|
184 |
return out; |
185 |
} |
186 |
|
187 |
|
188 |
/////////////////////////////////////////////////////////////////////////// |
189 |
|
190 |
// Look. (not the transform, the top-level class) |
191 |
|
192 |
void operator >> (const YAML::Node& node, LookRcPtr& look) |
193 |
{ |
194 |
if(node.Tag() != "Look") |
195 |
return; |
196 |
|
197 |
std::string key, stringval; |
198 |
|
123 |
|
199 |
for (YAML::Iterator iter = node.begin(); |
124 |
inline void load(const YAML::Node& node, bool& x) |
200 |
iter != node.end(); |
|
|
201 |
++iter) |
202 |
{ |
125 |
{ |
203 |
iter.first() >> key; |
126 |
#ifdef OLDYAML |
204 |
|
127 |
node.Read<bool>(x); |
205 |
if(key == "name") |
128 |
#else |
206 |
{ |
129 |
x = node.as<bool>(); |
207 |
if (iter.second().Type() != YAML::NodeType::Null && |
130 |
#endif |
208 |
iter.second().Read<std::string>(stringval)) |
|
|
209 |
look->setName(stringval.c_str()); |
210 |
} |
211 |
else if(key == "process_space") |
212 |
{ |
213 |
if (iter.second().Type() != YAML::NodeType::Null && |
214 |
iter.second().Read<std::string>(stringval)) |
215 |
look->setProcessSpace(stringval.c_str()); |
216 |
} |
217 |
else if(key == "transform") |
218 |
{ |
219 |
TransformRcPtr val; |
220 |
if (iter.second().Type() != YAML::NodeType::Null && |
221 |
iter.second().Read<TransformRcPtr>(val)) |
222 |
look->setTransform(val); |
223 |
} |
224 |
else if(key == "inverse_transform") |
225 |
{ |
226 |
TransformRcPtr val; |
227 |
if (iter.second().Type() != YAML::NodeType::Null && |
228 |
iter.second().Read<TransformRcPtr>(val)) |
229 |
look->setInverseTransform(val); |
230 |
} |
231 |
else |
232 |
{ |
233 |
LogUnknownKeyWarning(node.Tag(), iter.first()); |
234 |
} |
235 |
} |
131 |
} |
236 |
} |
|
|
237 |
|
238 |
YAML::Emitter& operator << (YAML::Emitter& out, LookRcPtr look) |
239 |
{ |
240 |
out << YAML::VerbatimTag("Look"); |
241 |
out << YAML::BeginMap; |
242 |
out << YAML::Key << "name" << YAML::Value << look->getName(); |
243 |
out << YAML::Key << "process_space" << YAML::Value << look->getProcessSpace(); |
244 |
|
132 |
|
245 |
if(look->getTransform()) |
133 |
inline void load(const YAML::Node& node, int& x) |
246 |
{ |
134 |
{ |
247 |
out << YAML::Key << "transform"; |
135 |
#ifdef OLDYAML |
248 |
out << YAML::Value << look->getTransform(); |
136 |
node.Read<int>(x); |
|
|
137 |
#else |
138 |
x = node.as<int>(); |
139 |
#endif |
249 |
} |
140 |
} |
250 |
|
141 |
|
251 |
if(look->getInverseTransform()) |
142 |
inline void load(const YAML::Node& node, float& x) |
252 |
{ |
143 |
{ |
253 |
out << YAML::Key << "inverse_transform"; |
144 |
#ifdef OLDYAML |
254 |
out << YAML::Value << look->getInverseTransform(); |
145 |
node.Read<float>(x); |
|
|
146 |
#else |
147 |
x = node.as<float>(); |
148 |
#endif |
255 |
} |
149 |
} |
256 |
|
150 |
|
257 |
out << YAML::EndMap; |
151 |
inline void load(const YAML::Node& node, std::string& x) |
258 |
out << YAML::Newline; |
152 |
{ |
|
|
153 |
#ifdef OLDYAML |
154 |
node.Read<std::string>(x); |
155 |
#else |
156 |
x = node.as<std::string>(); |
157 |
#endif |
158 |
} |
259 |
|
159 |
|
260 |
return out; |
160 |
inline void load(const YAML::Node& node, std::vector<std::string>& x) |
261 |
} |
|
|
262 |
|
263 |
|
264 |
|
265 |
/////////////////////////////////////////////////////////////////////////// |
266 |
|
267 |
|
268 |
namespace |
269 |
{ |
270 |
void EmitBaseTransformKeyValues(YAML::Emitter & out, |
271 |
const ConstTransformRcPtr & t) |
272 |
{ |
161 |
{ |
273 |
if(t->getDirection() != TRANSFORM_DIR_FORWARD) |
162 |
#ifdef OLDYAML |
274 |
{ |
163 |
node >> x; |
275 |
out << YAML::Key << "direction"; |
164 |
#else |
276 |
out << YAML::Value << YAML::Flow << t->getDirection(); |
165 |
x = node.as<std::vector<std::string> >(); |
277 |
} |
166 |
#endif |
278 |
} |
167 |
} |
279 |
} |
168 |
|
280 |
|
169 |
inline void load(const YAML::Node& node, std::vector<float>& x) |
281 |
void operator >> (const YAML::Node& node, TransformRcPtr& t) |
|
|
282 |
{ |
283 |
if(node.Type() != YAML::NodeType::Map) |
284 |
{ |
170 |
{ |
285 |
std::ostringstream os; |
171 |
#ifdef OLDYAML |
286 |
os << "Unsupported Transform type encountered: (" << node.Type() << ") in OCIO profile. "; |
172 |
node >> x; |
287 |
os << "Only Mapping types supported. (line "; |
173 |
#else |
288 |
os << (node.GetMark().line+1) << ", column "; // (yaml line numbers start at 0) |
174 |
x = node.as<std::vector<float> >(); |
289 |
os << node.GetMark().column << ")"; |
175 |
#endif |
290 |
throw Exception(os.str().c_str()); |
|
|
291 |
} |
176 |
} |
292 |
|
177 |
|
293 |
std::string type = node.Tag(); |
178 |
// Enums |
294 |
|
179 |
|
295 |
if(type == "AllocationTransform") { |
180 |
inline void load(const YAML::Node& node, BitDepth& depth) |
296 |
AllocationTransformRcPtr temp; |
181 |
{ |
297 |
node.Read<AllocationTransformRcPtr>(temp); |
182 |
std::string str; |
298 |
t = temp; |
183 |
load(node, str); |
|
|
184 |
depth = BitDepthFromString(str.c_str()); |
299 |
} |
185 |
} |
300 |
else if(type == "CDLTransform") { |
186 |
|
301 |
CDLTransformRcPtr temp; |
187 |
inline void save(YAML::Emitter& out, BitDepth depth) |
302 |
node.Read<CDLTransformRcPtr>(temp); |
188 |
{ |
303 |
t = temp; |
189 |
out << BitDepthToString(depth); |
304 |
} |
190 |
} |
305 |
else if(type == "ColorSpaceTransform") { |
191 |
|
306 |
ColorSpaceTransformRcPtr temp; |
192 |
inline void load(const YAML::Node& node, Allocation& alloc) |
307 |
node.Read<ColorSpaceTransformRcPtr>(temp); |
193 |
{ |
308 |
t = temp; |
194 |
std::string str; |
|
|
195 |
load(node, str); |
196 |
alloc = AllocationFromString(str.c_str()); |
309 |
} |
197 |
} |
310 |
// TODO: DisplayTransform |
198 |
|
311 |
else if(type == "ExponentTransform") { |
199 |
inline void save(YAML::Emitter& out, Allocation alloc) |
312 |
ExponentTransformRcPtr temp; |
200 |
{ |
313 |
node.Read<ExponentTransformRcPtr>(temp); |
201 |
out << AllocationToString(alloc); |
314 |
t = temp; |
|
|
315 |
} |
202 |
} |
316 |
else if(type == "FileTransform") { |
203 |
|
317 |
FileTransformRcPtr temp; |
204 |
inline void load(const YAML::Node& node, ColorSpaceDirection& dir) |
318 |
node.Read<FileTransformRcPtr>(temp); |
205 |
{ |
319 |
t = temp; |
206 |
std::string str; |
|
|
207 |
load(node, str); |
208 |
dir = ColorSpaceDirectionFromString(str.c_str()); |
320 |
} |
209 |
} |
321 |
else if(type == "GroupTransform") { |
210 |
|
322 |
GroupTransformRcPtr temp; |
211 |
inline void save(YAML::Emitter& out, ColorSpaceDirection dir) |
323 |
node.Read<GroupTransformRcPtr>(temp); |
212 |
{ |
324 |
t = temp; |
213 |
out << ColorSpaceDirectionToString(dir); |
325 |
} |
214 |
} |
326 |
else if(type == "LogTransform") { |
215 |
|
327 |
LogTransformRcPtr temp; |
216 |
inline void load(const YAML::Node& node, TransformDirection& dir) |
328 |
node.Read<LogTransformRcPtr>(temp); |
217 |
{ |
329 |
t = temp; |
218 |
std::string str; |
|
|
219 |
load(node, str); |
220 |
dir = TransformDirectionFromString(str.c_str()); |
330 |
} |
221 |
} |
331 |
else if(type == "LookTransform") { |
222 |
|
332 |
LookTransformRcPtr temp; |
223 |
inline void save(YAML::Emitter& out, TransformDirection dir) |
333 |
node.Read<LookTransformRcPtr>(temp); |
224 |
{ |
334 |
t = temp; |
225 |
out << TransformDirectionToString(dir); |
335 |
} |
226 |
} |
336 |
else if(type == "MatrixTransform") { |
227 |
|
337 |
MatrixTransformRcPtr temp; |
228 |
inline void load(const YAML::Node& node, Interpolation& interp) |
338 |
node.Read<MatrixTransformRcPtr>(temp); |
229 |
{ |
339 |
t = temp; |
230 |
std::string str; |
|
|
231 |
load(node, str); |
232 |
interp = InterpolationFromString(str.c_str()); |
340 |
} |
233 |
} |
341 |
else if(type == "TruelightTransform") { |
234 |
|
342 |
TruelightTransformRcPtr temp; |
235 |
inline void save(YAML::Emitter& out, Interpolation interp) |
343 |
node.Read<TruelightTransformRcPtr>(temp); |
236 |
{ |
344 |
t = temp; |
237 |
out << InterpolationToString(interp); |
345 |
} |
238 |
} |
346 |
else |
239 |
|
|
|
240 |
// |
241 |
|
242 |
inline void LogUnknownKeyWarning(const std::string & name, |
243 |
const YAML::Node& tag) |
347 |
{ |
244 |
{ |
348 |
// TODO: add a new empty (better name?) aka passthru Transform() |
245 |
std::string key; |
349 |
// which does nothing. This is so upsupported !<tag> types don't |
246 |
load(tag, key); |
350 |
// throw an exception. Alternativly this could be caught in the |
247 |
|
351 |
// GroupTransformRcPtr >> operator with some type of |
|
|
352 |
// supported_tag() method |
353 |
|
354 |
// TODO: consider the forwards-compatibility implication of |
355 |
// throwing an exception. Should this be a warning, instead? |
356 |
|
357 |
// t = EmptyTransformRcPtr(new EmptyTransform(), &deleter); |
358 |
std::ostringstream os; |
248 |
std::ostringstream os; |
359 |
os << "Unsupported transform type !<" << type << "> in OCIO profile. "; |
249 |
os << "Unknown key in " << name << ": '" << key << "'."; |
360 |
os << " (line "; |
250 |
LogWarning(os.str()); |
361 |
os << (node.GetMark().line+1) << ", column "; // (yaml line numbers start at 0) |
|
|
362 |
os << node.GetMark().column << ")"; |
363 |
throw Exception(os.str().c_str()); |
364 |
} |
251 |
} |
365 |
} |
|
|
366 |
|
367 |
YAML::Emitter& operator << (YAML::Emitter& out, ConstTransformRcPtr t) |
368 |
{ |
369 |
if(ConstAllocationTransformRcPtr Allocation_tran = \ |
370 |
DynamicPtrCast<const AllocationTransform>(t)) |
371 |
out << Allocation_tran; |
372 |
else if(ConstCDLTransformRcPtr CDL_tran = \ |
373 |
DynamicPtrCast<const CDLTransform>(t)) |
374 |
out << CDL_tran; |
375 |
else if(ConstColorSpaceTransformRcPtr ColorSpace_tran = \ |
376 |
DynamicPtrCast<const ColorSpaceTransform>(t)) |
377 |
out << ColorSpace_tran; |
378 |
else if(ConstExponentTransformRcPtr Exponent_tran = \ |
379 |
DynamicPtrCast<const ExponentTransform>(t)) |
380 |
out << Exponent_tran; |
381 |
else if(ConstFileTransformRcPtr File_tran = \ |
382 |
DynamicPtrCast<const FileTransform>(t)) |
383 |
out << File_tran; |
384 |
else if(ConstGroupTransformRcPtr Group_tran = \ |
385 |
DynamicPtrCast<const GroupTransform>(t)) |
386 |
out << Group_tran; |
387 |
else if(ConstLogTransformRcPtr Log_tran = \ |
388 |
DynamicPtrCast<const LogTransform>(t)) |
389 |
out << Log_tran; |
390 |
else if(ConstLookTransformRcPtr Look_tran = \ |
391 |
DynamicPtrCast<const LookTransform>(t)) |
392 |
out << Look_tran; |
393 |
else if(ConstMatrixTransformRcPtr Matrix_tran = \ |
394 |
DynamicPtrCast<const MatrixTransform>(t)) |
395 |
out << Matrix_tran; |
396 |
else if(ConstTruelightTransformRcPtr Truelight_tran = \ |
397 |
DynamicPtrCast<const TruelightTransform>(t)) |
398 |
out << Truelight_tran; |
399 |
else |
400 |
throw Exception("Unsupported Transform() type for serialization."); |
401 |
|
402 |
return out; |
403 |
} |
404 |
|
405 |
|
406 |
/////////////////////////////////////////////////////////////////////////// |
407 |
// Transforms |
408 |
|
409 |
void operator >> (const YAML::Node& node, GroupTransformRcPtr& t) |
410 |
{ |
411 |
t = GroupTransform::Create(); |
412 |
|
252 |
|
413 |
std::string key; |
253 |
// View |
414 |
|
254 |
|
415 |
for (YAML::Iterator iter = node.begin(); |
255 |
inline void load(const YAML::Node& node, View& v) |
416 |
iter != node.end(); |
|
|
417 |
++iter) |
418 |
{ |
256 |
{ |
419 |
iter.first() >> key; |
257 |
if(node.Tag() != "View") |
|
|
258 |
return; |
420 |
|
259 |
|
421 |
if(key == "children") |
260 |
std::string key, stringval; |
422 |
{ |
261 |
|
423 |
const YAML::Node & children = iter.second(); |
262 |
for (Iterator iter = node.begin(); |
424 |
for(unsigned i = 0; i <children.size(); ++i) |
263 |
iter != node.end(); |
|
|
264 |
++iter) |
265 |
{ |
266 |
const YAML::Node& first = get_first(iter); |
267 |
const YAML::Node& second = get_second(iter); |
268 |
|
269 |
load(first, key); |
270 |
|
271 |
if (second.Type() == YAML::NodeType::Null) continue; |
272 |
|
273 |
if(key == "name") |
425 |
{ |
274 |
{ |
426 |
TransformRcPtr childTransform; |
275 |
load(second, stringval); |
427 |
children[i].Read<TransformRcPtr>(childTransform); |
276 |
v.name = stringval; |
428 |
|
277 |
} |
429 |
// TODO: consider the forwards-compatibility implication of |
278 |
else if(key == "colorspace") |
430 |
// throwing an exception. Should this be a warning, instead? |
279 |
{ |
431 |
if(!childTransform) |
280 |
load(second, stringval); |
432 |
{ |
281 |
v.colorspace = stringval; |
433 |
throw Exception("Child transform could not be parsed."); |
282 |
} |
434 |
} |
283 |
else if(key == "looks" || key == "look") |
435 |
|
284 |
{ |
436 |
t->push_back(childTransform); |
285 |
load(second, stringval); |
|
|
286 |
v.looks = stringval; |
287 |
} |
288 |
else |
289 |
{ |
290 |
LogUnknownKeyWarning(node.Tag(), first); |
437 |
} |
291 |
} |
438 |
} |
292 |
} |
439 |
else if(key == "direction") |
293 |
|
|
|
294 |
if(v.name.empty()) |
440 |
{ |
295 |
{ |
441 |
TransformDirection val; |
296 |
throw Exception("View does not specify 'name'."); |
442 |
if (iter.second().Type() != YAML::NodeType::Null && |
|
|
443 |
iter.second().Read<TransformDirection>(val)) |
444 |
t->setDirection(val); |
445 |
} |
297 |
} |
446 |
else |
298 |
if(v.colorspace.empty()) |
447 |
{ |
299 |
{ |
448 |
LogUnknownKeyWarning(node.Tag(), iter.first()); |
300 |
std::ostringstream os; |
|
|
301 |
os << "View '" << v.name << "' "; |
302 |
os << "does not specify colorspace."; |
303 |
throw Exception(os.str().c_str()); |
449 |
} |
304 |
} |
450 |
} |
305 |
} |
451 |
} |
|
|
452 |
|
453 |
YAML::Emitter& operator << (YAML::Emitter& out, ConstGroupTransformRcPtr t) |
454 |
{ |
455 |
out << YAML::VerbatimTag("GroupTransform"); |
456 |
out << YAML::BeginMap; |
457 |
EmitBaseTransformKeyValues(out, t); |
458 |
|
306 |
|
459 |
out << YAML::Key << "children"; |
307 |
inline void save(YAML::Emitter& out, View view) |
460 |
out << YAML::Value; |
|
|
461 |
|
462 |
out << YAML::BeginSeq; |
463 |
for(int i = 0; i < t->size(); ++i) |
464 |
{ |
308 |
{ |
465 |
out << t->getTransform(i); |
309 |
out << YAML::VerbatimTag("View"); |
|
|
310 |
out << YAML::Flow; |
311 |
out << YAML::BeginMap; |
312 |
out << YAML::Key << "name" << YAML::Value << view.name; |
313 |
out << YAML::Key << "colorspace" << YAML::Value << view.colorspace; |
314 |
if(!view.looks.empty()) out << YAML::Key << "looks" << YAML::Value << view.looks; |
315 |
out << YAML::EndMap; |
466 |
} |
316 |
} |
467 |
out << YAML::EndSeq; |
|
|
468 |
|
469 |
out << YAML::EndMap; |
470 |
|
471 |
return out; |
472 |
} |
473 |
|
474 |
|
475 |
|
476 |
void operator >> (const YAML::Node& node, FileTransformRcPtr& t) |
477 |
{ |
478 |
t = FileTransform::Create(); |
479 |
|
317 |
|
480 |
std::string key, stringval; |
318 |
// Common Transform |
481 |
|
319 |
|
482 |
for (YAML::Iterator iter = node.begin(); |
320 |
inline void EmitBaseTransformKeyValues(YAML::Emitter & out, |
483 |
iter != node.end(); |
321 |
const ConstTransformRcPtr & t) |
484 |
++iter) |
|
|
485 |
{ |
322 |
{ |
486 |
iter.first() >> key; |
323 |
if(t->getDirection() != TRANSFORM_DIR_FORWARD) |
487 |
|
|
|
488 |
if(key == "src") |
489 |
{ |
490 |
if (iter.second().Type() != YAML::NodeType::Null && |
491 |
iter.second().Read<std::string>(stringval)) |
492 |
t->setSrc(stringval.c_str()); |
493 |
} |
494 |
else if(key == "cccid") |
495 |
{ |
496 |
if (iter.second().Type() != YAML::NodeType::Null && |
497 |
iter.second().Read<std::string>(stringval)) |
498 |
t->setCCCId(stringval.c_str()); |
499 |
} |
500 |
else if(key == "interpolation") |
501 |
{ |
502 |
Interpolation val; |
503 |
if (iter.second().Type() != YAML::NodeType::Null && |
504 |
iter.second().Read<Interpolation>(val)) |
505 |
t->setInterpolation(val); |
506 |
} |
507 |
else if(key == "direction") |
508 |
{ |
509 |
TransformDirection val; |
510 |
if (iter.second().Type() != YAML::NodeType::Null && |
511 |
iter.second().Read<TransformDirection>(val)) |
512 |
t->setDirection(val); |
513 |
} |
514 |
else |
515 |
{ |
324 |
{ |
516 |
LogUnknownKeyWarning(node.Tag(), iter.first()); |
325 |
out << YAML::Key << "direction"; |
|
|
326 |
out << YAML::Value << YAML::Flow; |
327 |
save(out, t->getDirection()); |
517 |
} |
328 |
} |
518 |
} |
329 |
} |
519 |
} |
|
|
520 |
|
521 |
YAML::Emitter& operator << (YAML::Emitter& out, ConstFileTransformRcPtr t) |
522 |
{ |
523 |
out << YAML::VerbatimTag("FileTransform"); |
524 |
out << YAML::Flow << YAML::BeginMap; |
525 |
out << YAML::Key << "src" << YAML::Value << t->getSrc(); |
526 |
const char * cccid = t->getCCCId(); |
527 |
if(cccid && *cccid) |
528 |
{ |
529 |
out << YAML::Key << "cccid" << YAML::Value << t->getCCCId(); |
530 |
} |
531 |
out << YAML::Key << "interpolation"; |
532 |
out << YAML::Value << t->getInterpolation(); |
533 |
|
534 |
EmitBaseTransformKeyValues(out, t); |
535 |
out << YAML::EndMap; |
536 |
return out; |
537 |
} |
538 |
|
539 |
void operator >> (const YAML::Node& node, ColorSpaceTransformRcPtr& t) |
540 |
{ |
541 |
t = ColorSpaceTransform::Create(); |
542 |
|
330 |
|
543 |
std::string key, stringval; |
331 |
// AllocationTransform |
544 |
|
332 |
|
545 |
for (YAML::Iterator iter = node.begin(); |
333 |
inline void load(const YAML::Node& node, AllocationTransformRcPtr& t) |
546 |
iter != node.end(); |
|
|
547 |
++iter) |
548 |
{ |
334 |
{ |
549 |
iter.first() >> key; |
335 |
t = AllocationTransform::Create(); |
550 |
|
336 |
|
551 |
if(key == "src") |
337 |
std::string key; |
552 |
{ |
338 |
|
553 |
if (iter.second().Type() != YAML::NodeType::Null && |
339 |
for (Iterator iter = node.begin(); |
554 |
iter.second().Read<std::string>(stringval)) |
340 |
iter != node.end(); |
555 |
t->setSrc(stringval.c_str()); |
341 |
++iter) |
556 |
} |
342 |
{ |
557 |
else if(key == "dst") |
343 |
const YAML::Node& first = get_first(iter); |
558 |
{ |
344 |
const YAML::Node& second = get_second(iter); |
559 |
if (iter.second().Type() != YAML::NodeType::Null && |
345 |
|
560 |
iter.second().Read<std::string>(stringval)) |
346 |
load(first, key); |
561 |
t->setDst(stringval.c_str()); |
347 |
|
562 |
} |
348 |
if (second.Type() == YAML::NodeType::Null) continue; |
563 |
else if(key == "direction") |
349 |
|
564 |
{ |
350 |
if(key == "allocation") |
565 |
TransformDirection val; |
351 |
{ |
566 |
if (iter.second().Type() != YAML::NodeType::Null && |
352 |
Allocation val; |
567 |
iter.second().Read<TransformDirection>(val)) |
353 |
load(second, val); |
568 |
t->setDirection(val); |
354 |
t->setAllocation(val); |
569 |
} |
355 |
} |
570 |
else |
356 |
else if(key == "vars") |
571 |
{ |
357 |
{ |
572 |
LogUnknownKeyWarning(node.Tag(), iter.first()); |
358 |
std::vector<float> val; |
|
|
359 |
load(second, val); |
360 |
if(!val.empty()) |
361 |
{ |
362 |
t->setVars(static_cast<int>(val.size()), &val[0]); |
363 |
} |
364 |
} |
365 |
else if(key == "direction") |
366 |
{ |
367 |
TransformDirection val; |
368 |
load(second, val); |
369 |
t->setDirection(val); |
370 |
} |
371 |
else |
372 |
{ |
373 |
LogUnknownKeyWarning(node.Tag(), first); |
374 |
} |
573 |
} |
375 |
} |
574 |
} |
376 |
} |
575 |
} |
|
|
576 |
|
577 |
YAML::Emitter& operator << (YAML::Emitter& out, ConstColorSpaceTransformRcPtr t) |
578 |
{ |
579 |
out << YAML::VerbatimTag("ColorSpaceTransform"); |
580 |
out << YAML::Flow << YAML::BeginMap; |
581 |
out << YAML::Key << "src" << YAML::Value << t->getSrc(); |
582 |
out << YAML::Key << "dst" << YAML::Value << t->getDst(); |
583 |
EmitBaseTransformKeyValues(out, t); |
584 |
out << YAML::EndMap; |
585 |
return out; |
586 |
} |
587 |
|
588 |
void operator >> (const YAML::Node& node, LookTransformRcPtr& t) |
589 |
{ |
590 |
t = LookTransform::Create(); |
591 |
|
377 |
|
592 |
std::string key, stringval; |
378 |
inline void save(YAML::Emitter& out, ConstAllocationTransformRcPtr t) |
593 |
|
|
|
594 |
for (YAML::Iterator iter = node.begin(); |
595 |
iter != node.end(); |
596 |
++iter) |
597 |
{ |
379 |
{ |
598 |
iter.first() >> key; |
380 |
out << YAML::VerbatimTag("AllocationTransform"); |
|
|
381 |
out << YAML::Flow << YAML::BeginMap; |
599 |
|
382 |
|
600 |
if(key == "src") |
383 |
out << YAML::Key << "allocation"; |
601 |
{ |
384 |
out << YAML::Value << YAML::Flow; |
602 |
if (iter.second().Type() != YAML::NodeType::Null && |
385 |
save(out, t->getAllocation()); |
603 |
iter.second().Read<std::string>(stringval)) |
386 |
|
604 |
t->setSrc(stringval.c_str()); |
387 |
if(t->getNumVars() > 0) |
605 |
} |
|
|
606 |
else if(key == "dst") |
607 |
{ |
608 |
if (iter.second().Type() != YAML::NodeType::Null && |
609 |
iter.second().Read<std::string>(stringval)) |
610 |
t->setDst(stringval.c_str()); |
611 |
} |
612 |
else if(key == "looks") |
613 |
{ |
614 |
if (iter.second().Type() != YAML::NodeType::Null && |
615 |
iter.second().Read<std::string>(stringval)) |
616 |
t->setLooks(stringval.c_str()); |
617 |
} |
618 |
else if(key == "direction") |
619 |
{ |
620 |
TransformDirection val; |
621 |
if (iter.second().Type() != YAML::NodeType::Null && |
622 |
iter.second().Read<TransformDirection>(val)) |
623 |
t->setDirection(val); |
624 |
} |
625 |
else |
626 |
{ |
388 |
{ |
627 |
LogUnknownKeyWarning(node.Tag(), iter.first()); |
389 |
std::vector<float> vars(t->getNumVars()); |
|
|
390 |
t->getVars(&vars[0]); |
391 |
out << YAML::Key << "vars"; |
392 |
out << YAML::Flow << YAML::Value << vars; |
628 |
} |
393 |
} |
|
|
394 |
|
395 |
EmitBaseTransformKeyValues(out, t); |
396 |
out << YAML::EndMap; |
629 |
} |
397 |
} |
630 |
} |
|
|
631 |
|
632 |
YAML::Emitter& operator << (YAML::Emitter& out, ConstLookTransformRcPtr t) |
633 |
{ |
634 |
out << YAML::VerbatimTag("LookTransform"); |
635 |
out << YAML::Flow << YAML::BeginMap; |
636 |
out << YAML::Key << "src" << YAML::Value << t->getSrc(); |
637 |
out << YAML::Key << "dst" << YAML::Value << t->getDst(); |
638 |
out << YAML::Key << "looks" << YAML::Value << t->getLooks(); |
639 |
EmitBaseTransformKeyValues(out, t); |
640 |
out << YAML::EndMap; |
641 |
return out; |
642 |
} |
643 |
|
644 |
void operator >> (const YAML::Node& node, ExponentTransformRcPtr& t) |
645 |
{ |
646 |
t = ExponentTransform::Create(); |
647 |
|
398 |
|
648 |
std::string key; |
399 |
// CDLTransform |
649 |
|
400 |
|
650 |
for (YAML::Iterator iter = node.begin(); |
401 |
inline void load(const YAML::Node& node, CDLTransformRcPtr& t) |
651 |
iter != node.end(); |
|
|
652 |
++iter) |
653 |
{ |
402 |
{ |
654 |
iter.first() >> key; |
403 |
t = CDLTransform::Create(); |
655 |
|
404 |
|
656 |
if(key == "value") |
405 |
std::string key; |
657 |
{ |
406 |
std::vector<float> floatvecval; |
658 |
std::vector<float> val; |
407 |
|
659 |
if (iter.second().Type() != YAML::NodeType::Null) |
408 |
for (Iterator iter = node.begin(); |
|
|
409 |
iter != node.end(); |
410 |
++iter) |
411 |
{ |
412 |
const YAML::Node& first = get_first(iter); |
413 |
const YAML::Node& second = get_second(iter); |
414 |
|
415 |
load(first, key); |
416 |
|
417 |
if (second.Type() == YAML::NodeType::Null) continue; |
418 |
|
419 |
if(key == "slope") |
660 |
{ |
420 |
{ |
661 |
iter.second() >> val; |
421 |
load(second, floatvecval); |
662 |
if(val.size() != 4) |
422 |
if(floatvecval.size() != 3) |
663 |
{ |
423 |
{ |
664 |
std::ostringstream os; |
424 |
std::ostringstream os; |
665 |
os << "ExponentTransform parse error, value field must be 4 "; |
425 |
os << "CDLTransform parse error, 'slope' field must be 3 "; |
666 |
os << "floats. Found '" << val.size() << "'."; |
426 |
os << "floats. Found '" << floatvecval.size() << "'."; |
667 |
throw Exception(os.str().c_str()); |
427 |
throw Exception(os.str().c_str()); |
668 |
} |
428 |
} |
669 |
t->setValue(&val[0]); |
429 |
t->setSlope(&floatvecval[0]); |
670 |
} |
430 |
} |
671 |
} |
431 |
else if(key == "offset") |
672 |
else if(key == "direction") |
432 |
{ |
673 |
{ |
433 |
load(second, floatvecval); |
674 |
TransformDirection val; |
434 |
if(floatvecval.size() != 3) |
675 |
if (iter.second().Type() != YAML::NodeType::Null && |
435 |
{ |
676 |
iter.second().Read<TransformDirection>(val)) |
436 |
std::ostringstream os; |
677 |
t->setDirection(val); |
437 |
os << "CDLTransform parse error, 'offset' field must be 3 "; |
678 |
} |
438 |
os << "floats. Found '" << floatvecval.size() << "'."; |
679 |
else |
439 |
throw Exception(os.str().c_str()); |
680 |
{ |
440 |
} |
681 |
LogUnknownKeyWarning(node.Tag(), iter.first()); |
441 |
t->setOffset(&floatvecval[0]); |
682 |
} |
442 |
} |
683 |
} |
443 |
else if(key == "power") |
684 |
} |
444 |
{ |
685 |
|
445 |
load(second, floatvecval); |
686 |
YAML::Emitter& operator << (YAML::Emitter& out, ConstExponentTransformRcPtr t) |
446 |
if(floatvecval.size() != 3) |
687 |
{ |
447 |
{ |
688 |
out << YAML::VerbatimTag("ExponentTransform"); |
448 |
std::ostringstream os; |
689 |
out << YAML::Flow << YAML::BeginMap; |
449 |
os << "CDLTransform parse error, 'power' field must be 3 "; |
690 |
|
450 |
os << "floats. Found '" << floatvecval.size() << "'."; |
691 |
std::vector<float> value(4, 0.0); |
451 |
throw Exception(os.str().c_str()); |
692 |
t->getValue(&value[0]); |
452 |
} |
693 |
out << YAML::Key << "value"; |
453 |
t->setPower(&floatvecval[0]); |
694 |
out << YAML::Value << YAML::Flow << value; |
454 |
} |
695 |
EmitBaseTransformKeyValues(out, t); |
455 |
else if(key == "saturation" || key == "sat") |
696 |
out << YAML::EndMap; |
456 |
{ |
697 |
return out; |
457 |
float val = 0.0f; |
698 |
} |
458 |
load(second, val); |
699 |
|
459 |
t->setSat(val); |
700 |
void operator >> (const YAML::Node& node, LogTransformRcPtr& t) |
460 |
} |
701 |
{ |
461 |
else if(key == "direction") |
702 |
t = LogTransform::Create(); |
462 |
{ |
703 |
|
463 |
TransformDirection val; |
704 |
std::string key; |
464 |
load(second, val); |
705 |
|
465 |
t->setDirection(val); |
706 |
for (YAML::Iterator iter = node.begin(); |
466 |
} |
707 |
iter != node.end(); |
467 |
else |
708 |
++iter) |
468 |
{ |
709 |
{ |
469 |
LogUnknownKeyWarning(node.Tag(), first); |
710 |
iter.first() >> key; |
470 |
} |
|
|
471 |
} |
472 |
} |
473 |
|
474 |
inline void save(YAML::Emitter& out, ConstCDLTransformRcPtr t) |
475 |
{ |
476 |
out << YAML::VerbatimTag("CDLTransform"); |
477 |
out << YAML::Flow << YAML::BeginMap; |
711 |
|
478 |
|
712 |
if(key == "base") |
479 |
std::vector<float> slope(3); |
|
|
480 |
t->getSlope(&slope[0]); |
481 |
if(!IsVecEqualToOne(&slope[0], 3)) |
713 |
{ |
482 |
{ |
714 |
float val = 0.0f; |
483 |
out << YAML::Key << "slope"; |
715 |
if (iter.second().Type() != YAML::NodeType::Null && |
484 |
out << YAML::Value << YAML::Flow << slope; |
716 |
iter.second().Read<float>(val)) |
|
|
717 |
t->setBase(val); |
718 |
} |
485 |
} |
719 |
else if(key == "direction") |
486 |
|
|
|
487 |
std::vector<float> offset(3); |
488 |
t->getOffset(&offset[0]); |
489 |
if(!IsVecEqualToZero(&offset[0], 3)) |
720 |
{ |
490 |
{ |
721 |
TransformDirection val; |
491 |
out << YAML::Key << "offset"; |
722 |
if (iter.second().Type() != YAML::NodeType::Null && |
492 |
out << YAML::Value << YAML::Flow << offset; |
723 |
iter.second().Read<TransformDirection>(val)) |
|
|
724 |
t->setDirection(val); |
725 |
} |
493 |
} |
726 |
else |
494 |
|
|
|
495 |
std::vector<float> power(3); |
496 |
t->getPower(&power[0]); |
497 |
if(!IsVecEqualToOne(&power[0], 3)) |
498 |
{ |
499 |
out << YAML::Key << "power"; |
500 |
out << YAML::Value << YAML::Flow << power; |
501 |
} |
502 |
|
503 |
if(!IsScalarEqualToOne(t->getSat())) |
727 |
{ |
504 |
{ |
728 |
LogUnknownKeyWarning(node.Tag(), iter.first()); |
505 |
out << YAML::Key << "sat" << YAML::Value << t->getSat(); |
729 |
} |
506 |
} |
|
|
507 |
|
508 |
EmitBaseTransformKeyValues(out, t); |
509 |
out << YAML::EndMap; |
730 |
} |
510 |
} |
731 |
} |
|
|
732 |
|
733 |
YAML::Emitter& operator << (YAML::Emitter& out, ConstLogTransformRcPtr t) |
734 |
{ |
735 |
out << YAML::VerbatimTag("LogTransform"); |
736 |
out << YAML::Flow << YAML::BeginMap; |
737 |
out << YAML::Key << "base" << YAML::Value << t->getBase(); |
738 |
EmitBaseTransformKeyValues(out, t); |
739 |
out << YAML::EndMap; |
740 |
return out; |
741 |
} |
742 |
|
743 |
void operator >> (const YAML::Node& node, MatrixTransformRcPtr& t) |
744 |
{ |
745 |
t = MatrixTransform::Create(); |
746 |
|
511 |
|
747 |
std::string key; |
512 |
// ColorSpaceTransform |
748 |
|
513 |
|
749 |
for (YAML::Iterator iter = node.begin(); |
514 |
inline void load(const YAML::Node& node, ColorSpaceTransformRcPtr& t) |
750 |
iter != node.end(); |
|
|
751 |
++iter) |
752 |
{ |
515 |
{ |
753 |
iter.first() >> key; |
516 |
t = ColorSpaceTransform::Create(); |
754 |
|
517 |
|
755 |
if(key == "matrix") |
518 |
std::string key, stringval; |
756 |
{ |
519 |
|
757 |
std::vector<float> val; |
520 |
for (Iterator iter = node.begin(); |
758 |
if (iter.second().Type() != YAML::NodeType::Null) |
521 |
iter != node.end(); |
|
|
522 |
++iter) |
523 |
{ |
524 |
const YAML::Node& first = get_first(iter); |
525 |
const YAML::Node& second = get_second(iter); |
526 |
|
527 |
load(first, key); |
528 |
|
529 |
if (second.Type() == YAML::NodeType::Null) continue; |
530 |
|
531 |
if(key == "src") |
759 |
{ |
532 |
{ |
760 |
iter.second() >> val; |
533 |
load(second, stringval); |
761 |
if(val.size() != 16) |
534 |
t->setSrc(stringval.c_str()); |
762 |
{ |
535 |
} |
763 |
std::ostringstream os; |
536 |
else if(key == "dst") |
764 |
os << "MatrixTransform parse error, matrix field must be 16 "; |
537 |
{ |
765 |
os << "floats. Found '" << val.size() << "'."; |
538 |
load(second, stringval); |
766 |
throw Exception(os.str().c_str()); |
539 |
t->setDst(stringval.c_str()); |
767 |
} |
540 |
} |
768 |
t->setMatrix(&val[0]); |
541 |
else if(key == "direction") |
|
|
542 |
{ |
543 |
TransformDirection val; |
544 |
load(second, val); |
545 |
t->setDirection(val); |
546 |
} |
547 |
else |
548 |
{ |
549 |
LogUnknownKeyWarning(node.Tag(), first); |
769 |
} |
550 |
} |
770 |
} |
551 |
} |
771 |
else if(key == "offset") |
552 |
} |
772 |
{ |
553 |
|
773 |
std::vector<float> val; |
554 |
inline void save(YAML::Emitter& out, ConstColorSpaceTransformRcPtr t) |
774 |
if (iter.second().Type() != YAML::NodeType::Null) |
555 |
{ |
|
|
556 |
out << YAML::VerbatimTag("ColorSpaceTransform"); |
557 |
out << YAML::Flow << YAML::BeginMap; |
558 |
out << YAML::Key << "src" << YAML::Value << t->getSrc(); |
559 |
out << YAML::Key << "dst" << YAML::Value << t->getDst(); |
560 |
EmitBaseTransformKeyValues(out, t); |
561 |
out << YAML::EndMap; |
562 |
} |
563 |
|
564 |
// ExponentTransform |
565 |
|
566 |
inline void load(const YAML::Node& node, ExponentTransformRcPtr& t) |
567 |
{ |
568 |
t = ExponentTransform::Create(); |
569 |
|
570 |
std::string key; |
571 |
|
572 |
for (Iterator iter = node.begin(); |
573 |
iter != node.end(); |
574 |
++iter) |
575 |
{ |
576 |
const YAML::Node& first = get_first(iter); |
577 |
const YAML::Node& second = get_second(iter); |
578 |
|
579 |
load(first, key); |
580 |
|
581 |
if (second.Type() == YAML::NodeType::Null) continue; |
582 |
|
583 |
if(key == "value") |
775 |
{ |
584 |
{ |
776 |
iter.second() >> val; |
585 |
std::vector<float> val; |
|
|
586 |
load(second, val); |
777 |
if(val.size() != 4) |
587 |
if(val.size() != 4) |
778 |
{ |
588 |
{ |
779 |
std::ostringstream os; |
589 |
std::ostringstream os; |
780 |
os << "MatrixTransform parse error, offset field must be 4 "; |
590 |
os << "ExponentTransform parse error, value field must be 4 "; |
781 |
os << "floats. Found '" << val.size() << "'."; |
591 |
os << "floats. Found '" << val.size() << "'."; |
782 |
throw Exception(os.str().c_str()); |
592 |
throw Exception(os.str().c_str()); |
783 |
} |
593 |
} |
784 |
t->setOffset(&val[0]); |
594 |
t->setValue(&val[0]); |
|
|
595 |
} |
596 |
else if(key == "direction") |
597 |
{ |
598 |
TransformDirection val; |
599 |
load(second, val); |
600 |
t->setDirection(val); |
601 |
} |
602 |
else |
603 |
{ |
604 |
LogUnknownKeyWarning(node.Tag(), first); |
785 |
} |
605 |
} |
786 |
} |
|
|
787 |
else if(key == "direction") |
788 |
{ |
789 |
TransformDirection val; |
790 |
if (iter.second().Type() != YAML::NodeType::Null && |
791 |
iter.second().Read<TransformDirection>(val)) |
792 |
t->setDirection(val); |
793 |
} |
794 |
else |
795 |
{ |
796 |
LogUnknownKeyWarning(node.Tag(), iter.first()); |
797 |
} |
606 |
} |
798 |
} |
607 |
} |
799 |
} |
|
|
800 |
|
801 |
YAML::Emitter& operator << (YAML::Emitter& out, ConstMatrixTransformRcPtr t) |
802 |
{ |
803 |
out << YAML::VerbatimTag("MatrixTransform"); |
804 |
out << YAML::Flow << YAML::BeginMap; |
805 |
|
608 |
|
806 |
std::vector<float> matrix(16, 0.0); |
609 |
inline void save(YAML::Emitter& out, ConstExponentTransformRcPtr t) |
807 |
t->getMatrix(&matrix[0]); |
|
|
808 |
if(!IsM44Identity(&matrix[0])) |
809 |
{ |
610 |
{ |
810 |
out << YAML::Key << "matrix"; |
611 |
out << YAML::VerbatimTag("ExponentTransform"); |
811 |
out << YAML::Value << YAML::Flow << matrix; |
612 |
out << YAML::Flow << YAML::BeginMap; |
|
|
613 |
|
614 |
std::vector<float> value(4, 0.0); |
615 |
t->getValue(&value[0]); |
616 |
out << YAML::Key << "value"; |
617 |
out << YAML::Value << YAML::Flow << value; |
618 |
EmitBaseTransformKeyValues(out, t); |
619 |
out << YAML::EndMap; |
812 |
} |
620 |
} |
813 |
|
621 |
|
814 |
std::vector<float> offset(4, 0.0); |
622 |
// FileTransform |
815 |
t->getOffset(&offset[0]); |
623 |
|
816 |
if(!IsVecEqualToZero(&offset[0],4)) |
624 |
inline void load(const YAML::Node& node, FileTransformRcPtr& t) |
817 |
{ |
625 |
{ |
818 |
out << YAML::Key << "offset"; |
626 |
t = FileTransform::Create(); |
819 |
out << YAML::Value << YAML::Flow << offset; |
627 |
|
|
|
628 |
std::string key, stringval; |
629 |
|
630 |
for (Iterator iter = node.begin(); |
631 |
iter != node.end(); |
632 |
++iter) |
633 |
{ |
634 |
const YAML::Node& first = get_first(iter); |
635 |
const YAML::Node& second = get_second(iter); |
636 |
|
637 |
load(first, key); |
638 |
|
639 |
if (second.Type() == YAML::NodeType::Null) continue; |
640 |
|
641 |
if(key == "src") |
642 |
{ |
643 |
load(second, stringval); |
644 |
t->setSrc(stringval.c_str()); |
645 |
} |
646 |
else if(key == "cccid") |
647 |
{ |
648 |
load(second, stringval); |
649 |
t->setCCCId(stringval.c_str()); |
650 |
} |
651 |
else if(key == "interpolation") |
652 |
{ |
653 |
Interpolation val; |
654 |
load(second, val); |
655 |
t->setInterpolation(val); |
656 |
} |
657 |
else if(key == "direction") |
658 |
{ |
659 |
TransformDirection val; |
660 |
load(second, val); |
661 |
t->setDirection(val); |
662 |
} |
663 |
else |
664 |
{ |
665 |
LogUnknownKeyWarning(node.Tag(), first); |
666 |
} |
667 |
} |
820 |
} |
668 |
} |
821 |
|
669 |
|
822 |
EmitBaseTransformKeyValues(out, t); |
670 |
inline void save(YAML::Emitter& out, ConstFileTransformRcPtr t) |
823 |
out << YAML::EndMap; |
671 |
{ |
824 |
return out; |
672 |
out << YAML::VerbatimTag("FileTransform"); |
825 |
} |
673 |
out << YAML::Flow << YAML::BeginMap; |
826 |
|
674 |
out << YAML::Key << "src" << YAML::Value << t->getSrc(); |
827 |
void operator >> (const YAML::Node& node, CDLTransformRcPtr& t) |
675 |
const char * cccid = t->getCCCId(); |
828 |
{ |
676 |
if(cccid && *cccid) |
829 |
t = CDLTransform::Create(); |
677 |
{ |
|
|
678 |
out << YAML::Key << "cccid" << YAML::Value << t->getCCCId(); |
679 |
} |
680 |
out << YAML::Key << "interpolation"; |
681 |
out << YAML::Value; |
682 |
save(out, t->getInterpolation()); |
683 |
|
684 |
EmitBaseTransformKeyValues(out, t); |
685 |
out << YAML::EndMap; |
686 |
} |
687 |
|
688 |
// GroupTransform |
830 |
|
689 |
|
831 |
std::string key; |
690 |
void load(const YAML::Node& node, TransformRcPtr& t); |
832 |
std::vector<float> floatvecval; |
691 |
void save(YAML::Emitter& out, ConstTransformRcPtr t); |
833 |
|
692 |
|
834 |
for (YAML::Iterator iter = node.begin(); |
693 |
inline void load(const YAML::Node& node, GroupTransformRcPtr& t) |
835 |
iter != node.end(); |
|
|
836 |
++iter) |
837 |
{ |
694 |
{ |
838 |
iter.first() >> key; |
695 |
t = GroupTransform::Create(); |
839 |
|
696 |
|
840 |
if(key == "slope") |
697 |
std::string key; |
841 |
{ |
698 |
|
842 |
if (iter.second().Type() != YAML::NodeType::Null) |
699 |
for (Iterator iter = node.begin(); |
|
|
700 |
iter != node.end(); |
701 |
++iter) |
702 |
{ |
703 |
const YAML::Node& first = get_first(iter); |
704 |
const YAML::Node& second = get_second(iter); |
705 |
|
706 |
load(first, key); |
707 |
|
708 |
if (second.Type() == YAML::NodeType::Null) continue; |
709 |
|
710 |
if(key == "children") |
843 |
{ |
711 |
{ |
844 |
iter.second() >> floatvecval; |
712 |
for(unsigned i = 0; i < second.size(); ++i) |
845 |
if(floatvecval.size() != 3) |
|
|
846 |
{ |
713 |
{ |
847 |
std::ostringstream os; |
714 |
TransformRcPtr childTransform; |
848 |
os << "CDLTransform parse error, 'slope' field must be 3 "; |
715 |
load(second[i], childTransform); |
849 |
os << "floats. Found '" << floatvecval.size() << "'."; |
716 |
|
850 |
throw Exception(os.str().c_str()); |
717 |
// TODO: consider the forwards-compatibility implication of |
|
|
718 |
// throwing an exception. Should this be a warning, instead? |
719 |
if(!childTransform) |
720 |
{ |
721 |
throw Exception("Child transform could not be parsed."); |
722 |
} |
723 |
|
724 |
t->push_back(childTransform); |
851 |
} |
725 |
} |
852 |
t->setSlope(&floatvecval[0]); |
|
|
853 |
} |
726 |
} |
854 |
} |
727 |
else if(key == "direction") |
855 |
else if(key == "offset") |
|
|
856 |
{ |
857 |
if (iter.second().Type() != YAML::NodeType::Null) |
858 |
{ |
728 |
{ |
859 |
iter.second() >> floatvecval; |
729 |
TransformDirection val; |
860 |
if(floatvecval.size() != 3) |
730 |
load(second, val); |
861 |
{ |
731 |
t->setDirection(val); |
862 |
std::ostringstream os; |
|
|
863 |
os << "CDLTransform parse error, 'offset' field must be 3 "; |
864 |
os << "floats. Found '" << floatvecval.size() << "'."; |
865 |
throw Exception(os.str().c_str()); |
866 |
} |
867 |
t->setOffset(&floatvecval[0]); |
868 |
} |
732 |
} |
869 |
} |
733 |
else |
870 |
else if(key == "power") |
|
|
871 |
{ |
872 |
if (iter.second().Type() != YAML::NodeType::Null) |
873 |
{ |
734 |
{ |
874 |
iter.second() >> floatvecval; |
735 |
LogUnknownKeyWarning(node.Tag(), first); |
875 |
if(floatvecval.size() != 3) |
|
|
876 |
{ |
877 |
std::ostringstream os; |
878 |
os << "CDLTransform parse error, 'power' field must be 3 "; |
879 |
os << "floats. Found '" << floatvecval.size() << "'."; |
880 |
throw Exception(os.str().c_str()); |
881 |
} |
882 |
t->setPower(&floatvecval[0]); |
883 |
} |
736 |
} |
884 |
} |
737 |
} |
885 |
else if(key == "saturation" || key == "sat") |
738 |
} |
886 |
{ |
739 |
|
887 |
float val = 0.0f; |
740 |
inline void save(YAML::Emitter& out, ConstGroupTransformRcPtr t) |
888 |
if (iter.second().Type() != YAML::NodeType::Null && |
741 |
{ |
889 |
iter.second().Read<float>(val)) |
742 |
out << YAML::VerbatimTag("GroupTransform"); |
890 |
t->setSat(val); |
743 |
out << YAML::BeginMap; |
891 |
} |
744 |
EmitBaseTransformKeyValues(out, t); |
892 |
else if(key == "direction") |
745 |
|
893 |
{ |
746 |
out << YAML::Key << "children"; |
894 |
TransformDirection val; |
747 |
out << YAML::Value; |
895 |
if (iter.second().Type() != YAML::NodeType::Null && |
748 |
|
896 |
iter.second().Read<TransformDirection>(val)) |
749 |
out << YAML::BeginSeq; |
897 |
t->setDirection(val); |
750 |
for(int i = 0; i < t->size(); ++i) |
898 |
} |
|
|
899 |
else |
900 |
{ |
751 |
{ |
901 |
LogUnknownKeyWarning(node.Tag(), iter.first()); |
752 |
save(out, t->getTransform(i)); |
902 |
} |
753 |
} |
|
|
754 |
out << YAML::EndSeq; |
755 |
|
756 |
out << YAML::EndMap; |
903 |
} |
757 |
} |
904 |
} |
|
|
905 |
|
906 |
YAML::Emitter& operator << (YAML::Emitter& out, ConstCDLTransformRcPtr t) |
907 |
{ |
908 |
out << YAML::VerbatimTag("CDLTransform"); |
909 |
out << YAML::Flow << YAML::BeginMap; |
910 |
|
758 |
|
911 |
std::vector<float> slope(3); |
759 |
// LogTransform |
912 |
t->getSlope(&slope[0]); |
760 |
|
913 |
if(!IsVecEqualToOne(&slope[0], 3)) |
761 |
inline void load(const YAML::Node& node, LogTransformRcPtr& t) |
914 |
{ |
762 |
{ |
915 |
out << YAML::Key << "slope"; |
763 |
t = LogTransform::Create(); |
916 |
out << YAML::Value << YAML::Flow << slope; |
764 |
|
|
|
765 |
std::string key; |
766 |
|
767 |
for (Iterator iter = node.begin(); |
768 |
iter != node.end(); |
769 |
++iter) |
770 |
{ |
771 |
const YAML::Node& first = get_first(iter); |
772 |
const YAML::Node& second = get_second(iter); |
773 |
|
774 |
load(first, key); |
775 |
|
776 |
if (second.Type() == YAML::NodeType::Null) continue; |
777 |
|
778 |
if(key == "base") |
779 |
{ |
780 |
float val = 0.0f; |
781 |
load(second, val); |
782 |
t->setBase(val); |
783 |
} |
784 |
else if(key == "direction") |
785 |
{ |
786 |
TransformDirection val; |
787 |
load(second, val); |
788 |
t->setDirection(val); |
789 |
} |
790 |
else |
791 |
{ |
792 |
LogUnknownKeyWarning(node.Tag(), first); |
793 |
} |
794 |
} |
917 |
} |
795 |
} |
918 |
|
796 |
|
919 |
std::vector<float> offset(3); |
797 |
inline void save(YAML::Emitter& out, ConstLogTransformRcPtr t) |
920 |
t->getOffset(&offset[0]); |
|
|
921 |
if(!IsVecEqualToZero(&offset[0], 3)) |
922 |
{ |
798 |
{ |
923 |
out << YAML::Key << "offset"; |
799 |
out << YAML::VerbatimTag("LogTransform"); |
924 |
out << YAML::Value << YAML::Flow << offset; |
800 |
out << YAML::Flow << YAML::BeginMap; |
|
|
801 |
out << YAML::Key << "base" << YAML::Value << t->getBase(); |
802 |
EmitBaseTransformKeyValues(out, t); |
803 |
out << YAML::EndMap; |
925 |
} |
804 |
} |
926 |
|
805 |
|
927 |
std::vector<float> power(3); |
806 |
// LookTransform |
928 |
t->getPower(&power[0]); |
807 |
|
929 |
if(!IsVecEqualToOne(&power[0], 3)) |
808 |
inline void load(const YAML::Node& node, LookTransformRcPtr& t) |
930 |
{ |
809 |
{ |
931 |
out << YAML::Key << "power"; |
810 |
t = LookTransform::Create(); |
932 |
out << YAML::Value << YAML::Flow << power; |
811 |
|
|
|
812 |
std::string key, stringval; |
813 |
|
814 |
for (Iterator iter = node.begin(); |
815 |
iter != node.end(); |
816 |
++iter) |
817 |
{ |
818 |
const YAML::Node& first = get_first(iter); |
819 |
const YAML::Node& second = get_second(iter); |
820 |
|
821 |
load(first, key); |
822 |
|
823 |
if (second.Type() == YAML::NodeType::Null) continue; |
824 |
|
825 |
if(key == "src") |
826 |
{ |
827 |
load(second, stringval); |
828 |
t->setSrc(stringval.c_str()); |
829 |
} |
830 |
else if(key == "dst") |
831 |
{ |
832 |
load(second, stringval); |
833 |
t->setDst(stringval.c_str()); |
834 |
} |
835 |
else if(key == "looks") |
836 |
{ |
837 |
load(second, stringval); |
838 |
t->setLooks(stringval.c_str()); |
839 |
} |
840 |
else if(key == "direction") |
841 |
{ |
842 |
TransformDirection val; |
843 |
load(second, val); |
844 |
t->setDirection(val); |
845 |
} |
846 |
else |
847 |
{ |
848 |
LogUnknownKeyWarning(node.Tag(), first); |
849 |
} |
850 |
} |
933 |
} |
851 |
} |
934 |
|
852 |
|
935 |
if(!IsScalarEqualToOne(t->getSat())) |
853 |
inline void save(YAML::Emitter& out, ConstLookTransformRcPtr t) |
936 |
{ |
854 |
{ |
937 |
out << YAML::Key << "sat" << YAML::Value << t->getSat(); |
855 |
out << YAML::VerbatimTag("LookTransform"); |
|
|
856 |
out << YAML::Flow << YAML::BeginMap; |
857 |
out << YAML::Key << "src" << YAML::Value << t->getSrc(); |
858 |
out << YAML::Key << "dst" << YAML::Value << t->getDst(); |
859 |
out << YAML::Key << "looks" << YAML::Value << t->getLooks(); |
860 |
EmitBaseTransformKeyValues(out, t); |
861 |
out << YAML::EndMap; |
938 |
} |
862 |
} |
939 |
|
863 |
|
940 |
EmitBaseTransformKeyValues(out, t); |
864 |
// MatrixTransform |
941 |
out << YAML::EndMap; |
|
|
942 |
return out; |
943 |
} |
944 |
|
945 |
void operator >> (const YAML::Node& node, AllocationTransformRcPtr& t) |
946 |
{ |
947 |
t = AllocationTransform::Create(); |
948 |
|
949 |
std::string key; |
950 |
|
865 |
|
951 |
for (YAML::Iterator iter = node.begin(); |
866 |
inline void load(const YAML::Node& node, MatrixTransformRcPtr& t) |
952 |
iter != node.end(); |
|
|
953 |
++iter) |
954 |
{ |
867 |
{ |
955 |
iter.first() >> key; |
868 |
t = MatrixTransform::Create(); |
956 |
|
869 |
|
957 |
if(key == "allocation") |
870 |
std::string key; |
958 |
{ |
871 |
|
959 |
Allocation val; |
872 |
for (Iterator iter = node.begin(); |
960 |
if (iter.second().Type() != YAML::NodeType::Null && |
873 |
iter != node.end(); |
961 |
iter.second().Read<Allocation>(val)) |
874 |
++iter) |
962 |
t->setAllocation(val); |
875 |
{ |
963 |
} |
876 |
const YAML::Node& first = get_first(iter); |
964 |
else if(key == "vars") |
877 |
const YAML::Node& second = get_second(iter); |
965 |
{ |
878 |
|
966 |
std::vector<float> val; |
879 |
load(first, key); |
967 |
if (iter.second().Type() != YAML::NodeType::Null) |
880 |
|
|
|
881 |
if (second.Type() == YAML::NodeType::Null) continue; |
882 |
|
883 |
if(key == "matrix") |
968 |
{ |
884 |
{ |
969 |
iter.second() >> val; |
885 |
std::vector<float> val; |
970 |
if(!val.empty()) |
886 |
load(second, val); |
|
|
887 |
if(val.size() != 16) |
971 |
{ |
888 |
{ |
972 |
t->setVars(static_cast<int>(val.size()), &val[0]); |
889 |
std::ostringstream os; |
|
|
890 |
os << "MatrixTransform parse error, matrix field must be 16 "; |
891 |
os << "floats. Found '" << val.size() << "'."; |
892 |
throw Exception(os.str().c_str()); |
893 |
} |
894 |
t->setMatrix(&val[0]); |
895 |
} |
896 |
else if(key == "offset") |
897 |
{ |
898 |
std::vector<float> val; |
899 |
load(second, val); |
900 |
if(val.size() != 4) |
901 |
{ |
902 |
std::ostringstream os; |
903 |
os << "MatrixTransform parse error, offset field must be 4 "; |
904 |
os << "floats. Found '" << val.size() << "'."; |
905 |
throw Exception(os.str().c_str()); |
973 |
} |
906 |
} |
|
|
907 |
t->setOffset(&val[0]); |
908 |
} |
909 |
else if(key == "direction") |
910 |
{ |
911 |
TransformDirection val; |
912 |
load(second, val); |
913 |
t->setDirection(val); |
914 |
} |
915 |
else |
916 |
{ |
917 |
LogUnknownKeyWarning(node.Tag(), first); |
974 |
} |
918 |
} |
975 |
} |
919 |
} |
976 |
else if(key == "direction") |
920 |
} |
|
|
921 |
|
922 |
inline void save(YAML::Emitter& out, ConstMatrixTransformRcPtr t) |
923 |
{ |
924 |
out << YAML::VerbatimTag("MatrixTransform"); |
925 |
out << YAML::Flow << YAML::BeginMap; |
926 |
|
927 |
std::vector<float> matrix(16, 0.0); |
928 |
t->getMatrix(&matrix[0]); |
929 |
if(!IsM44Identity(&matrix[0])) |
977 |
{ |
930 |
{ |
978 |
TransformDirection val; |
931 |
out << YAML::Key << "matrix"; |
979 |
if (iter.second().Type() != YAML::NodeType::Null && |
932 |
out << YAML::Value << YAML::Flow << matrix; |
980 |
iter.second().Read<TransformDirection>(val)) |
|
|
981 |
t->setDirection(val); |
982 |
} |
933 |
} |
983 |
else |
934 |
|
|
|
935 |
std::vector<float> offset(4, 0.0); |
936 |
t->getOffset(&offset[0]); |
937 |
if(!IsVecEqualToZero(&offset[0],4)) |
984 |
{ |
938 |
{ |
985 |
LogUnknownKeyWarning(node.Tag(), iter.first()); |
939 |
out << YAML::Key << "offset"; |
|
|
940 |
out << YAML::Value << YAML::Flow << offset; |
986 |
} |
941 |
} |
|
|
942 |
|
943 |
EmitBaseTransformKeyValues(out, t); |
944 |
out << YAML::EndMap; |
987 |
} |
945 |
} |
988 |
} |
|
|
989 |
|
990 |
YAML::Emitter& operator << (YAML::Emitter& out, ConstAllocationTransformRcPtr t) |
991 |
{ |
992 |
out << YAML::VerbatimTag("AllocationTransform"); |
993 |
out << YAML::Flow << YAML::BeginMap; |
994 |
|
946 |
|
995 |
out << YAML::Key << "allocation"; |
947 |
// TruelightTransform |
996 |
out << YAML::Value << YAML::Flow << t->getAllocation(); |
|
|
997 |
|
948 |
|
998 |
if(t->getNumVars() > 0) |
949 |
inline void load(const YAML::Node& node, TruelightTransformRcPtr& t) |
999 |
{ |
950 |
{ |
1000 |
std::vector<float> vars(t->getNumVars()); |
951 |
t = TruelightTransform::Create(); |
1001 |
t->getVars(&vars[0]); |
952 |
|
1002 |
out << YAML::Key << "vars"; |
953 |
std::string key, stringval; |
1003 |
out << YAML::Flow << YAML::Value << vars; |
954 |
|
|
|
955 |
for (Iterator iter = node.begin(); |
956 |
iter != node.end(); |
957 |
++iter) |
958 |
{ |
959 |
const YAML::Node& first = get_first(iter); |
960 |
const YAML::Node& second = get_second(iter); |
961 |
|
962 |
load(first, key); |
963 |
|
964 |
if (second.Type() == YAML::NodeType::Null) continue; |
965 |
|
966 |
if(key == "config_root") |
967 |
{ |
968 |
load(second, stringval); |
969 |
t->setConfigRoot(stringval.c_str()); |
970 |
} |
971 |
else if(key == "profile") |
972 |
{ |
973 |
load(second, stringval); |
974 |
t->setProfile(stringval.c_str()); |
975 |
} |
976 |
else if(key == "camera") |
977 |
{ |
978 |
load(second, stringval); |
979 |
t->setCamera(stringval.c_str()); |
980 |
} |
981 |
else if(key == "input_display") |
982 |
{ |
983 |
load(second, stringval); |
984 |
t->setInputDisplay(stringval.c_str()); |
985 |
} |
986 |
else if(key == "recorder") |
987 |
{ |
988 |
load(second, stringval); |
989 |
t->setRecorder(stringval.c_str()); |
990 |
} |
991 |
else if(key == "print") |
992 |
{ |
993 |
load(second, stringval); |
994 |
t->setPrint(stringval.c_str()); |
995 |
} |
996 |
else if(key == "lamp") |
997 |
{ |
998 |
load(second, stringval); |
999 |
t->setLamp(stringval.c_str()); |
1000 |
} |
1001 |
else if(key == "output_camera") |
1002 |
{ |
1003 |
load(second, stringval); |
1004 |
t->setOutputCamera(stringval.c_str()); |
1005 |
} |
1006 |
else if(key == "display") |
1007 |
{ |
1008 |
load(second, stringval); |
1009 |
t->setDisplay(stringval.c_str()); |
1010 |
} |
1011 |
else if(key == "cube_input") |
1012 |
{ |
1013 |
load(second, stringval); |
1014 |
t->setCubeInput(stringval.c_str()); |
1015 |
} |
1016 |
else if(key == "direction") |
1017 |
{ |
1018 |
TransformDirection val; |
1019 |
load(second, val); |
1020 |
t->setDirection(val); |
1021 |
} |
1022 |
else |
1023 |
{ |
1024 |
LogUnknownKeyWarning(node.Tag(), first); |
1025 |
} |
1026 |
} |
1004 |
} |
1027 |
} |
1005 |
|
1028 |
|
1006 |
EmitBaseTransformKeyValues(out, t); |
1029 |
inline void save(YAML::Emitter& out, ConstTruelightTransformRcPtr t) |
1007 |
out << YAML::EndMap; |
|
|
1008 |
return out; |
1009 |
} |
1010 |
|
1011 |
void operator >> (const YAML::Node& node, TruelightTransformRcPtr& t) |
1012 |
{ |
1013 |
t = TruelightTransform::Create(); |
1014 |
|
1015 |
std::string key, stringval; |
1016 |
|
1017 |
for (YAML::Iterator iter = node.begin(); |
1018 |
iter != node.end(); |
1019 |
++iter) |
1020 |
{ |
1030 |
{ |
1021 |
iter.first() >> key; |
|
|
1022 |
|
1031 |
|
1023 |
if(key == "config_root") |
1032 |
out << YAML::VerbatimTag("TruelightTransform"); |
|
|
1033 |
out << YAML::Flow << YAML::BeginMap; |
1034 |
if(strcmp(t->getConfigRoot(), "") != 0) |
1024 |
{ |
1035 |
{ |
1025 |
if (iter.second().Type() != YAML::NodeType::Null && |
1036 |
out << YAML::Key << "config_root"; |
1026 |
iter.second().Read<std::string>(stringval)) |
1037 |
out << YAML::Value << YAML::Flow << t->getConfigRoot(); |
1027 |
t->setConfigRoot(stringval.c_str()); |
|
|
1028 |
} |
1038 |
} |
1029 |
else if(key == "profile") |
1039 |
if(strcmp(t->getProfile(), "") != 0) |
1030 |
{ |
1040 |
{ |
1031 |
if (iter.second().Type() != YAML::NodeType::Null && |
1041 |
out << YAML::Key << "profile"; |
1032 |
iter.second().Read<std::string>(stringval)) |
1042 |
out << YAML::Value << YAML::Flow << t->getProfile(); |
1033 |
t->setProfile(stringval.c_str()); |
|
|
1034 |
} |
1043 |
} |
1035 |
else if(key == "camera") |
1044 |
if(strcmp(t->getCamera(), "") != 0) |
1036 |
{ |
1045 |
{ |
1037 |
if (iter.second().Type() != YAML::NodeType::Null && |
1046 |
out << YAML::Key << "camera"; |
1038 |
iter.second().Read<std::string>(stringval)) |
1047 |
out << YAML::Value << YAML::Flow << t->getCamera(); |
1039 |
t->setCamera(stringval.c_str()); |
|
|
1040 |
} |
1048 |
} |
1041 |
else if(key == "input_display") |
1049 |
if(strcmp(t->getInputDisplay(), "") != 0) |
1042 |
{ |
1050 |
{ |
1043 |
if (iter.second().Type() != YAML::NodeType::Null && |
1051 |
out << YAML::Key << "input_display"; |
1044 |
iter.second().Read<std::string>(stringval)) |
1052 |
out << YAML::Value << YAML::Flow << t->getInputDisplay(); |
1045 |
t->setInputDisplay(stringval.c_str()); |
|
|
1046 |
} |
1053 |
} |
1047 |
else if(key == "recorder") |
1054 |
if(strcmp(t->getRecorder(), "") != 0) |
1048 |
{ |
1055 |
{ |
1049 |
if (iter.second().Type() != YAML::NodeType::Null && |
1056 |
out << YAML::Key << "recorder"; |
1050 |
iter.second().Read<std::string>(stringval)) |
1057 |
out << YAML::Value << YAML::Flow << t->getRecorder(); |
1051 |
t->setRecorder(stringval.c_str()); |
|
|
1052 |
} |
1058 |
} |
1053 |
else if(key == "print") |
1059 |
if(strcmp(t->getPrint(), "") != 0) |
1054 |
{ |
1060 |
{ |
1055 |
if (iter.second().Type() != YAML::NodeType::Null && |
1061 |
out << YAML::Key << "print"; |
1056 |
iter.second().Read<std::string>(stringval)) |
1062 |
out << YAML::Value << YAML::Flow << t->getPrint(); |
1057 |
t->setPrint(stringval.c_str()); |
|
|
1058 |
} |
1063 |
} |
1059 |
else if(key == "lamp") |
1064 |
if(strcmp(t->getLamp(), "") != 0) |
1060 |
{ |
1065 |
{ |
1061 |
if (iter.second().Type() != YAML::NodeType::Null && |
1066 |
out << YAML::Key << "lamp"; |
1062 |
iter.second().Read<std::string>(stringval)) |
1067 |
out << YAML::Value << YAML::Flow << t->getLamp(); |
1063 |
t->setLamp(stringval.c_str()); |
|
|
1064 |
} |
1068 |
} |
1065 |
else if(key == "output_camera") |
1069 |
if(strcmp(t->getOutputCamera(), "") != 0) |
1066 |
{ |
1070 |
{ |
1067 |
if (iter.second().Type() != YAML::NodeType::Null && |
1071 |
out << YAML::Key << "output_camera"; |
1068 |
iter.second().Read<std::string>(stringval)) |
1072 |
out << YAML::Value << YAML::Flow << t->getOutputCamera(); |
1069 |
t->setOutputCamera(stringval.c_str()); |
|
|
1070 |
} |
1073 |
} |
1071 |
else if(key == "display") |
1074 |
if(strcmp(t->getDisplay(), "") != 0) |
1072 |
{ |
1075 |
{ |
1073 |
if (iter.second().Type() != YAML::NodeType::Null && |
1076 |
out << YAML::Key << "display"; |
1074 |
iter.second().Read<std::string>(stringval)) |
1077 |
out << YAML::Value << YAML::Flow << t->getDisplay(); |
1075 |
t->setDisplay(stringval.c_str()); |
|
|
1076 |
} |
1078 |
} |
1077 |
else if(key == "cube_input") |
1079 |
if(strcmp(t->getCubeInput(), "") != 0) |
1078 |
{ |
1080 |
{ |
1079 |
if (iter.second().Type() != YAML::NodeType::Null && |
1081 |
out << YAML::Key << "cube_input"; |
1080 |
iter.second().Read<std::string>(stringval)) |
1082 |
out << YAML::Value << YAML::Flow << t->getCubeInput(); |
1081 |
t->setCubeInput(stringval.c_str()); |
|
|
1082 |
} |
1083 |
} |
1083 |
else if(key == "direction") |
1084 |
|
|
|
1085 |
EmitBaseTransformKeyValues(out, t); |
1086 |
|
1087 |
out << YAML::EndMap; |
1088 |
} |
1089 |
|
1090 |
// Transform |
1091 |
|
1092 |
void load(const YAML::Node& node, TransformRcPtr& t) |
1093 |
{ |
1094 |
if(node.Type() != YAML::NodeType::Map) |
1084 |
{ |
1095 |
{ |
1085 |
TransformDirection val; |
1096 |
std::ostringstream os; |
1086 |
if (iter.second().Type() != YAML::NodeType::Null && |
1097 |
os << "Unsupported Transform type encountered: (" << node.Type() << ") in OCIO profile. "; |
1087 |
iter.second().Read<TransformDirection>(val)) |
1098 |
os << "Only Mapping types supported."; |
1088 |
t->setDirection(val); |
1099 |
throw Exception(os.str().c_str()); |
|
|
1100 |
} |
1101 |
|
1102 |
std::string type = node.Tag(); |
1103 |
|
1104 |
if(type == "AllocationTransform") { |
1105 |
AllocationTransformRcPtr temp; |
1106 |
load(node, temp); |
1107 |
t = temp; |
1108 |
} |
1109 |
else if(type == "CDLTransform") { |
1110 |
CDLTransformRcPtr temp; |
1111 |
load(node, temp); |
1112 |
t = temp; |
1113 |
} |
1114 |
else if(type == "ColorSpaceTransform") { |
1115 |
ColorSpaceTransformRcPtr temp; |
1116 |
load(node, temp); |
1117 |
t = temp; |
1118 |
} |
1119 |
// TODO: DisplayTransform |
1120 |
else if(type == "ExponentTransform") { |
1121 |
ExponentTransformRcPtr temp; |
1122 |
load(node, temp); |
1123 |
t = temp; |
1124 |
} |
1125 |
else if(type == "FileTransform") { |
1126 |
FileTransformRcPtr temp; |
1127 |
load(node, temp); |
1128 |
t = temp; |
1129 |
} |
1130 |
else if(type == "GroupTransform") { |
1131 |
GroupTransformRcPtr temp; |
1132 |
load(node, temp); |
1133 |
t = temp; |
1134 |
} |
1135 |
else if(type == "LogTransform") { |
1136 |
LogTransformRcPtr temp; |
1137 |
load(node, temp); |
1138 |
t = temp; |
1139 |
} |
1140 |
else if(type == "LookTransform") { |
1141 |
LookTransformRcPtr temp; |
1142 |
load(node, temp); |
1143 |
t = temp; |
1144 |
} |
1145 |
else if(type == "MatrixTransform") { |
1146 |
MatrixTransformRcPtr temp; |
1147 |
load(node, temp); |
1148 |
t = temp; |
1149 |
} |
1150 |
else if(type == "TruelightTransform") { |
1151 |
TruelightTransformRcPtr temp; |
1152 |
load(node, temp); |
1153 |
t = temp; |
1089 |
} |
1154 |
} |
1090 |
else |
1155 |
else |
1091 |
{ |
1156 |
{ |
1092 |
LogUnknownKeyWarning(node.Tag(), iter.first()); |
1157 |
// TODO: add a new empty (better name?) aka passthru Transform() |
|
|
1158 |
// which does nothing. This is so upsupported !<tag> types don't |
1159 |
// throw an exception. Alternativly this could be caught in the |
1160 |
// GroupTransformRcPtr >> operator with some type of |
1161 |
// supported_tag() method |
1162 |
|
1163 |
// TODO: consider the forwards-compatibility implication of |
1164 |
// throwing an exception. Should this be a warning, instead? |
1165 |
|
1166 |
// t = EmptyTransformRcPtr(new EmptyTransform(), &deleter); |
1167 |
std::ostringstream os; |
1168 |
os << "Unsupported transform type !<" << type << "> in OCIO profile. "; |
1169 |
throw Exception(os.str().c_str()); |
1093 |
} |
1170 |
} |
1094 |
} |
1171 |
} |
1095 |
} |
|
|
1096 |
|
1097 |
YAML::Emitter& operator << (YAML::Emitter& out, ConstTruelightTransformRcPtr t) |
1098 |
{ |
1099 |
|
1172 |
|
1100 |
out << YAML::VerbatimTag("TruelightTransform"); |
1173 |
void save(YAML::Emitter& out, ConstTransformRcPtr t) |
1101 |
out << YAML::Flow << YAML::BeginMap; |
|
|
1102 |
if(strcmp(t->getConfigRoot(), "") != 0) |
1103 |
{ |
1104 |
out << YAML::Key << "config_root"; |
1105 |
out << YAML::Value << YAML::Flow << t->getConfigRoot(); |
1106 |
} |
1107 |
if(strcmp(t->getProfile(), "") != 0) |
1108 |
{ |
1174 |
{ |
1109 |
out << YAML::Key << "profile"; |
1175 |
if(ConstAllocationTransformRcPtr Allocation_tran = \ |
1110 |
out << YAML::Value << YAML::Flow << t->getProfile(); |
1176 |
DynamicPtrCast<const AllocationTransform>(t)) |
1111 |
} |
1177 |
save(out, Allocation_tran); |
1112 |
if(strcmp(t->getCamera(), "") != 0) |
1178 |
else if(ConstCDLTransformRcPtr CDL_tran = \ |
1113 |
{ |
1179 |
DynamicPtrCast<const CDLTransform>(t)) |
1114 |
out << YAML::Key << "camera"; |
1180 |
save(out, CDL_tran); |
1115 |
out << YAML::Value << YAML::Flow << t->getCamera(); |
1181 |
else if(ConstColorSpaceTransformRcPtr ColorSpace_tran = \ |
1116 |
} |
1182 |
DynamicPtrCast<const ColorSpaceTransform>(t)) |
1117 |
if(strcmp(t->getInputDisplay(), "") != 0) |
1183 |
save(out, ColorSpace_tran); |
1118 |
{ |
1184 |
else if(ConstExponentTransformRcPtr Exponent_tran = \ |
1119 |
out << YAML::Key << "input_display"; |
1185 |
DynamicPtrCast<const ExponentTransform>(t)) |
1120 |
out << YAML::Value << YAML::Flow << t->getInputDisplay(); |
1186 |
save(out, Exponent_tran); |
|
|
1187 |
else if(ConstFileTransformRcPtr File_tran = \ |
1188 |
DynamicPtrCast<const FileTransform>(t)) |
1189 |
save(out, File_tran); |
1190 |
else if(ConstGroupTransformRcPtr Group_tran = \ |
1191 |
DynamicPtrCast<const GroupTransform>(t)) |
1192 |
save(out, Group_tran); |
1193 |
else if(ConstLogTransformRcPtr Log_tran = \ |
1194 |
DynamicPtrCast<const LogTransform>(t)) |
1195 |
save(out, Log_tran); |
1196 |
else if(ConstLookTransformRcPtr Look_tran = \ |
1197 |
DynamicPtrCast<const LookTransform>(t)) |
1198 |
save(out, Look_tran); |
1199 |
else if(ConstMatrixTransformRcPtr Matrix_tran = \ |
1200 |
DynamicPtrCast<const MatrixTransform>(t)) |
1201 |
save(out, Matrix_tran); |
1202 |
else if(ConstTruelightTransformRcPtr Truelight_tran = \ |
1203 |
DynamicPtrCast<const TruelightTransform>(t)) |
1204 |
save(out, Truelight_tran); |
1205 |
else |
1206 |
throw Exception("Unsupported Transform() type for serialization."); |
1121 |
} |
1207 |
} |
1122 |
if(strcmp(t->getRecorder(), "") != 0) |
1208 |
|
|
|
1209 |
// ColorSpace |
1210 |
|
1211 |
inline void load(const YAML::Node& node, ColorSpaceRcPtr& cs) |
1123 |
{ |
1212 |
{ |
1124 |
out << YAML::Key << "recorder"; |
1213 |
if(node.Tag() != "ColorSpace") |
1125 |
out << YAML::Value << YAML::Flow << t->getRecorder(); |
1214 |
return; // not a !<ColorSpace> tag |
|
|
1215 |
|
1216 |
std::string key, stringval; |
1217 |
bool boolval; |
1218 |
|
1219 |
for (Iterator iter = node.begin(); |
1220 |
iter != node.end(); |
1221 |
++iter) |
1222 |
{ |
1223 |
const YAML::Node& first = get_first(iter); |
1224 |
const YAML::Node& second = get_second(iter); |
1225 |
|
1226 |
load(first, key); |
1227 |
|
1228 |
if (second.Type() == YAML::NodeType::Null) continue; |
1229 |
|
1230 |
if(key == "name") |
1231 |
{ |
1232 |
load(second, stringval); |
1233 |
cs->setName(stringval.c_str()); |
1234 |
} |
1235 |
else if(key == "description") |
1236 |
{ |
1237 |
load(second, stringval); |
1238 |
cs->setDescription(stringval.c_str()); |
1239 |
} |
1240 |
else if(key == "family") |
1241 |
{ |
1242 |
load(second, stringval); |
1243 |
cs->setFamily(stringval.c_str()); |
1244 |
} |
1245 |
else if(key == "equalitygroup") |
1246 |
{ |
1247 |
load(second, stringval); |
1248 |
cs->setEqualityGroup(stringval.c_str()); |
1249 |
} |
1250 |
else if(key == "bitdepth") |
1251 |
{ |
1252 |
BitDepth ret; |
1253 |
load(second, ret); |
1254 |
cs->setBitDepth(ret); |
1255 |
} |
1256 |
else if(key == "isdata") |
1257 |
{ |
1258 |
load(second, boolval); |
1259 |
cs->setIsData(boolval); |
1260 |
} |
1261 |
else if(key == "allocation") |
1262 |
{ |
1263 |
Allocation val; |
1264 |
load(second, val); |
1265 |
cs->setAllocation(val); |
1266 |
} |
1267 |
else if(key == "allocationvars") |
1268 |
{ |
1269 |
std::vector<float> val; |
1270 |
load(second, val); |
1271 |
if(!val.empty()) |
1272 |
cs->setAllocationVars(static_cast<int>(val.size()), &val[0]); |
1273 |
} |
1274 |
else if(key == "to_reference") |
1275 |
{ |
1276 |
TransformRcPtr val; |
1277 |
load(second, val); |
1278 |
cs->setTransform(val, COLORSPACE_DIR_TO_REFERENCE); |
1279 |
} |
1280 |
else if(key == "from_reference") |
1281 |
{ |
1282 |
TransformRcPtr val; |
1283 |
load(second, val); |
1284 |
cs->setTransform(val, COLORSPACE_DIR_FROM_REFERENCE); |
1285 |
} |
1286 |
else |
1287 |
{ |
1288 |
LogUnknownKeyWarning(node.Tag(), first); |
1289 |
} |
1290 |
} |
1126 |
} |
1291 |
} |
1127 |
if(strcmp(t->getPrint(), "") != 0) |
1292 |
|
|
|
1293 |
inline void save(YAML::Emitter& out, ConstColorSpaceRcPtr cs) |
1128 |
{ |
1294 |
{ |
1129 |
out << YAML::Key << "print"; |
1295 |
out << YAML::VerbatimTag("ColorSpace"); |
1130 |
out << YAML::Value << YAML::Flow << t->getPrint(); |
1296 |
out << YAML::BeginMap; |
|
|
1297 |
|
1298 |
out << YAML::Key << "name" << YAML::Value << cs->getName(); |
1299 |
out << YAML::Key << "family" << YAML::Value << cs->getFamily(); |
1300 |
out << YAML::Key << "equalitygroup" << YAML::Value << cs->getEqualityGroup(); |
1301 |
out << YAML::Key << "bitdepth" << YAML::Value; |
1302 |
save(out, cs->getBitDepth()); |
1303 |
if(cs->getDescription() != NULL && strlen(cs->getDescription()) > 0) |
1304 |
{ |
1305 |
out << YAML::Key << "description"; |
1306 |
out << YAML::Value << YAML::Literal << cs->getDescription(); |
1307 |
} |
1308 |
out << YAML::Key << "isdata" << YAML::Value << cs->isData(); |
1309 |
|
1310 |
out << YAML::Key << "allocation" << YAML::Value; |
1311 |
save(out, cs->getAllocation()); |
1312 |
if(cs->getAllocationNumVars() > 0) |
1313 |
{ |
1314 |
std::vector<float> allocationvars(cs->getAllocationNumVars()); |
1315 |
cs->getAllocationVars(&allocationvars[0]); |
1316 |
out << YAML::Key << "allocationvars"; |
1317 |
out << YAML::Flow << YAML::Value << allocationvars; |
1318 |
} |
1319 |
|
1320 |
ConstTransformRcPtr toref = \ |
1321 |
cs->getTransform(COLORSPACE_DIR_TO_REFERENCE); |
1322 |
if(toref) |
1323 |
{ |
1324 |
out << YAML::Key << "to_reference" << YAML::Value; |
1325 |
save(out, toref); |
1326 |
} |
1327 |
|
1328 |
ConstTransformRcPtr fromref = \ |
1329 |
cs->getTransform(COLORSPACE_DIR_FROM_REFERENCE); |
1330 |
if(fromref) |
1331 |
{ |
1332 |
out << YAML::Key << "from_reference" << YAML::Value; |
1333 |
save(out, fromref); |
1334 |
} |
1335 |
|
1336 |
out << YAML::EndMap; |
1337 |
out << YAML::Newline; |
1131 |
} |
1338 |
} |
1132 |
if(strcmp(t->getLamp(), "") != 0) |
1339 |
|
|
|
1340 |
// Look |
1341 |
|
1342 |
inline void load(const YAML::Node& node, LookRcPtr& look) |
1133 |
{ |
1343 |
{ |
1134 |
out << YAML::Key << "lamp"; |
1344 |
if(node.Tag() != "Look") |
1135 |
out << YAML::Value << YAML::Flow << t->getLamp(); |
1345 |
return; |
|
|
1346 |
|
1347 |
std::string key, stringval; |
1348 |
|
1349 |
for (Iterator iter = node.begin(); |
1350 |
iter != node.end(); |
1351 |
++iter) |
1352 |
{ |
1353 |
const YAML::Node& first = get_first(iter); |
1354 |
const YAML::Node& second = get_second(iter); |
1355 |
|
1356 |
load(first, key); |
1357 |
|
1358 |
if (second.Type() == YAML::NodeType::Null) continue; |
1359 |
|
1360 |
if(key == "name") |
1361 |
{ |
1362 |
load(second, stringval); |
1363 |
look->setName(stringval.c_str()); |
1364 |
} |
1365 |
else if(key == "process_space") |
1366 |
{ |
1367 |
load(second, stringval); |
1368 |
look->setProcessSpace(stringval.c_str()); |
1369 |
} |
1370 |
else if(key == "transform") |
1371 |
{ |
1372 |
TransformRcPtr val; |
1373 |
load(second, val); |
1374 |
look->setTransform(val); |
1375 |
} |
1376 |
else if(key == "inverse_transform") |
1377 |
{ |
1378 |
TransformRcPtr val; |
1379 |
load(second, val); |
1380 |
look->setInverseTransform(val); |
1381 |
} |
1382 |
else |
1383 |
{ |
1384 |
LogUnknownKeyWarning(node.Tag(), first); |
1385 |
} |
1386 |
} |
1136 |
} |
1387 |
} |
1137 |
if(strcmp(t->getOutputCamera(), "") != 0) |
1388 |
|
|
|
1389 |
inline void save(YAML::Emitter& out, ConstLookRcPtr look) |
1138 |
{ |
1390 |
{ |
1139 |
out << YAML::Key << "output_camera"; |
1391 |
out << YAML::VerbatimTag("Look"); |
1140 |
out << YAML::Value << YAML::Flow << t->getOutputCamera(); |
1392 |
out << YAML::BeginMap; |
|
|
1393 |
out << YAML::Key << "name" << YAML::Value << look->getName(); |
1394 |
out << YAML::Key << "process_space" << YAML::Value << look->getProcessSpace(); |
1395 |
|
1396 |
if(look->getTransform()) |
1397 |
{ |
1398 |
out << YAML::Key << "transform"; |
1399 |
out << YAML::Value; |
1400 |
save(out, look->getTransform()); |
1401 |
} |
1402 |
|
1403 |
if(look->getInverseTransform()) |
1404 |
{ |
1405 |
out << YAML::Key << "inverse_transform"; |
1406 |
out << YAML::Value; |
1407 |
save(out, look->getInverseTransform()); |
1408 |
} |
1409 |
|
1410 |
out << YAML::EndMap; |
1411 |
out << YAML::Newline; |
1141 |
} |
1412 |
} |
1142 |
if(strcmp(t->getDisplay(), "") != 0) |
1413 |
|
|
|
1414 |
// Config |
1415 |
|
1416 |
inline void load(const YAML::Node& node, ConfigRcPtr& c, const char* filename) |
1143 |
{ |
1417 |
{ |
1144 |
out << YAML::Key << "display"; |
1418 |
|
1145 |
out << YAML::Value << YAML::Flow << t->getDisplay(); |
1419 |
// check profile version |
|
|
1420 |
int profile_version = 0; |
1421 |
#ifdef OLDYAML |
1422 |
if(node.FindValue("ocio_profile_version") == NULL) |
1423 |
#else |
1424 |
if(node["ocio_profile_version"] == NULL) |
1425 |
#endif |
1426 |
{ |
1427 |
std::ostringstream os; |
1428 |
os << "The specified file "; |
1429 |
os << "does not appear to be an OCIO configuration."; |
1430 |
throw Exception (os.str().c_str()); |
1431 |
} |
1432 |
|
1433 |
load(node["ocio_profile_version"], profile_version); |
1434 |
if(profile_version > 1) |
1435 |
{ |
1436 |
std::ostringstream os; |
1437 |
os << "This .ocio config "; |
1438 |
if(filename && *filename) |
1439 |
{ |
1440 |
os << " '" << filename << "' "; |
1441 |
} |
1442 |
os << "is version " << profile_version << ". "; |
1443 |
os << "This version of the OpenColorIO library (" << OCIO_VERSION ") "; |
1444 |
os << "is not known to be able to load this profile. "; |
1445 |
os << "An attempt will be made, but there are no guarantees that the "; |
1446 |
os << "results will be accurate. Continue at your own risk."; |
1447 |
LogWarning(os.str()); |
1448 |
} |
1449 |
|
1450 |
std::string key, stringval; |
1451 |
bool boolval = false; |
1452 |
EnvironmentMode mode = ENV_ENVIRONMENT_LOAD_ALL; |
1453 |
|
1454 |
for (Iterator iter = node.begin(); |
1455 |
iter != node.end(); |
1456 |
++iter) |
1457 |
{ |
1458 |
const YAML::Node& first = get_first(iter); |
1459 |
const YAML::Node& second = get_second(iter); |
1460 |
|
1461 |
load(first, key); |
1462 |
|
1463 |
if (second.Type() == YAML::NodeType::Null) continue; |
1464 |
|
1465 |
if(key == "ocio_profile_version") { } // Already handled above. |
1466 |
else if(key == "environment") |
1467 |
{ |
1468 |
mode = ENV_ENVIRONMENT_LOAD_PREDEFINED; |
1469 |
if(second.Type() != YAML::NodeType::Map) |
1470 |
{ |
1471 |
std::ostringstream os; |
1472 |
os << "'environment' field needs to be a (name: key) map."; |
1473 |
throw Exception(os.str().c_str()); |
1474 |
} |
1475 |
for (Iterator it = second.begin(); |
1476 |
it != second.end(); |
1477 |
++it) |
1478 |
{ |
1479 |
std::string k, v; |
1480 |
load(get_first(it), k); |
1481 |
load(get_second(it), v); |
1482 |
c->addEnvironmentVar(k.c_str(), v.c_str()); |
1483 |
} |
1484 |
} |
1485 |
else if(key == "search_path" || key == "resource_path") |
1486 |
{ |
1487 |
load(second, stringval); |
1488 |
c->setSearchPath(stringval.c_str()); |
1489 |
} |
1490 |
else if(key == "strictparsing") |
1491 |
{ |
1492 |
load(second, boolval); |
1493 |
c->setStrictParsingEnabled(boolval); |
1494 |
} |
1495 |
else if(key == "description") |
1496 |
{ |
1497 |
load(second, stringval); |
1498 |
c->setDescription(stringval.c_str()); |
1499 |
} |
1500 |
else if(key == "luma") |
1501 |
{ |
1502 |
std::vector<float> val; |
1503 |
load(second, val); |
1504 |
if(val.size() != 3) |
1505 |
{ |
1506 |
std::ostringstream os; |
1507 |
os << "'luma' field must be 3 "; |
1508 |
os << "floats. Found '" << val.size() << "'."; |
1509 |
throw Exception(os.str().c_str()); |
1510 |
} |
1511 |
c->setDefaultLumaCoefs(&val[0]); |
1512 |
} |
1513 |
else if(key == "roles") |
1514 |
{ |
1515 |
if(second.Type() != YAML::NodeType::Map) |
1516 |
{ |
1517 |
std::ostringstream os; |
1518 |
os << "'roles' field needs to be a (name: key) map."; |
1519 |
throw Exception(os.str().c_str()); |
1520 |
} |
1521 |
for (Iterator it = second.begin(); |
1522 |
it != second.end(); |
1523 |
++it) |
1524 |
{ |
1525 |
std::string k, v; |
1526 |
load(get_first(it), k); |
1527 |
load(get_second(it), v); |
1528 |
c->setRole(k.c_str(), v.c_str()); |
1529 |
} |
1530 |
} |
1531 |
else if(key == "displays") |
1532 |
{ |
1533 |
if(second.Type() != YAML::NodeType::Map) |
1534 |
{ |
1535 |
std::ostringstream os; |
1536 |
os << "'displays' field needs to be a (name: key) map."; |
1537 |
throw Exception(os.str().c_str()); |
1538 |
} |
1539 |
for (Iterator it = second.begin(); |
1540 |
it != second.end(); |
1541 |
++it) |
1542 |
{ |
1543 |
std::string display; |
1544 |
load(get_first(it), display); |
1545 |
const YAML::Node& dsecond = get_second(it); |
1546 |
for(unsigned i = 0; i < dsecond.size(); ++i) |
1547 |
{ |
1548 |
View view; |
1549 |
load(dsecond[i], view); |
1550 |
c->addDisplay(display.c_str(), view.name.c_str(), |
1551 |
view.colorspace.c_str(), view.looks.c_str()); |
1552 |
} |
1553 |
} |
1554 |
} |
1555 |
else if(key == "active_displays") |
1556 |
{ |
1557 |
std::vector<std::string> display; |
1558 |
load(second, display); |
1559 |
std::string displays = JoinStringEnvStyle(display); |
1560 |
c->setActiveDisplays(displays.c_str()); |
1561 |
} |
1562 |
else if(key == "active_views") |
1563 |
{ |
1564 |
std::vector<std::string> view; |
1565 |
load(second, view); |
1566 |
std::string views = JoinStringEnvStyle(view); |
1567 |
c->setActiveViews(views.c_str()); |
1568 |
} |
1569 |
else if(key == "colorspaces") |
1570 |
{ |
1571 |
if(second.Type() != YAML::NodeType::Sequence) |
1572 |
{ |
1573 |
std::ostringstream os; |
1574 |
os << "'colorspaces' field needs to be a (- !<ColorSpace>) list."; |
1575 |
throw Exception(os.str().c_str()); |
1576 |
} |
1577 |
for(unsigned i = 0; i < second.size(); ++i) |
1578 |
{ |
1579 |
if(second[i].Tag() == "ColorSpace") |
1580 |
{ |
1581 |
ColorSpaceRcPtr cs = ColorSpace::Create(); |
1582 |
load(second[i], cs); |
1583 |
for(int ii = 0; ii < c->getNumColorSpaces(); ++ii) |
1584 |
{ |
1585 |
if(strcmp(c->getColorSpaceNameByIndex(ii), cs->getName()) == 0) |
1586 |
{ |
1587 |
std::ostringstream os; |
1588 |
os << "Colorspace with name '" << cs->getName() << "' already defined."; |
1589 |
throw Exception(os.str().c_str()); |
1590 |
} |
1591 |
} |
1592 |
c->addColorSpace(cs); |
1593 |
} |
1594 |
else |
1595 |
{ |
1596 |
std::ostringstream os; |
1597 |
os << "Unknown element found in colorspaces:"; |
1598 |
os << second[i].Tag() << ". Only ColorSpace(s)"; |
1599 |
os << " currently handled."; |
1600 |
LogWarning(os.str()); |
1601 |
} |
1602 |
} |
1603 |
} |
1604 |
else if(key == "looks") |
1605 |
{ |
1606 |
if(second.Type() != YAML::NodeType::Sequence) |
1607 |
{ |
1608 |
std::ostringstream os; |
1609 |
os << "'looks' field needs to be a (- !<Look>) list."; |
1610 |
throw Exception(os.str().c_str()); |
1611 |
} |
1612 |
|
1613 |
for(unsigned i = 0; i < second.size(); ++i) |
1614 |
{ |
1615 |
if(second[i].Tag() == "Look") |
1616 |
{ |
1617 |
LookRcPtr look = Look::Create(); |
1618 |
load(second[i], look); |
1619 |
c->addLook(look); |
1620 |
} |
1621 |
else |
1622 |
{ |
1623 |
std::ostringstream os; |
1624 |
os << "Unknown element found in looks:"; |
1625 |
os << second[i].Tag() << ". Only Look(s)"; |
1626 |
os << " currently handled."; |
1627 |
LogWarning(os.str()); |
1628 |
} |
1629 |
} |
1630 |
} |
1631 |
else |
1632 |
{ |
1633 |
LogUnknownKeyWarning("profile", first); |
1634 |
} |
1635 |
} |
1636 |
|
1637 |
if(filename) |
1638 |
{ |
1639 |
std::string realfilename = pystring::os::path::abspath(filename); |
1640 |
std::string configrootdir = pystring::os::path::dirname(realfilename); |
1641 |
c->setWorkingDir(configrootdir.c_str()); |
1642 |
} |
1643 |
|
1644 |
c->setEnvironmentMode(mode); |
1645 |
c->loadEnvironment(); |
1646 |
|
1647 |
if(mode == ENV_ENVIRONMENT_LOAD_ALL) |
1648 |
{ |
1649 |
std::ostringstream os; |
1650 |
os << "This .ocio config "; |
1651 |
if(filename && *filename) |
1652 |
{ |
1653 |
os << " '" << filename << "' "; |
1654 |
} |
1655 |
os << "has no environment section defined. The default behaviour is to "; |
1656 |
os << "load all environment variables (" << c->getNumEnvironmentVars() << ")"; |
1657 |
os << ", which reduces the efficiency of OCIO's caching. Considering "; |
1658 |
os << "predefining the environment variables used."; |
1659 |
LogDebug(os.str()); |
1660 |
} |
1661 |
|
1146 |
} |
1662 |
} |
1147 |
if(strcmp(t->getCubeInput(), "") != 0) |
1663 |
|
|
|
1664 |
inline void save(YAML::Emitter& out, const Config* c) |
1148 |
{ |
1665 |
{ |
1149 |
out << YAML::Key << "cube_input"; |
1666 |
out << YAML::Block; |
1150 |
out << YAML::Value << YAML::Flow << t->getCubeInput(); |
1667 |
out << YAML::BeginMap; |
|
|
1668 |
out << YAML::Key << "ocio_profile_version" << YAML::Value << 1; |
1669 |
out << YAML::Newline; |
1670 |
#ifndef OLDYAML |
1671 |
out << YAML::Newline; |
1672 |
#endif |
1673 |
|
1674 |
if(c->getNumEnvironmentVars() > 0) |
1675 |
{ |
1676 |
out << YAML::Key << "environment"; |
1677 |
out << YAML::Value << YAML::BeginMap; |
1678 |
for(unsigned i = 0; i < c->getNumEnvironmentVars(); ++i) |
1679 |
{ |
1680 |
const char* name = c->getEnvironmentVarNameByIndex(i); |
1681 |
out << YAML::Key << name; |
1682 |
out << YAML::Value << c->getEnvironmentVarDefault(name); |
1683 |
} |
1684 |
out << YAML::EndMap; |
1685 |
out << YAML::Newline; |
1686 |
} |
1687 |
out << YAML::Key << "search_path" << YAML::Value << c->getSearchPath(); |
1688 |
out << YAML::Key << "strictparsing" << YAML::Value << c->isStrictParsingEnabled(); |
1689 |
|
1690 |
std::vector<float> luma(3, 0.f); |
1691 |
c->getDefaultLumaCoefs(&luma[0]); |
1692 |
out << YAML::Key << "luma" << YAML::Value << YAML::Flow << luma; |
1693 |
|
1694 |
if(c->getDescription() != NULL && strlen(c->getDescription()) > 0) |
1695 |
{ |
1696 |
out << YAML::Newline; |
1697 |
out << YAML::Key << "description"; |
1698 |
out << YAML::Value << c->getDescription(); |
1699 |
out << YAML::Newline; |
1700 |
} |
1701 |
|
1702 |
// Roles |
1703 |
out << YAML::Newline; |
1704 |
#ifndef OLDYAML |
1705 |
out << YAML::Newline; |
1706 |
#endif |
1707 |
out << YAML::Key << "roles"; |
1708 |
out << YAML::Value << YAML::BeginMap; |
1709 |
for(unsigned i = 0; i < c->getNumRoles(); ++i) |
1710 |
{ |
1711 |
const char* role = c->getRoleName(i); |
1712 |
out << YAML::Key << role; |
1713 |
out << YAML::Value << c->getColorSpace(role)->getName(); |
1714 |
} |
1715 |
out << YAML::EndMap; |
1716 |
#ifndef OLDYAML |
1717 |
out << YAML::Newline; |
1718 |
#endif |
1719 |
|
1720 |
// Displays |
1721 |
out << YAML::Newline; |
1722 |
out << YAML::Key << "displays"; |
1723 |
out << YAML::Value << YAML::BeginMap; |
1724 |
for(unsigned i = 0; i < c->getNumDisplays(); ++i) |
1725 |
{ |
1726 |
const char* display = c->getDisplay(i); |
1727 |
out << YAML::Key << display; |
1728 |
out << YAML::Value << YAML::BeginSeq; |
1729 |
for(unsigned v = 0; v < c->getNumViews(display); ++v) |
1730 |
{ |
1731 |
View dview; |
1732 |
dview.name = c->getView(display, v); |
1733 |
dview.colorspace = c->getDisplayColorSpaceName(display, dview.name.c_str()); |
1734 |
if(c->getDisplayLooks(display, dview.name.c_str()) != NULL) |
1735 |
dview.looks = c->getDisplayLooks(display, dview.name.c_str()); |
1736 |
save(out, dview); |
1737 |
|
1738 |
} |
1739 |
out << YAML::EndSeq; |
1740 |
} |
1741 |
out << YAML::EndMap; |
1742 |
|
1743 |
#ifndef OLDYAML |
1744 |
out << YAML::Newline; |
1745 |
#endif |
1746 |
out << YAML::Newline; |
1747 |
out << YAML::Key << "active_displays"; |
1748 |
std::vector<std::string> active_displays; |
1749 |
if(c->getActiveDisplays() != NULL && strlen(c->getActiveDisplays()) > 0) |
1750 |
SplitStringEnvStyle(active_displays, c->getActiveDisplays()); |
1751 |
out << YAML::Value << YAML::Flow << active_displays; |
1752 |
out << YAML::Key << "active_views"; |
1753 |
std::vector<std::string> active_views; |
1754 |
if(c->getActiveViews() != NULL && strlen(c->getActiveViews()) > 0) |
1755 |
SplitStringEnvStyle(active_views, c->getActiveViews()); |
1756 |
out << YAML::Value << YAML::Flow << active_views; |
1757 |
#ifndef OLDYAML |
1758 |
out << YAML::Newline; |
1759 |
#endif |
1760 |
|
1761 |
// Looks |
1762 |
if(c->getNumLooks() > 0) |
1763 |
{ |
1764 |
out << YAML::Newline; |
1765 |
out << YAML::Key << "looks"; |
1766 |
out << YAML::Value << YAML::BeginSeq; |
1767 |
for(unsigned i = 0; i < c->getNumLooks(); ++i) |
1768 |
{ |
1769 |
const char* name = c->getLookNameByIndex(i); |
1770 |
save(out, c->getLook(name)); |
1771 |
} |
1772 |
out << YAML::EndSeq; |
1773 |
out << YAML::Newline; |
1774 |
} |
1775 |
|
1776 |
// ColorSpaces |
1777 |
{ |
1778 |
out << YAML::Newline; |
1779 |
out << YAML::Key << "colorspaces"; |
1780 |
out << YAML::Value << YAML::BeginSeq; |
1781 |
for(unsigned i = 0; i < c->getNumColorSpaces(); ++i) |
1782 |
{ |
1783 |
const char* name = c->getColorSpaceNameByIndex(i); |
1784 |
save(out, c->getColorSpace(name)); |
1785 |
} |
1786 |
out << YAML::EndSeq; |
1787 |
} |
1788 |
|
1789 |
out << YAML::EndMap; |
1151 |
} |
1790 |
} |
1152 |
|
1791 |
|
1153 |
EmitBaseTransformKeyValues(out, t); |
|
|
1154 |
|
1155 |
out << YAML::EndMap; |
1156 |
return out; |
1157 |
} |
1792 |
} |
1158 |
|
1793 |
|
1159 |
/////////////////////////////////////////////////////////////////////////// |
1794 |
/////////////////////////////////////////////////////////////////////////// |
1160 |
// Enums |
|
|
1161 |
|
1162 |
YAML::Emitter& operator << (YAML::Emitter& out, BitDepth depth) { |
1163 |
out << BitDepthToString(depth); |
1164 |
return out; |
1165 |
} |
1166 |
|
1167 |
void operator >> (const YAML::Node& node, BitDepth& depth) { |
1168 |
std::string str; |
1169 |
node.Read<std::string>(str); |
1170 |
depth = BitDepthFromString(str.c_str()); |
1171 |
} |
1172 |
|
1173 |
YAML::Emitter& operator << (YAML::Emitter& out, Allocation alloc) { |
1174 |
out << AllocationToString(alloc); |
1175 |
return out; |
1176 |
} |
1177 |
|
1178 |
void operator >> (const YAML::Node& node, Allocation& alloc) { |
1179 |
std::string str; |
1180 |
node.Read<std::string>(str); |
1181 |
alloc = AllocationFromString(str.c_str()); |
1182 |
} |
1183 |
|
1184 |
YAML::Emitter& operator << (YAML::Emitter& out, ColorSpaceDirection dir) { |
1185 |
out << ColorSpaceDirectionToString(dir); |
1186 |
return out; |
1187 |
} |
1188 |
|
1795 |
|
1189 |
void operator >> (const YAML::Node& node, ColorSpaceDirection& dir) { |
1796 |
void OCIOYaml::open(std::istream& istream, ConfigRcPtr& c, const char* filename) const |
1190 |
std::string str; |
1797 |
{ |
1191 |
node.Read<std::string>(str); |
1798 |
try |
1192 |
dir = ColorSpaceDirectionFromString(str.c_str()); |
1799 |
{ |
1193 |
} |
1800 |
#ifdef OLDYAML |
1194 |
|
1801 |
YAML::Parser parser(istream); |
1195 |
YAML::Emitter& operator << (YAML::Emitter& out, TransformDirection dir) { |
1802 |
YAML::Node node; |
1196 |
out << TransformDirectionToString(dir); |
1803 |
parser.GetNextDocument(node); |
1197 |
return out; |
1804 |
#else |
1198 |
} |
1805 |
YAML::Node node = YAML::Load(istream); |
1199 |
|
1806 |
#endif |
1200 |
void operator >> (const YAML::Node& node, TransformDirection& dir) { |
1807 |
load(node, c, filename); |
1201 |
std::string str; |
1808 |
} |
1202 |
node.Read<std::string>(str); |
1809 |
catch(const std::exception & e) |
1203 |
dir = TransformDirectionFromString(str.c_str()); |
1810 |
{ |
1204 |
} |
1811 |
std::ostringstream os; |
1205 |
|
1812 |
os << "Error: Loading the OCIO profile "; |
1206 |
YAML::Emitter& operator << (YAML::Emitter& out, Interpolation interp) { |
1813 |
if(filename) os << "'" << filename << "' "; |
1207 |
out << InterpolationToString(interp); |
1814 |
os << "failed. " << e.what(); |
1208 |
return out; |
1815 |
throw Exception(os.str().c_str()); |
|
|
1816 |
} |
1209 |
} |
1817 |
} |
1210 |
|
1818 |
|
1211 |
void operator >> (const YAML::Node& node, Interpolation& interp) { |
1819 |
void OCIOYaml::write(std::ostream& ostream, const Config* c) const |
1212 |
std::string str; |
1820 |
{ |
1213 |
node.Read<std::string>(str); |
1821 |
YAML::Emitter out; |
1214 |
interp = InterpolationFromString(str.c_str()); |
1822 |
save(out, c); |
|
|
1823 |
ostream << out.c_str(); |
1215 |
} |
1824 |
} |
1216 |
|
1825 |
|
1217 |
} |
1826 |
} |