Skip to content

Commit

Permalink
Adsk Contrib - Rework LogOpData to get ready for Log CTF parsing. (#674)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
BernardLefebvre authored and hodoulp committed Mar 11, 2019
1 parent 03ac35d commit 67cb724
Show file tree
Hide file tree
Showing 31 changed files with 3,989 additions and 653 deletions.
86 changes: 76 additions & 10 deletions include/OpenColorIO/OpenColorTransforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,77 @@ OCIO_NAMESPACE_ENTER
//!cpp:function::
extern OCIOEXPORT std::ostream& operator<< (std::ostream&, const GroupTransform&);



//!rst:: //////////////////////////////////////////////////////////////////

//!cpp:class:: Applies a logarithm with an affine transform before and after.
// Represents the Cineon lin-to-log type transforms.
//
// logSideSlope * log( linSideSlope * color + linSideOffset, base) + logSideOffset
//
// * Default values are: 1. * log( 1. * color + 0., 2.) + 0.
// * Only the rgb channels are affected.
class OCIOEXPORT LogAffineTransform : public Transform
{
public:
//!cpp:function::
static LogAffineTransformRcPtr Create();

//!cpp:function::
virtual TransformRcPtr createEditableCopy() const;

//!cpp:function::
virtual TransformDirection getDirection() const;
//!cpp:function::
virtual void setDirection(TransformDirection dir);

//!cpp:function:: Will throw if data is not valid.
virtual void validate() const;

//!cpp:function::
void setBase(double base);
//!cpp:function::
double getBase() const;

//!rst:: Set/Get values for each R, G, and B components.

//!cpp:function::
void setLogSideSlopeValue(const double(&values)[3]);
//!cpp:function::
void setLogSideOffsetValue(const double(&values)[3]);
//!cpp:function::
void setLinSideSlopeValue(const double(&values)[3]);
//!cpp:function::
void setLinSideOffsetValue(const double(&values)[3]);
//!cpp:function::
void getLogSideSlopeValue(double(&values)[3]) const;
//!cpp:function::
void getLogSideOffsetValue(double(&values)[3]) const;
//!cpp:function::
void getLinSideSlopeValue(double(&values)[3]) const;
//!cpp:function::
void getLinSideOffsetValue(double(&values)[3]) const;

private:
LogAffineTransform();
LogAffineTransform(const LogTransform &);
virtual ~LogAffineTransform();

LogAffineTransform& operator= (const LogAffineTransform &);

static void deleter(LogAffineTransform* t);

class Impl;
friend class Impl;
Impl * m_impl;
Impl * getImpl() { return m_impl; }
const Impl * getImpl() const { return m_impl; }
};

//!cpp:function::
extern OCIOEXPORT std::ostream& operator<< (std::ostream&, const LogAffineTransform&);


//!rst:: //////////////////////////////////////////////////////////////////

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

//!cpp:function::
void setBase(float val);
void setBase(double val);
//!cpp:function::
float getBase() const;
double getBase() const;

private:
LogTransform();
LogTransform(const LogTransform &);
Expand All @@ -664,10 +734,8 @@ OCIO_NAMESPACE_ENTER

//!cpp:function::
extern OCIOEXPORT std::ostream& operator<< (std::ostream&, const LogTransform&);






//!rst:: //////////////////////////////////////////////////////////////////

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




//!rst:: //////////////////////////////////////////////////////////////////

//!cpp:class:: Represents an MX+B Matrix transform
Expand Down
8 changes: 7 additions & 1 deletion include/OpenColorIO/OpenColorTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ OCIO_NAMESPACE_ENTER
typedef OCIO_SHARED_PTR<const LogTransform> ConstLogTransformRcPtr;
//!cpp:type::
typedef OCIO_SHARED_PTR<LogTransform> LogTransformRcPtr;


class OCIOEXPORT LogAffineTransform;
//!cpp:type::
typedef OCIO_SHARED_PTR<const LogAffineTransform> ConstLogAffineTransformRcPtr;
//!cpp:type::
typedef OCIO_SHARED_PTR<LogAffineTransform> LogAffineTransformRcPtr;

class OCIOEXPORT LookTransform;
//!cpp:type::
typedef OCIO_SHARED_PTR<const LookTransform> ConstLookTransformRcPtr;
Expand Down
107 changes: 107 additions & 0 deletions src/OpenColorIO/Baker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,113 @@ OIIO_ADD_TEST(Baker_Unit_Tests, test_listlutwriters)
}
*/

OIIO_ADD_TEST(Baker_Unit_Tests, bake)
{
// SSE aware test, similar to python test.
OCIO::BakerRcPtr bake = OCIO::Baker::Create();

static const std::string myProfile =
"ocio_profile_version: 1\n"
"\n"
"strictparsing: false\n"
"\n"
"colorspaces :\n"
" - !<ColorSpace>\n"
" name : lnh\n"
" bitdepth : 16f\n"
" isdata : false\n"
" allocation : lg2\n"
"\n"
" - !<ColorSpace>\n"
" name : test\n"
" bitdepth : 8ui\n"
" isdata : false\n"
" allocation : uniform\n"
" to_reference : !<ExponentTransform> {value: [2.2, 2.2, 2.2, 1]}\n";

static const std::string expectedLut =
"CSPLUTV100\n"
"3D\n"
"\n"
"BEGIN METADATA\n"
"this is some metadata!\n"
"END METADATA\n"
"\n"
#ifdef USE_SSE
"4\n"
"0.000977 0.039373 1.587398 64.000168\n"
"0.000000 0.333333 0.666667 1.000000\n"
"4\n"
"0.000977 0.039373 1.587398 64.000168\n"
"0.000000 0.333333 0.666667 1.000000\n"
"4\n"
"0.000977 0.039373 1.587398 64.000168\n"
"0.000000 0.333333 0.666667 1.000000\n"
"\n"
"2 2 2\n"
"0.042823 0.042823 0.042823\n"
"6.622035 0.042823 0.042823\n"
"0.042823 6.622035 0.042823\n"
"6.622035 6.622035 0.042823\n"
"0.042823 0.042823 6.622035\n"
"6.622035 0.042823 6.622035\n"
"0.042823 6.622035 6.622035\n"
"6.622035 6.622035 6.622035\n"
#else
"4\n"
"0.000977 0.039373 1.587401 64.000000\n"
"0.000000 0.333333 0.666667 1.000000\n"
"4\n"
"0.000977 0.039373 1.587401 64.000000\n"
"0.000000 0.333333 0.666667 1.000000\n"
"4\n"
"0.000977 0.039373 1.587401 64.000000\n"
"0.000000 0.333333 0.666667 1.000000\n"
"\n"
"2 2 2\n"
"0.042823 0.042823 0.042823\n"
"6.622026 0.042823 0.042823\n"
"0.042823 6.622026 0.042823\n"
"6.622026 6.622026 0.042823\n"
"0.042823 0.042823 6.622026\n"
"6.622026 0.042823 6.622026\n"
"0.042823 6.622026 6.622026\n"
"6.622026 6.622026 6.622026\n"
#endif // USE_SSE
"\n";
std::istringstream is(myProfile);
OCIO::ConstConfigRcPtr config;
OIIO_CHECK_NO_THROW(config = OCIO::Config::CreateFromStream(is));
OIIO_REQUIRE_EQUAL(config->getNumColorSpaces(), 2);
bake->setConfig(config);
auto cfg2 = bake->getConfig();
OIIO_REQUIRE_EQUAL(cfg2->getNumColorSpaces(), 2);

bake->setFormat("cinespace");
OIIO_CHECK_EQUAL("cinespace", std::string(bake->getFormat()));
bake->setType("3D");
OIIO_CHECK_EQUAL("3D", std::string(bake->getType()));
bake->setMetadata("this is some metadata!");
OIIO_CHECK_EQUAL("this is some metadata!", std::string(bake->getMetadata()));
bake->setInputSpace("lnh");
OIIO_CHECK_EQUAL("lnh", std::string(bake->getInputSpace()));
bake->setLooks("foo, +bar");
OIIO_CHECK_EQUAL("foo, +bar", std::string(bake->getLooks()));
bake->setLooks("");
bake->setTargetSpace("test");
OIIO_CHECK_EQUAL("test", std::string(bake->getTargetSpace()));
bake->setShaperSize(4);
OIIO_CHECK_EQUAL(4, bake->getShaperSize());
bake->setCubeSize(2);
OIIO_CHECK_EQUAL(2, bake->getCubeSize());
std::ostringstream os;
bake->bake(os);
OIIO_CHECK_EQUAL(expectedLut, os.str());
OIIO_CHECK_EQUAL(8, bake->getNumFormats());
OIIO_CHECK_EQUAL("cinespace", std::string(bake->getFormatNameByIndex(2)));
OIIO_CHECK_EQUAL("3dl", std::string(bake->getFormatExtensionByIndex(1)));
}

#endif // OCIO_BUILD_TESTS


5 changes: 5 additions & 0 deletions src/OpenColorIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ set(SOURCES
ops/Gamma/GammaOpUtils.cpp
ops/Gamma/GammaOps.cpp
ops/IndexMapping.cpp
ops/Log/LogOpCPU.cpp
ops/Log/LogOpData.cpp
ops/Log/LogOpGPU.cpp
ops/Log/LogOps.cpp
ops/Log/LogUtils.cpp
ops/Lut1D/Lut1DOp.cpp
ops/Lut1D/Lut1DOpCPU.cpp
ops/Lut1D/Lut1DOpData.cpp
Expand Down Expand Up @@ -92,6 +96,7 @@ set(SOURCES
transforms/ExponentWithLinearTransform.cpp
transforms/FileTransform.cpp
transforms/GroupTransform.cpp
transforms/LogAffineTransform.cpp
transforms/LogTransform.cpp
transforms/LookTransform.cpp
transforms/MatrixTransform.cpp
Expand Down
Loading

0 comments on commit 67cb724

Please sign in to comment.