11// SPDX-License-Identifier: BSD-3-Clause
22// Copyright Contributors to the OpenColorIO Project.
33
4-
54#include < iostream>
65
76#include < OpenColorIO/OpenColorIO.h>
87
9- #include " transforms/FileTransform.h"
108#include " BakingUtils.h"
119#include " MathUtils.h"
12-
10+ # include " transforms/FileTransform.h "
1311
1412namespace OCIO_NAMESPACE
1513{
@@ -19,18 +17,17 @@ BakerRcPtr Baker::Create()
1917 return BakerRcPtr (new Baker (), &deleter);
2018}
2119
22- void Baker::deleter (Baker* c)
20+ void Baker::deleter (Baker * c)
2321{
2422 delete c;
2523}
2624
2725class Baker ::Impl
2826{
2927public:
30-
3128 ConfigRcPtr m_config;
3229 std::string m_formatName;
33- FormatMetadataImpl m_formatMetadata{ METADATA_ROOT, " " };
30+ FormatMetadataImpl m_formatMetadata{METADATA_ROOT, " " };
3431 std::string m_inputSpace;
3532 std::string m_shaperSpace;
3633 std::string m_looks;
@@ -40,40 +37,38 @@ class Baker::Impl
4037 int m_shapersize;
4138 int m_cubesize;
4239
43- Impl () :
44- m_shapersize (-1 ),
45- m_cubesize (-1 )
40+ Impl ()
41+ : m_shapersize(-1 )
42+ , m_cubesize(-1 )
4643 {
4744 }
4845
4946 Impl (const Impl &) = delete ;
5047
51- ~Impl ()
52- {
53- }
48+ ~Impl () {}
5449
55- Impl& operator = (const Impl & rhs)
50+ Impl & operator =(const Impl & rhs)
5651 {
5752 if (this != &rhs)
5853 {
59- m_config = rhs.m_config ;
60- m_formatName = rhs.m_formatName ;
54+ m_config = rhs.m_config ;
55+ m_formatName = rhs.m_formatName ;
6156 m_formatMetadata = rhs.m_formatMetadata ;
62- m_inputSpace = rhs.m_inputSpace ;
63- m_shaperSpace = rhs.m_shaperSpace ;
64- m_looks = rhs.m_looks ;
65- m_targetSpace = rhs.m_targetSpace ;
66- m_display = rhs.m_display ;
67- m_view = rhs.m_view ;
68- m_shapersize = rhs.m_shapersize ;
69- m_cubesize = rhs.m_cubesize ;
57+ m_inputSpace = rhs.m_inputSpace ;
58+ m_shaperSpace = rhs.m_shaperSpace ;
59+ m_looks = rhs.m_looks ;
60+ m_targetSpace = rhs.m_targetSpace ;
61+ m_display = rhs.m_display ;
62+ m_view = rhs.m_view ;
63+ m_shapersize = rhs.m_shapersize ;
64+ m_cubesize = rhs.m_cubesize ;
7065 }
7166 return *this ;
7267 }
7368};
7469
7570Baker::Baker ()
76- : m_impl(new Baker::Impl)
71+ : m_impl(new Baker::Impl)
7772{
7873}
7974
@@ -86,7 +81,7 @@ Baker::~Baker()
8681BakerRcPtr Baker::createEditableCopy () const
8782{
8883 BakerRcPtr oven = Baker::Create ();
89- *oven->m_impl = *m_impl;
84+ *oven->m_impl = *m_impl;
9085 return oven;
9186}
9287
@@ -211,7 +206,7 @@ void Baker::setDisplayView(const char * display, const char * view)
211206 }
212207
213208 getImpl ()->m_display = display;
214- getImpl ()->m_view = view;
209+ getImpl ()->m_view = view;
215210}
216211
217212void Baker::setShaperSize (int shapersize)
@@ -236,9 +231,9 @@ int Baker::getCubeSize() const
236231
237232void Baker::bake (std::ostream & os) const
238233{
239- FileFormat* fmt = FormatRegistry::GetInstance ().getFileFormatByName (getImpl ()->m_formatName );
234+ FileFormat * fmt = FormatRegistry::GetInstance ().getFileFormatByName (getImpl ()->m_formatName );
240235
241- if (!fmt)
236+ if (!fmt)
242237 {
243238 std::ostringstream err;
244239 err << " The format named '" << getImpl ()->m_formatName ;
@@ -250,58 +245,57 @@ void Baker::bake(std::ostream & os) const
250245 fmt->getFormatInfo (fmtInfoVec);
251246 FormatInfo fmtInfo = fmtInfoVec[0 ];
252247
253- const std::string & inputSpace = getImpl ()->m_inputSpace ;
248+ const std::string & inputSpace = getImpl ()->m_inputSpace ;
254249 const std::string & targetSpace = getImpl ()->m_targetSpace ;
255250 const std::string & shaperSpace = getImpl ()->m_shaperSpace ;
256- const std::string & display = getImpl ()->m_display ;
257- const std::string & view = getImpl ()->m_view ;
251+ const std::string & display = getImpl ()->m_display ;
252+ const std::string & view = getImpl ()->m_view ;
258253
259254 const bool displayViewMode = !display.empty () && !view.empty ();
260- const bool colorSpaceMode = !targetSpace.empty ();
255+ const bool colorSpaceMode = !targetSpace.empty ();
261256
262257 // Settings validation.
263- if (!getConfig ())
258+ if (!getConfig ())
264259 {
265260 throw Exception (" No OCIO config has been set." );
266261 }
267262
268- if (inputSpace.empty ())
263+ if (inputSpace.empty ())
269264 {
270265 throw Exception (" No input space has been set." );
271266 }
272267
273- if (!displayViewMode && !colorSpaceMode)
268+ if (!displayViewMode && !colorSpaceMode)
274269 {
275270 throw Exception (" No display / view or target colorspace has been set." );
276271 }
277272
278- if (displayViewMode && colorSpaceMode)
273+ if (displayViewMode && colorSpaceMode)
279274 {
280275 throw Exception (" Cannot use both display / view and target colorspace." );
281276 }
282277
283- if (!getConfig ()->getColorSpace (inputSpace.c_str ()))
278+ if (!getConfig ()->getColorSpace (inputSpace.c_str ()))
284279 {
285280 std::ostringstream os;
286281 os << " Could not find input colorspace '" << inputSpace << " '." ;
287282 throw Exception (os.str ().c_str ());
288283 }
289284
290- if (colorSpaceMode && !getConfig ()->getColorSpace (targetSpace.c_str ()))
285+ if (colorSpaceMode && !getConfig ()->getColorSpace (targetSpace.c_str ()))
291286 {
292287 std::ostringstream os;
293288 os << " Could not find target colorspace '" << targetSpace << " '." ;
294289 throw Exception (os.str ().c_str ());
295290 }
296291
297- if (displayViewMode)
292+ if (displayViewMode)
298293 {
299294 bool foundDisplay = false ;
300- bool foundView = false ;
295+ bool foundView = false ;
301296
302297 // Make sure we also search through inactive views.
303- auto hasViewByType = [this ](ViewType type, const char * display, const char * view)
304- {
298+ auto hasViewByType = [this ](ViewType type, const char * display, const char * view) {
305299 for (int i = 0 ; i < getConfig ()->getNumViews (type, display); ++i)
306300 {
307301 if (std::string (getConfig ()->getView (type, display, i)) == std::string (view))
@@ -343,43 +337,42 @@ void Baker::bake(std::ostream & os) const
343337 }
344338
345339 const bool bake_1D = fmtInfo.bake_capabilities == FORMAT_BAKE_CAPABILITY_1DLUT;
346- if (bake_1D && GetInputToTargetProcessor (*this )->hasChannelCrosstalk ())
340+ if (bake_1D && GetInputToTargetProcessor (*this )->hasChannelCrosstalk ())
347341 {
348342 std::ostringstream os;
349343 os << " The format '" << getImpl ()->m_formatName << " ' does not support" ;
350344 os << " transformations with channel crosstalk." ;
351345 throw Exception (os.str ().c_str ());
352346 }
353347
354- if (getCubeSize () != -1 && getCubeSize () < 2 )
348+ if (getCubeSize () != -1 && getCubeSize () < 2 )
355349 {
356350 throw Exception (" Cube size must be at least 2 if set." );
357351 }
358352
359- const bool supportShaper =
360- fmtInfo.bake_capabilities & FORMAT_BAKE_CAPABILITY_1D_3D_LUT ||
361- fmtInfo.bake_capabilities & FORMAT_BAKE_CAPABILITY_1DLUT;
362- if (!shaperSpace.empty () && !supportShaper)
353+ const bool supportShaper = fmtInfo.bake_capabilities & FORMAT_BAKE_CAPABILITY_1D_3D_LUT
354+ || fmtInfo.bake_capabilities & FORMAT_BAKE_CAPABILITY_1DLUT;
355+ if (!shaperSpace.empty () && !supportShaper)
363356 {
364357 std::ostringstream os;
365358 os << " The format '" << getImpl ()->m_formatName << " ' does not support shaper space." ;
366359 throw Exception (os.str ().c_str ());
367360 }
368361
369- if (!shaperSpace.empty () && getShaperSize () != -1 && getShaperSize () < 2 )
362+ if (!shaperSpace.empty () && getShaperSize () != -1 && getShaperSize () < 2 )
370363 {
371364 std::ostringstream os;
372365 os << " A shaper space '" << getShaperSpace () << " ' has" ;
373366 os << " been specified, so the shaper size must be 2 or larger." ;
374367 throw Exception (os.str ().c_str ());
375368 }
376369
377- if (!shaperSpace.empty ())
370+ if (!shaperSpace.empty ())
378371 {
379372 ConstCPUProcessorRcPtr inputToShaper = GetInputToShaperProcessor (*this );
380373 ConstCPUProcessorRcPtr shaperToInput = GetShaperToInputProcessor (*this );
381374
382- if (inputToShaper->hasChannelCrosstalk () || shaperToInput->hasChannelCrosstalk ())
375+ if (inputToShaper->hasChannelCrosstalk () || shaperToInput->hasChannelCrosstalk ())
383376 {
384377 std::ostringstream os;
385378 os << " The specified shaper space, '" << getShaperSpace ();
@@ -394,17 +387,17 @@ void Baker::bake(std::ostream & os) const
394387 {
395388 fmt->bake (*this , getImpl ()->m_formatName , os);
396389 }
397- catch (std::exception & e)
390+ catch (std::exception & e)
398391 {
399392 std::ostringstream err;
400393 err << " Error baking " << getImpl ()->m_formatName << " :" ;
401394 err << e.what ();
402395 throw Exception (err.str ().c_str ());
403396 }
404397
405- //
398+ //
406399 // TODO:
407- //
400+ //
408401 // - check limits of shaper and target, throw exception if we can't
409402 // write that much data in x format
410403 // - add some checks to make sure we are monotonic
0 commit comments