Skip to content

Commit 67cb724

Browse files
BernardLefebvrehodoulp
authored andcommitted
Adsk Contrib - Rework LogOpData to get ready for Log CTF parsing. (#674)
* Rework LogOpData to get ready for Log CTF parsing. Add LogAffineTransform. Add SSE and non SSE code path CPU and GPU implementation. * LogAffine transform: remove enum defining parameters order from the API. Adding get/set for each paramater. * Fix build after bad merge * Adjust SSE version of the baked LUT in test.
1 parent 03ac35d commit 67cb724

31 files changed

+3989
-653
lines changed

include/OpenColorIO/OpenColorTransforms.h

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,77 @@ OCIO_NAMESPACE_ENTER
616616
//!cpp:function::
617617
extern OCIOEXPORT std::ostream& operator<< (std::ostream&, const GroupTransform&);
618618

619-
619+
620+
//!rst:: //////////////////////////////////////////////////////////////////
621+
622+
//!cpp:class:: Applies a logarithm with an affine transform before and after.
623+
// Represents the Cineon lin-to-log type transforms.
624+
//
625+
// logSideSlope * log( linSideSlope * color + linSideOffset, base) + logSideOffset
626+
//
627+
// * Default values are: 1. * log( 1. * color + 0., 2.) + 0.
628+
// * Only the rgb channels are affected.
629+
class OCIOEXPORT LogAffineTransform : public Transform
630+
{
631+
public:
632+
//!cpp:function::
633+
static LogAffineTransformRcPtr Create();
634+
635+
//!cpp:function::
636+
virtual TransformRcPtr createEditableCopy() const;
637+
638+
//!cpp:function::
639+
virtual TransformDirection getDirection() const;
640+
//!cpp:function::
641+
virtual void setDirection(TransformDirection dir);
642+
643+
//!cpp:function:: Will throw if data is not valid.
644+
virtual void validate() const;
645+
646+
//!cpp:function::
647+
void setBase(double base);
648+
//!cpp:function::
649+
double getBase() const;
650+
651+
//!rst:: Set/Get values for each R, G, and B components.
652+
653+
//!cpp:function::
654+
void setLogSideSlopeValue(const double(&values)[3]);
655+
//!cpp:function::
656+
void setLogSideOffsetValue(const double(&values)[3]);
657+
//!cpp:function::
658+
void setLinSideSlopeValue(const double(&values)[3]);
659+
//!cpp:function::
660+
void setLinSideOffsetValue(const double(&values)[3]);
661+
//!cpp:function::
662+
void getLogSideSlopeValue(double(&values)[3]) const;
663+
//!cpp:function::
664+
void getLogSideOffsetValue(double(&values)[3]) const;
665+
//!cpp:function::
666+
void getLinSideSlopeValue(double(&values)[3]) const;
667+
//!cpp:function::
668+
void getLinSideOffsetValue(double(&values)[3]) const;
669+
670+
private:
671+
LogAffineTransform();
672+
LogAffineTransform(const LogTransform &);
673+
virtual ~LogAffineTransform();
674+
675+
LogAffineTransform& operator= (const LogAffineTransform &);
676+
677+
static void deleter(LogAffineTransform* t);
678+
679+
class Impl;
680+
friend class Impl;
681+
Impl * m_impl;
682+
Impl * getImpl() { return m_impl; }
683+
const Impl * getImpl() const { return m_impl; }
684+
};
685+
686+
//!cpp:function::
687+
extern OCIOEXPORT std::ostream& operator<< (std::ostream&, const LogAffineTransform&);
688+
689+
620690
//!rst:: //////////////////////////////////////////////////////////////////
621691

622692
//!cpp:class:: Represents log transform: log(color, base)
@@ -642,10 +712,10 @@ OCIO_NAMESPACE_ENTER
642712
virtual void validate() const;
643713

644714
//!cpp:function::
645-
void setBase(float val);
715+
void setBase(double val);
646716
//!cpp:function::
647-
float getBase() const;
648-
717+
double getBase() const;
718+
649719
private:
650720
LogTransform();
651721
LogTransform(const LogTransform &);
@@ -664,10 +734,8 @@ OCIO_NAMESPACE_ENTER
664734

665735
//!cpp:function::
666736
extern OCIOEXPORT std::ostream& operator<< (std::ostream&, const LogTransform&);
667-
668-
669-
670-
737+
738+
671739
//!rst:: //////////////////////////////////////////////////////////////////
672740

673741
//!cpp:class::
@@ -726,8 +794,6 @@ OCIO_NAMESPACE_ENTER
726794
extern OCIOEXPORT std::ostream& operator<< (std::ostream&, const LookTransform&);
727795

728796

729-
730-
731797
//!rst:: //////////////////////////////////////////////////////////////////
732798

733799
//!cpp:class:: Represents an MX+B Matrix transform

include/OpenColorIO/OpenColorTypes.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,13 @@ OCIO_NAMESPACE_ENTER
172172
typedef OCIO_SHARED_PTR<const LogTransform> ConstLogTransformRcPtr;
173173
//!cpp:type::
174174
typedef OCIO_SHARED_PTR<LogTransform> LogTransformRcPtr;
175-
175+
176+
class OCIOEXPORT LogAffineTransform;
177+
//!cpp:type::
178+
typedef OCIO_SHARED_PTR<const LogAffineTransform> ConstLogAffineTransformRcPtr;
179+
//!cpp:type::
180+
typedef OCIO_SHARED_PTR<LogAffineTransform> LogAffineTransformRcPtr;
181+
176182
class OCIOEXPORT LookTransform;
177183
//!cpp:type::
178184
typedef OCIO_SHARED_PTR<const LookTransform> ConstLookTransformRcPtr;

src/OpenColorIO/Baker.cpp

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,113 @@ OIIO_ADD_TEST(Baker_Unit_Tests, test_listlutwriters)
295295
}
296296
*/
297297

298+
OIIO_ADD_TEST(Baker_Unit_Tests, bake)
299+
{
300+
// SSE aware test, similar to python test.
301+
OCIO::BakerRcPtr bake = OCIO::Baker::Create();
302+
303+
static const std::string myProfile =
304+
"ocio_profile_version: 1\n"
305+
"\n"
306+
"strictparsing: false\n"
307+
"\n"
308+
"colorspaces :\n"
309+
" - !<ColorSpace>\n"
310+
" name : lnh\n"
311+
" bitdepth : 16f\n"
312+
" isdata : false\n"
313+
" allocation : lg2\n"
314+
"\n"
315+
" - !<ColorSpace>\n"
316+
" name : test\n"
317+
" bitdepth : 8ui\n"
318+
" isdata : false\n"
319+
" allocation : uniform\n"
320+
" to_reference : !<ExponentTransform> {value: [2.2, 2.2, 2.2, 1]}\n";
321+
322+
static const std::string expectedLut =
323+
"CSPLUTV100\n"
324+
"3D\n"
325+
"\n"
326+
"BEGIN METADATA\n"
327+
"this is some metadata!\n"
328+
"END METADATA\n"
329+
"\n"
330+
#ifdef USE_SSE
331+
"4\n"
332+
"0.000977 0.039373 1.587398 64.000168\n"
333+
"0.000000 0.333333 0.666667 1.000000\n"
334+
"4\n"
335+
"0.000977 0.039373 1.587398 64.000168\n"
336+
"0.000000 0.333333 0.666667 1.000000\n"
337+
"4\n"
338+
"0.000977 0.039373 1.587398 64.000168\n"
339+
"0.000000 0.333333 0.666667 1.000000\n"
340+
"\n"
341+
"2 2 2\n"
342+
"0.042823 0.042823 0.042823\n"
343+
"6.622035 0.042823 0.042823\n"
344+
"0.042823 6.622035 0.042823\n"
345+
"6.622035 6.622035 0.042823\n"
346+
"0.042823 0.042823 6.622035\n"
347+
"6.622035 0.042823 6.622035\n"
348+
"0.042823 6.622035 6.622035\n"
349+
"6.622035 6.622035 6.622035\n"
350+
#else
351+
"4\n"
352+
"0.000977 0.039373 1.587401 64.000000\n"
353+
"0.000000 0.333333 0.666667 1.000000\n"
354+
"4\n"
355+
"0.000977 0.039373 1.587401 64.000000\n"
356+
"0.000000 0.333333 0.666667 1.000000\n"
357+
"4\n"
358+
"0.000977 0.039373 1.587401 64.000000\n"
359+
"0.000000 0.333333 0.666667 1.000000\n"
360+
"\n"
361+
"2 2 2\n"
362+
"0.042823 0.042823 0.042823\n"
363+
"6.622026 0.042823 0.042823\n"
364+
"0.042823 6.622026 0.042823\n"
365+
"6.622026 6.622026 0.042823\n"
366+
"0.042823 0.042823 6.622026\n"
367+
"6.622026 0.042823 6.622026\n"
368+
"0.042823 6.622026 6.622026\n"
369+
"6.622026 6.622026 6.622026\n"
370+
#endif // USE_SSE
371+
"\n";
372+
std::istringstream is(myProfile);
373+
OCIO::ConstConfigRcPtr config;
374+
OIIO_CHECK_NO_THROW(config = OCIO::Config::CreateFromStream(is));
375+
OIIO_REQUIRE_EQUAL(config->getNumColorSpaces(), 2);
376+
bake->setConfig(config);
377+
auto cfg2 = bake->getConfig();
378+
OIIO_REQUIRE_EQUAL(cfg2->getNumColorSpaces(), 2);
379+
380+
bake->setFormat("cinespace");
381+
OIIO_CHECK_EQUAL("cinespace", std::string(bake->getFormat()));
382+
bake->setType("3D");
383+
OIIO_CHECK_EQUAL("3D", std::string(bake->getType()));
384+
bake->setMetadata("this is some metadata!");
385+
OIIO_CHECK_EQUAL("this is some metadata!", std::string(bake->getMetadata()));
386+
bake->setInputSpace("lnh");
387+
OIIO_CHECK_EQUAL("lnh", std::string(bake->getInputSpace()));
388+
bake->setLooks("foo, +bar");
389+
OIIO_CHECK_EQUAL("foo, +bar", std::string(bake->getLooks()));
390+
bake->setLooks("");
391+
bake->setTargetSpace("test");
392+
OIIO_CHECK_EQUAL("test", std::string(bake->getTargetSpace()));
393+
bake->setShaperSize(4);
394+
OIIO_CHECK_EQUAL(4, bake->getShaperSize());
395+
bake->setCubeSize(2);
396+
OIIO_CHECK_EQUAL(2, bake->getCubeSize());
397+
std::ostringstream os;
398+
bake->bake(os);
399+
OIIO_CHECK_EQUAL(expectedLut, os.str());
400+
OIIO_CHECK_EQUAL(8, bake->getNumFormats());
401+
OIIO_CHECK_EQUAL("cinespace", std::string(bake->getFormatNameByIndex(2)));
402+
OIIO_CHECK_EQUAL("3dl", std::string(bake->getFormatExtensionByIndex(1)));
403+
}
404+
298405
#endif // OCIO_BUILD_TESTS
299406

300407

src/OpenColorIO/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ set(SOURCES
5858
ops/Gamma/GammaOpUtils.cpp
5959
ops/Gamma/GammaOps.cpp
6060
ops/IndexMapping.cpp
61+
ops/Log/LogOpCPU.cpp
62+
ops/Log/LogOpData.cpp
63+
ops/Log/LogOpGPU.cpp
6164
ops/Log/LogOps.cpp
65+
ops/Log/LogUtils.cpp
6266
ops/Lut1D/Lut1DOp.cpp
6367
ops/Lut1D/Lut1DOpCPU.cpp
6468
ops/Lut1D/Lut1DOpData.cpp
@@ -92,6 +96,7 @@ set(SOURCES
9296
transforms/ExponentWithLinearTransform.cpp
9397
transforms/FileTransform.cpp
9498
transforms/GroupTransform.cpp
99+
transforms/LogAffineTransform.cpp
95100
transforms/LogTransform.cpp
96101
transforms/LookTransform.cpp
97102
transforms/MatrixTransform.cpp

0 commit comments

Comments
 (0)