From 539621925333a79379685f35d2fb85d8850a5dc6 Mon Sep 17 00:00:00 2001 From: Mei Chu Date: Fri, 29 Mar 2024 18:22:05 -0700 Subject: [PATCH 1/9] Add FileTransform::IsFormatExtensionSupported() Signed-off-by: Mei Chu --- include/OpenColorIO/OpenColorTransforms.h | 41 +++++++------- src/OpenColorIO/transforms/FileTransform.cpp | 56 +++++++++++++------- src/OpenColorIO/transforms/FileTransform.h | 1 + 3 files changed, 59 insertions(+), 39 deletions(-) diff --git a/include/OpenColorIO/OpenColorTransforms.h b/include/OpenColorIO/OpenColorTransforms.h index 19bf1496a4..cc301744cd 100644 --- a/include/OpenColorIO/OpenColorTransforms.h +++ b/include/OpenColorIO/OpenColorTransforms.h @@ -17,7 +17,7 @@ /** * C++ Transforms * ============== - * + * * Typically only needed when creating and/or manipulating configurations */ @@ -228,7 +228,7 @@ extern OCIOEXPORT std::ostream & operator<<(std::ostream &, const BuiltinTransfo /** - * \brief + * \brief * An implementation of the ASC Color Decision List (CDL), based on the ASC v1.2 * specification. * @@ -236,7 +236,7 @@ extern OCIOEXPORT std::ostream & operator<<(std::ostream &, const BuiltinTransfo * * Slope, offset, power:: * out = clamp( (in * slope) + offset ) ^ power - * + * * \note​ * If the config version is 1, negative values are clamped if the power is not 1.0. * For config version 2 and higher, the negative handling is controlled by the CDL style. @@ -256,7 +256,7 @@ class OCIOEXPORT CDLTransform : public Transform * if file does not contain any CDL or if the specified cccid is not found. */ static CDLTransformRcPtr CreateFromFile(const char * src, const char * cccid); - + /** * \brief Load all of the CDLs in a .cdl or .ccc file into a single GroupTransform. * @@ -842,7 +842,7 @@ class OCIOEXPORT ExponentTransform : public Transform */ virtual NegativeStyle getNegativeStyle() const = 0; virtual void setNegativeStyle(NegativeStyle style) = 0; - + ExponentTransform(const ExponentTransform &) = delete; ExponentTransform & operator= (const ExponentTransform &) = delete; /// Do not use (needed only for pybind11). @@ -883,7 +883,7 @@ class OCIOEXPORT ExponentWithLinearTransform : public Transform /** * Set the exponent value for the power function for R, G, B, A. * - * \note + * \note * The gamma values must be in the range of [1, 10]. Set the transform direction * to inverse to obtain the effect of values less than 1. */ @@ -893,7 +893,7 @@ class OCIOEXPORT ExponentWithLinearTransform : public Transform /** * Set the offset value for the power function for R, G, B, A. * - * \note + * \note * The offset values must be in the range [0, 0.9]. */ virtual void setOffset(const double(&values)[4]) noexcept = 0; @@ -907,7 +907,7 @@ class OCIOEXPORT ExponentWithLinearTransform : public Transform */ virtual NegativeStyle getNegativeStyle() const = 0; virtual void setNegativeStyle(NegativeStyle style) = 0; - + ExponentWithLinearTransform(const ExponentWithLinearTransform &) = delete; ExponentWithLinearTransform & operator= (const ExponentWithLinearTransform &) = delete; /// Do not use (needed only for pybind11). @@ -1070,6 +1070,9 @@ class OCIOEXPORT FileTransform : public Transform static const char * GetFormatNameByIndex(int index); /// Get the LUT reader extension at index, return empty string if an invalid index is specified. static const char * GetFormatExtensionByIndex(int index); + /// Returns true if the extension corresponds to a format supported by FileTransform. + /// The argument is case-insensitive, and a leading dot, if present, is ignored. + static bool IsFormatExtensionSupported(const char * extension); FileTransform & operator=(const FileTransform &) = delete; /// Do not use (needed only for pybind11). @@ -1227,8 +1230,8 @@ class OCIOEXPORT GradingRGBCurveTransform : public Transform virtual void setValue(const ConstGradingRGBCurveRcPtr & values) = 0; /** - * It is possible to provide a desired slope value for each control point. The number of slopes is - * always the same as the number of control points and so the control points must be set before + * It is possible to provide a desired slope value for each control point. The number of slopes is + * always the same as the number of control points and so the control points must be set before * setting the slopes. The slopes are primarily intended for use by config authors looking to match * a specific shape with as few control points as possible, they are not intended to be exposed to * a user interface for direct manipulation. When a curve is being generated for creative purposes @@ -1285,7 +1288,7 @@ extern OCIOEXPORT std::ostream & operator<<(std::ostream &, const GradingRGBCurv * Each control allows R, G, B adjustments and a Master adjustment. * * There is also an S-contrast control for imparting an S-shape curve. - * + * * The controls are dynamic, so they may be adjusted even after the Transform has been included * in a Processor. */ @@ -1448,7 +1451,7 @@ extern OCIOEXPORT std::ostream & operator<<(std::ostream &, const LogAffineTrans * is used for many camera logs (e.g., LogC) as well as ACEScct. * * * The linSideBreak specifies the point on the linear axis where the log and linear - * segments meet. It must be set (there is no default). + * segments meet. It must be set (there is no default). * * The linearSlope specifies the slope of the linear segment of the forward (linToLog) * transform. By default it is set equal to the slope of the log curve at the break point. */ @@ -1485,14 +1488,14 @@ class OCIOEXPORT LogCameraTransform : public Transform virtual bool getLinearSlopeValue(double(&values)[3]) const = 0; /** * \brief Set LinearSlope value. - * + * * \note * You must call setLinSideBreakValue before calling this. */ virtual void setLinearSlopeValue(const double(&values)[3]) = 0; /// Remove LinearSlope values so that default values are used. virtual void unsetLinearSlopeValue() = 0; - + LogCameraTransform(const LogCameraTransform &) = delete; LogCameraTransform & operator= (const LogCameraTransform &) = delete; /// Do not use (needed only for pybind11). @@ -1677,7 +1680,7 @@ class OCIOEXPORT Lut1DTransform : public Transform * For example, the value 1.0 would be written as the integer 15360 * because it has the same bit-pattern. Note that this implies the * values will be quantized to a 16-bit float. Note that this setting - * only controls the output formatting (where supported) and not the + * only controls the output formatting (where supported) and not the * values for getValue/setValue. The only file formats that currently * support this are CLF and CTF. */ @@ -1782,7 +1785,7 @@ extern OCIOEXPORT std::ostream& operator<< (std::ostream&, const Lut3DTransform& /** * Represents an MX+B Matrix transform. * - * \note + * \note * For singular matrices, an inverse direction will throw an exception during finalization. */ class OCIOEXPORT MatrixTransform : public Transform @@ -1827,7 +1830,7 @@ class OCIOEXPORT MatrixTransform : public Transform * outside [0,1]. */ virtual void setOffset(const double * offset4) = 0; - + /** * Get the bit-depths associated with the matrix values read from a * file or set the bit-depths of values to be written to a file @@ -1848,7 +1851,7 @@ class OCIOEXPORT MatrixTransform : public Transform /// **Convenience functions** /// /// Build the matrix and offset corresponding to higher-level concepts. - /// + /// /// \note /// These can throw an exception if for any component /// ``oldmin == oldmax. (divide by 0)`` @@ -1886,7 +1889,7 @@ extern OCIOEXPORT std::ostream & operator<<(std::ostream &, const MatrixTransfor * The Range is used to apply an affine transform (scale & offset) and * clamps values to min/max bounds on all color components except the alpha. * The scale and offset values are computed from the input and output bounds. - * + * * Refer to section 7.2.4 in specification S-2014-006 "A Common File Format * for Look-Up Tables" from the Academy of Motion Picture Arts and Sciences * and the American Society of Cinematographers. diff --git a/src/OpenColorIO/transforms/FileTransform.cpp b/src/OpenColorIO/transforms/FileTransform.cpp index 9aeae8df43..a8c2dcb6dc 100755 --- a/src/OpenColorIO/transforms/FileTransform.cpp +++ b/src/OpenColorIO/transforms/FileTransform.cpp @@ -158,6 +158,11 @@ const char * FileTransform::GetFormatExtensionByIndex(int index) return FormatRegistry::GetInstance().getFormatExtensionByIndex(FORMAT_CAPABILITY_READ, index); } +bool FileTransform::IsFormatExtensionSupported(const char * extension) +{ + return FormatRegistry::GetInstance().isFormatExtensionSupported(extension); +} + std::ostream& operator<< (std::ostream& os, const FileTransform& t) { os << " getLutData( - const Config & config, - const std::string & filepath, + const Config & config, + const std::string & filepath, std::ios_base::openmode mode) { if (config.getConfigIOProxy()) @@ -218,7 +223,7 @@ void closeLutStream(const Config & config, const std::istream & istream) } } -bool CollectContextVariables(const Config &, +bool CollectContextVariables(const Config &, const Context & context, const FileTransform & tr, ContextRcPtr & usedContextVars) @@ -230,7 +235,7 @@ bool CollectContextVariables(const Config &, bool foundContextVars = false; // Used to collect the context variables needed to resolve the src string itself (not involving - // the search_path yet). + // the search_path yet). ContextRcPtr ctxFilename = Context::Create(); ctxFilename->setSearchPath(context.getSearchPath()); ctxFilename->setWorkingDir(context.getWorkingDir()); @@ -247,7 +252,7 @@ bool CollectContextVariables(const Config &, // resolveFileLocation returns all usedContextVars in the search_path, regardless of whether // they are needed for the given file. The work-around is to compare the resolved location // with and without using the environment -- if they are the same, it means the environment - // was not used. So we create an empty context for this purpose. + // was not used. So we create an empty context for this purpose. ContextRcPtr emptyContext = Context::Create(); emptyContext->setSearchPath(context.getSearchPath()); @@ -494,7 +499,7 @@ const char * FormatRegistry::getFormatExtensionByIndex(int capability, int index { if(capability == FORMAT_CAPABILITY_READ) { - if(index<0 + if(index<0 || index>=static_cast(m_readFormatExtensions.size())) { return ""; @@ -512,7 +517,7 @@ const char * FormatRegistry::getFormatExtensionByIndex(int capability, int index } else if(capability == FORMAT_CAPABILITY_WRITE) { - if(index<0 + if(index<0 || index>=static_cast(m_writeFormatExtensions.size())) { return ""; @@ -522,6 +527,17 @@ const char * FormatRegistry::getFormatExtensionByIndex(int capability, int index return ""; } +bool FormatRegistry::isFormatExtensionSupported(const char * extension) const +{ + std::cerr << extension << std::endl; + FileFormatVectorMap::const_iterator iter = m_formatsByExtension.find(StringUtils::Lower(extension)); + if (iter != m_formatsByExtension.end()) + { + return true; + } + return false; +} + /////////////////////////////////////////////////////////////////////////// FileFormat::~FileFormat() @@ -601,11 +617,11 @@ void LoadFileUncached(FileFormat * & returnFormat, { pStream = getLutData( config, - filepath, - tryFormat->isBinary() ? std::ios_base::binary : std::ios_base::in + filepath, + tryFormat->isBinary() ? std::ios_base::binary : std::ios_base::in ); auto & filestream = *pStream; - + if (!filestream.good()) { std::ostringstream os; @@ -637,7 +653,7 @@ void LoadFileUncached(FileFormat * & returnFormat, { if (pStream) { - closeLutStream(config, *pStream); + closeLutStream(config, *pStream); } primaryErrorText += " '"; @@ -678,11 +694,11 @@ void LoadFileUncached(FileFormat * & returnFormat, { pStream = getLutData( config, - filepath, - altFormat->isBinary() ? std::ios_base::binary : std::ios_base::in + filepath, + altFormat->isBinary() ? std::ios_base::binary : std::ios_base::in ); auto& filestream = *pStream; - + if (!filestream.good()) { std::ostringstream os; @@ -715,9 +731,9 @@ void LoadFileUncached(FileFormat * & returnFormat, { if (pStream) { - closeLutStream(config, *pStream); + closeLutStream(config, *pStream); } - + if(IsDebugLoggingEnabled()) { std::ostringstream os; @@ -799,7 +815,7 @@ void GetCachedFileAndFormat(FileFormat * & format, FileCacheResultPtr result; { AutoMutex guard(g_fileCache.lock()); - + if (g_fileCache.isEnabled()) { // As the entry is a shared pointer instance, having an empty one @@ -920,9 +936,9 @@ void BuildFileTransformOps(OpRcPtrVec & ops, FileFormat* format = NULL; CachedFileRcPtr cachedFile; - GetCachedFileAndFormat(format, - cachedFile, - filepath, + GetCachedFileAndFormat(format, + cachedFile, + filepath, fileTransform.getInterpolation(), config); diff --git a/src/OpenColorIO/transforms/FileTransform.h b/src/OpenColorIO/transforms/FileTransform.h index db737b8bd8..19b2b8c73f 100644 --- a/src/OpenColorIO/transforms/FileTransform.h +++ b/src/OpenColorIO/transforms/FileTransform.h @@ -137,6 +137,7 @@ class FormatRegistry int getNumFormats(int capability) const noexcept; const char * getFormatNameByIndex(int capability, int index) const noexcept; const char * getFormatExtensionByIndex(int capability, int index) const noexcept; + bool isFormatExtensionSupported(const char * extension) const; private: FormatRegistry(); ~FormatRegistry(); From 95521a2b9c7148ade31795eef215c7cb13e26dec Mon Sep 17 00:00:00 2001 From: Mei Chu Date: Fri, 29 Mar 2024 18:51:33 -0700 Subject: [PATCH 2/9] IsFormatExtensionSupported ignores dot at start. Signed-off-by: Mei Chu --- src/OpenColorIO/transforms/FileTransform.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/OpenColorIO/transforms/FileTransform.cpp b/src/OpenColorIO/transforms/FileTransform.cpp index a8c2dcb6dc..75423d3627 100755 --- a/src/OpenColorIO/transforms/FileTransform.cpp +++ b/src/OpenColorIO/transforms/FileTransform.cpp @@ -529,8 +529,16 @@ const char * FormatRegistry::getFormatExtensionByIndex(int capability, int index bool FormatRegistry::isFormatExtensionSupported(const char * extension) const { - std::cerr << extension << std::endl; - FileFormatVectorMap::const_iterator iter = m_formatsByExtension.find(StringUtils::Lower(extension)); + FileFormatVectorMap::const_iterator iter; + // If dot is present at the start, pointer arithmetic increment up by one to ignore that dot. + if (extension[0] == '.') + { + iter = m_formatsByExtension.find(extension+1); + } + else + { + iter = m_formatsByExtension.find(extension); + } if (iter != m_formatsByExtension.end()) { return true; From d8333f66cb12a1e351c3d861da9035c4914b0148 Mon Sep 17 00:00:00 2001 From: Mei Chu Date: Fri, 29 Mar 2024 19:41:45 -0700 Subject: [PATCH 3/9] Add C++ tests for new function. Signed-off-by: Mei Chu --- tests/cpu/transforms/FileTransform_tests.cpp | 25 ++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/cpu/transforms/FileTransform_tests.cpp b/tests/cpu/transforms/FileTransform_tests.cpp index 0301ac02dc..bdcd4c2761 100644 --- a/tests/cpu/transforms/FileTransform_tests.cpp +++ b/tests/cpu/transforms/FileTransform_tests.cpp @@ -149,7 +149,7 @@ OCIO_ADD_TEST(FileTransform, load_file_fail) // Supported file extension with a wrong content. // It's in fact a binary png file i.e. all readers must fail. const std::string faultyCLFFile("clf/illegal/image_png.clf"); - OCIO_CHECK_THROW_WHAT(OCIO::GetFileTransformProcessor(faultyCLFFile), + OCIO_CHECK_THROW_WHAT(OCIO::GetFileTransformProcessor(faultyCLFFile), OCIO::Exception, "image_png.clf' could not be loaded"); // Missing file. @@ -290,6 +290,17 @@ OCIO_ADD_TEST(FileTransform, format_by_index) ValidateFormatByIndex(formatRegistry, OCIO::FORMAT_CAPABILITY_READ); } +OCIO_ADD_TEST(FileTransform, is_format_extension_supported) +{ + OCIO::FormatRegistry & formatRegistry = OCIO::FormatRegistry::GetInstance(); + OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("foo", false)); + OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("bar", false)); + OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("cdl", true)); + OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported(".cdl", true)); + OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("3dl", true)); + OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported(".3dl", true)); +} + OCIO_ADD_TEST(FileTransform, validate) { OCIO::FileTransformRcPtr tr = OCIO::FileTransform::Create(); @@ -318,7 +329,7 @@ OCIO_ADD_TEST(FileTransform, interpolation_validity) OCIO_CHECK_NO_THROW(cfg->getProcessor(tr)); // UNKNOWN can't be used by a LUT file, so the interp on the LUT is set to DEFAULT and a - // warning is logged. + // warning is logged. tr->setInterpolation(OCIO::INTERP_UNKNOWN); OCIO_CHECK_NO_THROW(tr->validate()); @@ -355,7 +366,7 @@ OCIO_ADD_TEST(FileTransform, context_variables) { // Test context variables with a FileTransform i.e. the file name or the search_path could // contain one or several context variables. - + OCIO::ContextRcPtr usedContextVars = OCIO::Context::Create(); OCIO::ConfigRcPtr cfg = OCIO::Config::CreateRaw()->createEditableCopy(); @@ -429,13 +440,13 @@ OCIO_ADD_TEST(FileTransform, context_variables) OCIO_CHECK_EQUAL(std::string("ENV1"), usedContextVars->getStringVarNameByIndex(1)); OCIO_CHECK_EQUAL(std::string("exposure_contrast_linear.ctf"), usedContextVars->getStringVarByIndex(1)); - // A basic check to validate that context variables are correctly used. + // A basic check to validate that context variables are correctly used. OCIO_CHECK_NO_THROW(cfg->getProcessor(ctx, file, OCIO::TRANSFORM_DIR_FORWARD)); { // Case 4 - The 'cccid' now contains a context variable - static const std::string CONFIG = + static const std::string CONFIG = "ocio_profile_version: 2\n" "\n" "environment:\n" @@ -475,7 +486,7 @@ OCIO_ADD_TEST(FileTransform, context_variables) ); OCIO::ConstFileTransformRcPtr fTr1 = OCIO::DynamicPtrCast(tr1); OCIO_CHECK_ASSERT(fTr1); - + OCIO_CHECK_ASSERT(CollectContextVariables(*cfg, *ctx, *fTr1, usedContextVars)); OCIO_CHECK_EQUAL(2, usedContextVars->getNumStringVars()); OCIO_CHECK_EQUAL(std::string("CCPREFIX"), usedContextVars->getStringVarNameByIndex(0)); @@ -487,7 +498,7 @@ OCIO_ADD_TEST(FileTransform, context_variables) OCIO_ADD_TEST(FileTransform, cc_file_with_different_file_extension) { - static const std::string BASE_CONFIG = + static const std::string BASE_CONFIG = "ocio_profile_version: 1\n" "description: Minimal\n" "search_path: " + OCIO::GetTestFilesDir() + "\n" From 2e43676cbcb0f84adb1a039b83fd32d1c1bc788d Mon Sep 17 00:00:00 2001 From: Mei Chu Date: Fri, 29 Mar 2024 19:51:02 -0700 Subject: [PATCH 4/9] Fix a small bug in the new C++ tests. Signed-off-by: Mei Chu --- tests/cpu/transforms/FileTransform_tests.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/cpu/transforms/FileTransform_tests.cpp b/tests/cpu/transforms/FileTransform_tests.cpp index bdcd4c2761..f4eabf55da 100644 --- a/tests/cpu/transforms/FileTransform_tests.cpp +++ b/tests/cpu/transforms/FileTransform_tests.cpp @@ -293,12 +293,12 @@ OCIO_ADD_TEST(FileTransform, format_by_index) OCIO_ADD_TEST(FileTransform, is_format_extension_supported) { OCIO::FormatRegistry & formatRegistry = OCIO::FormatRegistry::GetInstance(); - OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("foo", false)); - OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("bar", false)); - OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("cdl", true)); - OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported(".cdl", true)); - OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("3dl", true)); - OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported(".3dl", true)); + OCIO_CHECK_EQUAL(formatRegistry.isFormatExtensionSupported("foo"), false); + OCIO_CHECK_EQUAL(formatRegistry.isFormatExtensionSupported("bar"), false); + OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("cdl")); + OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported(".cdl")); + OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("3dl")); + OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported(".3dl")); } OCIO_ADD_TEST(FileTransform, validate) From a97a3cf4478b5ee395956750932ac6ef11530cfd Mon Sep 17 00:00:00 2001 From: Mei Chu Date: Sat, 30 Mar 2024 13:09:13 -0700 Subject: [PATCH 5/9] Add python binding, python tests and address feedbacks. Signed-off-by: Mei Chu --- include/OpenColorIO/OpenColorTransforms.h | 4 ++ .../python/transforms/PyFileTransform.cpp | 64 ++++++++++--------- tests/cpu/transforms/FileTransform_tests.cpp | 2 + tests/python/FileTransformTest.py | 13 ++++ 4 files changed, 52 insertions(+), 31 deletions(-) diff --git a/include/OpenColorIO/OpenColorTransforms.h b/include/OpenColorIO/OpenColorTransforms.h index cc301744cd..57b872e084 100644 --- a/include/OpenColorIO/OpenColorTransforms.h +++ b/include/OpenColorIO/OpenColorTransforms.h @@ -1072,6 +1072,10 @@ class OCIOEXPORT FileTransform : public Transform static const char * GetFormatExtensionByIndex(int index); /// Returns true if the extension corresponds to a format supported by FileTransform. /// The argument is case-insensitive, and a leading dot, if present, is ignored. + /// Note that FileTransform will attempt all format readers on a given file until it is + /// successful, even files that contain an unsupported extension or no extension. + /// However, this function is useful for applications that want to know which files are likely + /// to be LUT files, based on their extension. static bool IsFormatExtensionSupported(const char * extension); FileTransform & operator=(const FileTransform &) = delete; diff --git a/src/bindings/python/transforms/PyFileTransform.cpp b/src/bindings/python/transforms/PyFileTransform.cpp index 614ed86bb9..528ba22ef5 100644 --- a/src/bindings/python/transforms/PyFileTransform.cpp +++ b/src/bindings/python/transforms/PyFileTransform.cpp @@ -22,21 +22,21 @@ void bindPyFileTransform(py::module & m) { FileTransformRcPtr DEFAULT = FileTransform::Create(); - auto clsFileTransform = + auto clsFileTransform = py::class_( m.attr("FileTransform")); - auto clsFormatIterator = + auto clsFormatIterator = py::class_( clsFileTransform, "FormatIterator"); clsFileTransform - .def(py::init(&FileTransform::Create), + .def(py::init(&FileTransform::Create), DOC(FileTransform, Create)) - .def(py::init([](const std::string & src, - const std::string & id, + .def(py::init([](const std::string & src, + const std::string & id, Interpolation interp, - TransformDirection dir) + TransformDirection dir) { FileTransformRcPtr p = FileTransform::Create(); if (!src.empty()) { p->setSrc(src.c_str()); } @@ -45,56 +45,58 @@ void bindPyFileTransform(py::module & m) p->setDirection(dir); p->validate(); return p; - }), - "src"_a = DEFAULT->getSrc(), + }), + "src"_a = DEFAULT->getSrc(), "cccId"_a = DEFAULT->getCCCId(), "interpolation"_a = DEFAULT->getInterpolation(), - "direction"_a = DEFAULT->getDirection(), + "direction"_a = DEFAULT->getDirection(), DOC(FileTransform, Create)) - .def_static("getFormats", []() - { - return FormatIterator(nullptr); + .def_static("getFormats", []() + { + return FormatIterator(nullptr); }) - .def("getSrc", &FileTransform::getSrc, + .def("getSrc", &FileTransform::getSrc, DOC(FileTransform, getSrc)) - .def("setSrc", &FileTransform::setSrc, "src"_a.none(false), + .def("setSrc", &FileTransform::setSrc, "src"_a.none(false), DOC(FileTransform, setSrc)) - .def("getCCCId", &FileTransform::getCCCId, + .def("getCCCId", &FileTransform::getCCCId, DOC(FileTransform, getCCCId)) - .def("setCCCId", &FileTransform::setCCCId, "cccId"_a.none(false), + .def("setCCCId", &FileTransform::setCCCId, "cccId"_a.none(false), DOC(FileTransform, setCCCId)) - .def("getCDLStyle", &FileTransform::getCDLStyle, + .def("getCDLStyle", &FileTransform::getCDLStyle, DOC(FileTransform, getCDLStyle)) - .def("setCDLStyle", &FileTransform::setCDLStyle, "style"_a, + .def("setCDLStyle", &FileTransform::setCDLStyle, "style"_a, DOC(FileTransform, setCDLStyle)) - .def("getInterpolation", &FileTransform::getInterpolation, + .def("getInterpolation", &FileTransform::getInterpolation, DOC(FileTransform, getInterpolation)) - .def("setInterpolation", &FileTransform::setInterpolation, "interpolation"_a, - DOC(FileTransform, setInterpolation)); + .def("setInterpolation", &FileTransform::setInterpolation, "interpolation"_a, + DOC(FileTransform, setInterpolation)) + .def_static("IsFormatExtensionSupported", &FileTransform::IsFormatExtensionSupported, "extension"_a, + DOC(FileTransform, IsFormatExtensionSupported)); defRepr(clsFileTransform); clsFormatIterator - .def("__len__", [](FormatIterator & /* it */) - { - return FileTransform::GetNumFormats(); + .def("__len__", [](FormatIterator & /* it */) + { + return FileTransform::GetNumFormats(); }) - .def("__getitem__", [](FormatIterator & it, int i) - { + .def("__getitem__", [](FormatIterator & it, int i) + { it.checkIndex(i, FileTransform::GetNumFormats()); - return py::make_tuple(FileTransform::GetFormatNameByIndex(i), + return py::make_tuple(FileTransform::GetFormatNameByIndex(i), FileTransform::GetFormatExtensionByIndex(i)); }) - .def("__iter__", [](FormatIterator & it) -> FormatIterator & - { - return it; + .def("__iter__", [](FormatIterator & it) -> FormatIterator & + { + return it; }) .def("__next__", [](FormatIterator & it) { int i = it.nextIndex(FileTransform::GetNumFormats()); - return py::make_tuple(FileTransform::GetFormatNameByIndex(i), + return py::make_tuple(FileTransform::GetFormatNameByIndex(i), FileTransform::GetFormatExtensionByIndex(i)); }); } diff --git a/tests/cpu/transforms/FileTransform_tests.cpp b/tests/cpu/transforms/FileTransform_tests.cpp index f4eabf55da..a7ccec15b3 100644 --- a/tests/cpu/transforms/FileTransform_tests.cpp +++ b/tests/cpu/transforms/FileTransform_tests.cpp @@ -297,6 +297,8 @@ OCIO_ADD_TEST(FileTransform, is_format_extension_supported) OCIO_CHECK_EQUAL(formatRegistry.isFormatExtensionSupported("bar"), false); OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("cdl")); OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported(".cdl")); + OCIO_CHECK_EQUAL(formatRegistry.isFormatExtensionSupported("Cdl"), false); + OCIO_CHECK_EQUAL(formatRegistry.isFormatExtensionSupported(".Cdl"), false); OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("3dl")); OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported(".3dl")); } diff --git a/tests/python/FileTransformTest.py b/tests/python/FileTransformTest.py index 84ac59ca42..8d91596891 100644 --- a/tests/python/FileTransformTest.py +++ b/tests/python/FileTransformTest.py @@ -85,6 +85,19 @@ def test_cdlstyle(self): with self.assertRaises(TypeError): self.tr.setCDLStyle(invalid) + def test_is_format_extension_supported(self): + """ + Test the IsFormatExtensionSupported() method. + """ + self.assertFalse(self.tr.IsFormatExtensionSupported('foo')) + self.assertFalse(self.tr.IsFormatExtensionSupported('bar')) + self.assertTrue(self.tr.IsFormatExtensionSupported('cdl')) + self.assertTrue(self.tr.IsFormatExtensionSupported('.cdl')) + self.assertFalse(self.tr.IsFormatExtensionSupported('Cdl')) + self.assertFalse(self.tr.IsFormatExtensionSupported('.Cdl')) + self.assertTrue(self.tr.IsFormatExtensionSupported('3dl')) + self.assertTrue(self.tr.IsFormatExtensionSupported('.3dl')) + def test_getformats(self): """ Test the getFormats() method. From 537431d16bb750d34609c2b0c043c706df84134b Mon Sep 17 00:00:00 2001 From: Mei Chu Date: Sat, 30 Mar 2024 22:54:41 -0700 Subject: [PATCH 6/9] Change extension accepted to IsFormatExtensionSupported() to case-insensitive. Signed-off-by: Mei Chu --- src/OpenColorIO/transforms/FileTransform.cpp | 4 ++-- tests/cpu/transforms/FileTransform_tests.cpp | 4 ++-- tests/python/FileTransformTest.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/OpenColorIO/transforms/FileTransform.cpp b/src/OpenColorIO/transforms/FileTransform.cpp index 75423d3627..d258828ed0 100755 --- a/src/OpenColorIO/transforms/FileTransform.cpp +++ b/src/OpenColorIO/transforms/FileTransform.cpp @@ -533,11 +533,11 @@ bool FormatRegistry::isFormatExtensionSupported(const char * extension) const // If dot is present at the start, pointer arithmetic increment up by one to ignore that dot. if (extension[0] == '.') { - iter = m_formatsByExtension.find(extension+1); + iter = m_formatsByExtension.find(StringUtils::Lower(extension + 1)); } else { - iter = m_formatsByExtension.find(extension); + iter = m_formatsByExtension.find(StringUtils::Lower(extension)); } if (iter != m_formatsByExtension.end()) { diff --git a/tests/cpu/transforms/FileTransform_tests.cpp b/tests/cpu/transforms/FileTransform_tests.cpp index a7ccec15b3..334e22a21a 100644 --- a/tests/cpu/transforms/FileTransform_tests.cpp +++ b/tests/cpu/transforms/FileTransform_tests.cpp @@ -297,8 +297,8 @@ OCIO_ADD_TEST(FileTransform, is_format_extension_supported) OCIO_CHECK_EQUAL(formatRegistry.isFormatExtensionSupported("bar"), false); OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("cdl")); OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported(".cdl")); - OCIO_CHECK_EQUAL(formatRegistry.isFormatExtensionSupported("Cdl"), false); - OCIO_CHECK_EQUAL(formatRegistry.isFormatExtensionSupported(".Cdl"), false); + OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("Cdl")); + OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported(".Cdl")); OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("3dl")); OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported(".3dl")); } diff --git a/tests/python/FileTransformTest.py b/tests/python/FileTransformTest.py index 8d91596891..7d87a71161 100644 --- a/tests/python/FileTransformTest.py +++ b/tests/python/FileTransformTest.py @@ -93,8 +93,8 @@ def test_is_format_extension_supported(self): self.assertFalse(self.tr.IsFormatExtensionSupported('bar')) self.assertTrue(self.tr.IsFormatExtensionSupported('cdl')) self.assertTrue(self.tr.IsFormatExtensionSupported('.cdl')) - self.assertFalse(self.tr.IsFormatExtensionSupported('Cdl')) - self.assertFalse(self.tr.IsFormatExtensionSupported('.Cdl')) + self.assertTrue(self.tr.IsFormatExtensionSupported('Cdl')) + self.assertTrue(self.tr.IsFormatExtensionSupported('.Cdl')) self.assertTrue(self.tr.IsFormatExtensionSupported('3dl')) self.assertTrue(self.tr.IsFormatExtensionSupported('.3dl')) From 0763c377239ec2b14f33b68b6fce6158aa9cdf2b Mon Sep 17 00:00:00 2001 From: Mei Chu Date: Sun, 31 Mar 2024 11:32:10 -0700 Subject: [PATCH 7/9] Bugfix to account for single dot input. Signed-off-by: Mei Chu --- src/OpenColorIO/transforms/FileTransform.cpp | 7 ++++++- tests/cpu/transforms/FileTransform_tests.cpp | 1 + tests/python/FileTransformTest.py | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/OpenColorIO/transforms/FileTransform.cpp b/src/OpenColorIO/transforms/FileTransform.cpp index d258828ed0..75793865e3 100755 --- a/src/OpenColorIO/transforms/FileTransform.cpp +++ b/src/OpenColorIO/transforms/FileTransform.cpp @@ -531,7 +531,12 @@ bool FormatRegistry::isFormatExtensionSupported(const char * extension) const { FileFormatVectorMap::const_iterator iter; // If dot is present at the start, pointer arithmetic increment up by one to ignore that dot. - if (extension[0] == '.') + // Early return false with malicious input of just the dot. + if (0 == strcmp(extension, ".")) + { + return false; + } + else if (extension[0] == '.') { iter = m_formatsByExtension.find(StringUtils::Lower(extension + 1)); } diff --git a/tests/cpu/transforms/FileTransform_tests.cpp b/tests/cpu/transforms/FileTransform_tests.cpp index 334e22a21a..02e304da21 100644 --- a/tests/cpu/transforms/FileTransform_tests.cpp +++ b/tests/cpu/transforms/FileTransform_tests.cpp @@ -295,6 +295,7 @@ OCIO_ADD_TEST(FileTransform, is_format_extension_supported) OCIO::FormatRegistry & formatRegistry = OCIO::FormatRegistry::GetInstance(); OCIO_CHECK_EQUAL(formatRegistry.isFormatExtensionSupported("foo"), false); OCIO_CHECK_EQUAL(formatRegistry.isFormatExtensionSupported("bar"), false); + OCIO_CHECK_EQUAL(formatRegistry.isFormatExtensionSupported("."), false); OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("cdl")); OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported(".cdl")); OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("Cdl")); diff --git a/tests/python/FileTransformTest.py b/tests/python/FileTransformTest.py index 7d87a71161..31c51cdd07 100644 --- a/tests/python/FileTransformTest.py +++ b/tests/python/FileTransformTest.py @@ -91,6 +91,7 @@ def test_is_format_extension_supported(self): """ self.assertFalse(self.tr.IsFormatExtensionSupported('foo')) self.assertFalse(self.tr.IsFormatExtensionSupported('bar')) + self.assertFalse(self.tr.IsFormatExtensionSupported('.')) self.assertTrue(self.tr.IsFormatExtensionSupported('cdl')) self.assertTrue(self.tr.IsFormatExtensionSupported('.cdl')) self.assertTrue(self.tr.IsFormatExtensionSupported('Cdl')) From 2005f7ee90b43264238482a6372303d39bca4338 Mon Sep 17 00:00:00 2001 From: Mei Chu Date: Sun, 31 Mar 2024 11:43:21 -0700 Subject: [PATCH 8/9] Cleanup isFormatExtensionSupported() structure a bit to look nicer. Signed-off-by: Mei Chu --- src/OpenColorIO/transforms/FileTransform.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/OpenColorIO/transforms/FileTransform.cpp b/src/OpenColorIO/transforms/FileTransform.cpp index 75793865e3..deec444462 100755 --- a/src/OpenColorIO/transforms/FileTransform.cpp +++ b/src/OpenColorIO/transforms/FileTransform.cpp @@ -529,14 +529,15 @@ const char * FormatRegistry::getFormatExtensionByIndex(int capability, int index bool FormatRegistry::isFormatExtensionSupported(const char * extension) const { - FileFormatVectorMap::const_iterator iter; - // If dot is present at the start, pointer arithmetic increment up by one to ignore that dot. - // Early return false with malicious input of just the dot. + // Early return false with an input of just the dot. if (0 == strcmp(extension, ".")) { return false; } - else if (extension[0] == '.') + + // If dot is present at the start, pointer arithmetic increment up by one to ignore that dot. + FileFormatVectorMap::const_iterator iter; + if (extension[0] == '.') { iter = m_formatsByExtension.find(StringUtils::Lower(extension + 1)); } @@ -544,6 +545,7 @@ bool FormatRegistry::isFormatExtensionSupported(const char * extension) const { iter = m_formatsByExtension.find(StringUtils::Lower(extension)); } + if (iter != m_formatsByExtension.end()) { return true; From a92e251573ebc0409baaa8e27d71fb8f62835599 Mon Sep 17 00:00:00 2001 From: Mei Chu Date: Mon, 1 Apr 2024 23:21:25 -0700 Subject: [PATCH 9/9] Reset whitespace cleanup. Also add a guard against invalid pointer. Signed-off-by: Mei Chu --- include/OpenColorIO/OpenColorTransforms.h | 38 ++++++------ src/OpenColorIO/transforms/FileTransform.cpp | 44 +++++++------- .../python/transforms/PyFileTransform.cpp | 60 +++++++++---------- tests/cpu/transforms/FileTransform_tests.cpp | 14 ++--- 4 files changed, 78 insertions(+), 78 deletions(-) diff --git a/include/OpenColorIO/OpenColorTransforms.h b/include/OpenColorIO/OpenColorTransforms.h index 57b872e084..e37c59e4c2 100644 --- a/include/OpenColorIO/OpenColorTransforms.h +++ b/include/OpenColorIO/OpenColorTransforms.h @@ -17,7 +17,7 @@ /** * C++ Transforms * ============== - * + * * Typically only needed when creating and/or manipulating configurations */ @@ -228,7 +228,7 @@ extern OCIOEXPORT std::ostream & operator<<(std::ostream &, const BuiltinTransfo /** - * \brief + * \brief * An implementation of the ASC Color Decision List (CDL), based on the ASC v1.2 * specification. * @@ -236,7 +236,7 @@ extern OCIOEXPORT std::ostream & operator<<(std::ostream &, const BuiltinTransfo * * Slope, offset, power:: * out = clamp( (in * slope) + offset ) ^ power - * + * * \note​ * If the config version is 1, negative values are clamped if the power is not 1.0. * For config version 2 and higher, the negative handling is controlled by the CDL style. @@ -256,7 +256,7 @@ class OCIOEXPORT CDLTransform : public Transform * if file does not contain any CDL or if the specified cccid is not found. */ static CDLTransformRcPtr CreateFromFile(const char * src, const char * cccid); - + /** * \brief Load all of the CDLs in a .cdl or .ccc file into a single GroupTransform. * @@ -842,7 +842,7 @@ class OCIOEXPORT ExponentTransform : public Transform */ virtual NegativeStyle getNegativeStyle() const = 0; virtual void setNegativeStyle(NegativeStyle style) = 0; - + ExponentTransform(const ExponentTransform &) = delete; ExponentTransform & operator= (const ExponentTransform &) = delete; /// Do not use (needed only for pybind11). @@ -883,7 +883,7 @@ class OCIOEXPORT ExponentWithLinearTransform : public Transform /** * Set the exponent value for the power function for R, G, B, A. * - * \note + * \note * The gamma values must be in the range of [1, 10]. Set the transform direction * to inverse to obtain the effect of values less than 1. */ @@ -893,7 +893,7 @@ class OCIOEXPORT ExponentWithLinearTransform : public Transform /** * Set the offset value for the power function for R, G, B, A. * - * \note + * \note * The offset values must be in the range [0, 0.9]. */ virtual void setOffset(const double(&values)[4]) noexcept = 0; @@ -907,7 +907,7 @@ class OCIOEXPORT ExponentWithLinearTransform : public Transform */ virtual NegativeStyle getNegativeStyle() const = 0; virtual void setNegativeStyle(NegativeStyle style) = 0; - + ExponentWithLinearTransform(const ExponentWithLinearTransform &) = delete; ExponentWithLinearTransform & operator= (const ExponentWithLinearTransform &) = delete; /// Do not use (needed only for pybind11). @@ -1234,8 +1234,8 @@ class OCIOEXPORT GradingRGBCurveTransform : public Transform virtual void setValue(const ConstGradingRGBCurveRcPtr & values) = 0; /** - * It is possible to provide a desired slope value for each control point. The number of slopes is - * always the same as the number of control points and so the control points must be set before + * It is possible to provide a desired slope value for each control point. The number of slopes is + * always the same as the number of control points and so the control points must be set before * setting the slopes. The slopes are primarily intended for use by config authors looking to match * a specific shape with as few control points as possible, they are not intended to be exposed to * a user interface for direct manipulation. When a curve is being generated for creative purposes @@ -1292,7 +1292,7 @@ extern OCIOEXPORT std::ostream & operator<<(std::ostream &, const GradingRGBCurv * Each control allows R, G, B adjustments and a Master adjustment. * * There is also an S-contrast control for imparting an S-shape curve. - * + * * The controls are dynamic, so they may be adjusted even after the Transform has been included * in a Processor. */ @@ -1455,7 +1455,7 @@ extern OCIOEXPORT std::ostream & operator<<(std::ostream &, const LogAffineTrans * is used for many camera logs (e.g., LogC) as well as ACEScct. * * * The linSideBreak specifies the point on the linear axis where the log and linear - * segments meet. It must be set (there is no default). + * segments meet. It must be set (there is no default). * * The linearSlope specifies the slope of the linear segment of the forward (linToLog) * transform. By default it is set equal to the slope of the log curve at the break point. */ @@ -1492,14 +1492,14 @@ class OCIOEXPORT LogCameraTransform : public Transform virtual bool getLinearSlopeValue(double(&values)[3]) const = 0; /** * \brief Set LinearSlope value. - * + * * \note * You must call setLinSideBreakValue before calling this. */ virtual void setLinearSlopeValue(const double(&values)[3]) = 0; /// Remove LinearSlope values so that default values are used. virtual void unsetLinearSlopeValue() = 0; - + LogCameraTransform(const LogCameraTransform &) = delete; LogCameraTransform & operator= (const LogCameraTransform &) = delete; /// Do not use (needed only for pybind11). @@ -1684,7 +1684,7 @@ class OCIOEXPORT Lut1DTransform : public Transform * For example, the value 1.0 would be written as the integer 15360 * because it has the same bit-pattern. Note that this implies the * values will be quantized to a 16-bit float. Note that this setting - * only controls the output formatting (where supported) and not the + * only controls the output formatting (where supported) and not the * values for getValue/setValue. The only file formats that currently * support this are CLF and CTF. */ @@ -1789,7 +1789,7 @@ extern OCIOEXPORT std::ostream& operator<< (std::ostream&, const Lut3DTransform& /** * Represents an MX+B Matrix transform. * - * \note + * \note * For singular matrices, an inverse direction will throw an exception during finalization. */ class OCIOEXPORT MatrixTransform : public Transform @@ -1834,7 +1834,7 @@ class OCIOEXPORT MatrixTransform : public Transform * outside [0,1]. */ virtual void setOffset(const double * offset4) = 0; - + /** * Get the bit-depths associated with the matrix values read from a * file or set the bit-depths of values to be written to a file @@ -1855,7 +1855,7 @@ class OCIOEXPORT MatrixTransform : public Transform /// **Convenience functions** /// /// Build the matrix and offset corresponding to higher-level concepts. - /// + /// /// \note /// These can throw an exception if for any component /// ``oldmin == oldmax. (divide by 0)`` @@ -1893,7 +1893,7 @@ extern OCIOEXPORT std::ostream & operator<<(std::ostream &, const MatrixTransfor * The Range is used to apply an affine transform (scale & offset) and * clamps values to min/max bounds on all color components except the alpha. * The scale and offset values are computed from the input and output bounds. - * + * * Refer to section 7.2.4 in specification S-2014-006 "A Common File Format * for Look-Up Tables" from the Academy of Motion Picture Arts and Sciences * and the American Society of Cinematographers. diff --git a/src/OpenColorIO/transforms/FileTransform.cpp b/src/OpenColorIO/transforms/FileTransform.cpp index deec444462..faf1d343e3 100755 --- a/src/OpenColorIO/transforms/FileTransform.cpp +++ b/src/OpenColorIO/transforms/FileTransform.cpp @@ -186,8 +186,8 @@ std::ostream& operator<< (std::ostream& os, const FileTransform& t) // Wrapper around ConfigIOProxy getLutData implementation. std::unique_ptr getLutData( - const Config & config, - const std::string & filepath, + const Config & config, + const std::string & filepath, std::ios_base::openmode mode) { if (config.getConfigIOProxy()) @@ -223,7 +223,7 @@ void closeLutStream(const Config & config, const std::istream & istream) } } -bool CollectContextVariables(const Config &, +bool CollectContextVariables(const Config &, const Context & context, const FileTransform & tr, ContextRcPtr & usedContextVars) @@ -235,7 +235,7 @@ bool CollectContextVariables(const Config &, bool foundContextVars = false; // Used to collect the context variables needed to resolve the src string itself (not involving - // the search_path yet). + // the search_path yet). ContextRcPtr ctxFilename = Context::Create(); ctxFilename->setSearchPath(context.getSearchPath()); ctxFilename->setWorkingDir(context.getWorkingDir()); @@ -252,7 +252,7 @@ bool CollectContextVariables(const Config &, // resolveFileLocation returns all usedContextVars in the search_path, regardless of whether // they are needed for the given file. The work-around is to compare the resolved location // with and without using the environment -- if they are the same, it means the environment - // was not used. So we create an empty context for this purpose. + // was not used. So we create an empty context for this purpose. ContextRcPtr emptyContext = Context::Create(); emptyContext->setSearchPath(context.getSearchPath()); @@ -499,7 +499,7 @@ const char * FormatRegistry::getFormatExtensionByIndex(int capability, int index { if(capability == FORMAT_CAPABILITY_READ) { - if(index<0 + if(index<0 || index>=static_cast(m_readFormatExtensions.size())) { return ""; @@ -517,7 +517,7 @@ const char * FormatRegistry::getFormatExtensionByIndex(int capability, int index } else if(capability == FORMAT_CAPABILITY_WRITE) { - if(index<0 + if(index<0 || index>=static_cast(m_writeFormatExtensions.size())) { return ""; @@ -529,8 +529,8 @@ const char * FormatRegistry::getFormatExtensionByIndex(int capability, int index bool FormatRegistry::isFormatExtensionSupported(const char * extension) const { - // Early return false with an input of just the dot. - if (0 == strcmp(extension, ".")) + // Early return false with an input of just the dot or invalid pointer. + if (!extension || !*extension || 0 == strcmp(extension, ".")) { return false; } @@ -632,11 +632,11 @@ void LoadFileUncached(FileFormat * & returnFormat, { pStream = getLutData( config, - filepath, - tryFormat->isBinary() ? std::ios_base::binary : std::ios_base::in + filepath, + tryFormat->isBinary() ? std::ios_base::binary : std::ios_base::in ); auto & filestream = *pStream; - + if (!filestream.good()) { std::ostringstream os; @@ -668,7 +668,7 @@ void LoadFileUncached(FileFormat * & returnFormat, { if (pStream) { - closeLutStream(config, *pStream); + closeLutStream(config, *pStream); } primaryErrorText += " '"; @@ -709,11 +709,11 @@ void LoadFileUncached(FileFormat * & returnFormat, { pStream = getLutData( config, - filepath, - altFormat->isBinary() ? std::ios_base::binary : std::ios_base::in + filepath, + altFormat->isBinary() ? std::ios_base::binary : std::ios_base::in ); auto& filestream = *pStream; - + if (!filestream.good()) { std::ostringstream os; @@ -746,9 +746,9 @@ void LoadFileUncached(FileFormat * & returnFormat, { if (pStream) { - closeLutStream(config, *pStream); + closeLutStream(config, *pStream); } - + if(IsDebugLoggingEnabled()) { std::ostringstream os; @@ -830,7 +830,7 @@ void GetCachedFileAndFormat(FileFormat * & format, FileCacheResultPtr result; { AutoMutex guard(g_fileCache.lock()); - + if (g_fileCache.isEnabled()) { // As the entry is a shared pointer instance, having an empty one @@ -951,9 +951,9 @@ void BuildFileTransformOps(OpRcPtrVec & ops, FileFormat* format = NULL; CachedFileRcPtr cachedFile; - GetCachedFileAndFormat(format, - cachedFile, - filepath, + GetCachedFileAndFormat(format, + cachedFile, + filepath, fileTransform.getInterpolation(), config); diff --git a/src/bindings/python/transforms/PyFileTransform.cpp b/src/bindings/python/transforms/PyFileTransform.cpp index 528ba22ef5..3d70800988 100644 --- a/src/bindings/python/transforms/PyFileTransform.cpp +++ b/src/bindings/python/transforms/PyFileTransform.cpp @@ -22,21 +22,21 @@ void bindPyFileTransform(py::module & m) { FileTransformRcPtr DEFAULT = FileTransform::Create(); - auto clsFileTransform = + auto clsFileTransform = py::class_( m.attr("FileTransform")); - auto clsFormatIterator = + auto clsFormatIterator = py::class_( clsFileTransform, "FormatIterator"); clsFileTransform - .def(py::init(&FileTransform::Create), + .def(py::init(&FileTransform::Create), DOC(FileTransform, Create)) - .def(py::init([](const std::string & src, - const std::string & id, + .def(py::init([](const std::string & src, + const std::string & id, Interpolation interp, - TransformDirection dir) + TransformDirection dir) { FileTransformRcPtr p = FileTransform::Create(); if (!src.empty()) { p->setSrc(src.c_str()); } @@ -45,33 +45,33 @@ void bindPyFileTransform(py::module & m) p->setDirection(dir); p->validate(); return p; - }), - "src"_a = DEFAULT->getSrc(), + }), + "src"_a = DEFAULT->getSrc(), "cccId"_a = DEFAULT->getCCCId(), "interpolation"_a = DEFAULT->getInterpolation(), - "direction"_a = DEFAULT->getDirection(), + "direction"_a = DEFAULT->getDirection(), DOC(FileTransform, Create)) - .def_static("getFormats", []() - { - return FormatIterator(nullptr); + .def_static("getFormats", []() + { + return FormatIterator(nullptr); }) - .def("getSrc", &FileTransform::getSrc, + .def("getSrc", &FileTransform::getSrc, DOC(FileTransform, getSrc)) - .def("setSrc", &FileTransform::setSrc, "src"_a.none(false), + .def("setSrc", &FileTransform::setSrc, "src"_a.none(false), DOC(FileTransform, setSrc)) - .def("getCCCId", &FileTransform::getCCCId, + .def("getCCCId", &FileTransform::getCCCId, DOC(FileTransform, getCCCId)) - .def("setCCCId", &FileTransform::setCCCId, "cccId"_a.none(false), + .def("setCCCId", &FileTransform::setCCCId, "cccId"_a.none(false), DOC(FileTransform, setCCCId)) - .def("getCDLStyle", &FileTransform::getCDLStyle, + .def("getCDLStyle", &FileTransform::getCDLStyle, DOC(FileTransform, getCDLStyle)) - .def("setCDLStyle", &FileTransform::setCDLStyle, "style"_a, + .def("setCDLStyle", &FileTransform::setCDLStyle, "style"_a, DOC(FileTransform, setCDLStyle)) - .def("getInterpolation", &FileTransform::getInterpolation, + .def("getInterpolation", &FileTransform::getInterpolation, DOC(FileTransform, getInterpolation)) - .def("setInterpolation", &FileTransform::setInterpolation, "interpolation"_a, + .def("setInterpolation", &FileTransform::setInterpolation, "interpolation"_a, DOC(FileTransform, setInterpolation)) .def_static("IsFormatExtensionSupported", &FileTransform::IsFormatExtensionSupported, "extension"_a, DOC(FileTransform, IsFormatExtensionSupported)); @@ -79,24 +79,24 @@ void bindPyFileTransform(py::module & m) defRepr(clsFileTransform); clsFormatIterator - .def("__len__", [](FormatIterator & /* it */) - { - return FileTransform::GetNumFormats(); + .def("__len__", [](FormatIterator & /* it */) + { + return FileTransform::GetNumFormats(); }) - .def("__getitem__", [](FormatIterator & it, int i) - { + .def("__getitem__", [](FormatIterator & it, int i) + { it.checkIndex(i, FileTransform::GetNumFormats()); - return py::make_tuple(FileTransform::GetFormatNameByIndex(i), + return py::make_tuple(FileTransform::GetFormatNameByIndex(i), FileTransform::GetFormatExtensionByIndex(i)); }) - .def("__iter__", [](FormatIterator & it) -> FormatIterator & - { - return it; + .def("__iter__", [](FormatIterator & it) -> FormatIterator & + { + return it; }) .def("__next__", [](FormatIterator & it) { int i = it.nextIndex(FileTransform::GetNumFormats()); - return py::make_tuple(FileTransform::GetFormatNameByIndex(i), + return py::make_tuple(FileTransform::GetFormatNameByIndex(i), FileTransform::GetFormatExtensionByIndex(i)); }); } diff --git a/tests/cpu/transforms/FileTransform_tests.cpp b/tests/cpu/transforms/FileTransform_tests.cpp index 02e304da21..9b78b9c50f 100644 --- a/tests/cpu/transforms/FileTransform_tests.cpp +++ b/tests/cpu/transforms/FileTransform_tests.cpp @@ -149,7 +149,7 @@ OCIO_ADD_TEST(FileTransform, load_file_fail) // Supported file extension with a wrong content. // It's in fact a binary png file i.e. all readers must fail. const std::string faultyCLFFile("clf/illegal/image_png.clf"); - OCIO_CHECK_THROW_WHAT(OCIO::GetFileTransformProcessor(faultyCLFFile), + OCIO_CHECK_THROW_WHAT(OCIO::GetFileTransformProcessor(faultyCLFFile), OCIO::Exception, "image_png.clf' could not be loaded"); // Missing file. @@ -332,7 +332,7 @@ OCIO_ADD_TEST(FileTransform, interpolation_validity) OCIO_CHECK_NO_THROW(cfg->getProcessor(tr)); // UNKNOWN can't be used by a LUT file, so the interp on the LUT is set to DEFAULT and a - // warning is logged. + // warning is logged. tr->setInterpolation(OCIO::INTERP_UNKNOWN); OCIO_CHECK_NO_THROW(tr->validate()); @@ -369,7 +369,7 @@ OCIO_ADD_TEST(FileTransform, context_variables) { // Test context variables with a FileTransform i.e. the file name or the search_path could // contain one or several context variables. - + OCIO::ContextRcPtr usedContextVars = OCIO::Context::Create(); OCIO::ConfigRcPtr cfg = OCIO::Config::CreateRaw()->createEditableCopy(); @@ -443,13 +443,13 @@ OCIO_ADD_TEST(FileTransform, context_variables) OCIO_CHECK_EQUAL(std::string("ENV1"), usedContextVars->getStringVarNameByIndex(1)); OCIO_CHECK_EQUAL(std::string("exposure_contrast_linear.ctf"), usedContextVars->getStringVarByIndex(1)); - // A basic check to validate that context variables are correctly used. + // A basic check to validate that context variables are correctly used. OCIO_CHECK_NO_THROW(cfg->getProcessor(ctx, file, OCIO::TRANSFORM_DIR_FORWARD)); { // Case 4 - The 'cccid' now contains a context variable - static const std::string CONFIG = + static const std::string CONFIG = "ocio_profile_version: 2\n" "\n" "environment:\n" @@ -489,7 +489,7 @@ OCIO_ADD_TEST(FileTransform, context_variables) ); OCIO::ConstFileTransformRcPtr fTr1 = OCIO::DynamicPtrCast(tr1); OCIO_CHECK_ASSERT(fTr1); - + OCIO_CHECK_ASSERT(CollectContextVariables(*cfg, *ctx, *fTr1, usedContextVars)); OCIO_CHECK_EQUAL(2, usedContextVars->getNumStringVars()); OCIO_CHECK_EQUAL(std::string("CCPREFIX"), usedContextVars->getStringVarNameByIndex(0)); @@ -501,7 +501,7 @@ OCIO_ADD_TEST(FileTransform, context_variables) OCIO_ADD_TEST(FileTransform, cc_file_with_different_file_extension) { - static const std::string BASE_CONFIG = + static const std::string BASE_CONFIG = "ocio_profile_version: 1\n" "description: Minimal\n" "search_path: " + OCIO::GetTestFilesDir() + "\n"