diff --git a/tests/cpu/Context_tests.cpp b/tests/cpu/Context_tests.cpp index c8d4052ffd..fc5fb22780 100644 --- a/tests/cpu/Context_tests.cpp +++ b/tests/cpu/Context_tests.cpp @@ -119,8 +119,8 @@ OCIO_ADD_TEST(Context, use_searchpaths) const std::string res1 = searchPath1 + "/Context.cpp"; OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(), SanitizePath(res1.c_str()).c_str()) == 0); - OCIO_CHECK_NO_THROW(resolvedSource = context->resolveFileLocation("GPUHelpers.h")); - const std::string res2 = searchPath2 + "/GPUHelpers.h"; + OCIO_CHECK_NO_THROW(resolvedSource = context->resolveFileLocation("GPUUnitTest.h")); + const std::string res2 = searchPath2 + "/GPUUniTest.h"; OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(), SanitizePath(res2.c_str()).c_str()) == 0); } @@ -141,8 +141,8 @@ OCIO_ADD_TEST(Context, use_searchpaths_workingdir) const std::string res1 = ociodir + "/" + searchPath1 + "/Context.cpp"; OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(), SanitizePath(res1.c_str()).c_str()) == 0); - OCIO_CHECK_NO_THROW(resolvedSource = context->resolveFileLocation("GPUHelpers.h")); - const std::string res2 = ociodir + "/" + searchPath2 + "/GPUHelpers.h"; + OCIO_CHECK_NO_THROW(resolvedSource = context->resolveFileLocation("GPUUnitTest.h")); + const std::string res2 = ociodir + "/" + searchPath2 + "/GPUUnitTest.h"; OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(), SanitizePath(res2.c_str()).c_str()) == 0); } diff --git a/tests/data/files/lut3d_arbitrary.csp b/tests/data/files/lut3d_arbitrary.csp new file mode 100644 index 0000000000..7babf7c08b --- /dev/null +++ b/tests/data/files/lut3d_arbitrary.csp @@ -0,0 +1,22 @@ +CSPLUTV100 +3D + +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 + +2 2 2 +0.100000 0.100000 0.100000 +1.100000 0.100000 0.100000 +0.100000 1.100000 0.100000 +1.100000 1.100000 0.100000 +0.100000 0.100000 1.100000 +1.100000 0.100000 1.100000 +0.100000 1.100000 1.100000 +1.100000 1.100000 1.100000 diff --git a/tests/data/files/lut3d_blu-only.csp b/tests/data/files/lut3d_blu-only.csp new file mode 100644 index 0000000000..e9f68bee8c --- /dev/null +++ b/tests/data/files/lut3d_blu-only.csp @@ -0,0 +1,22 @@ +CSPLUTV100 +3D + +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 + +2 2 2 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 1.0 +0.0 0.0 1.0 +0.0 0.0 1.0 +0.0 0.0 1.0 diff --git a/tests/data/files/lut3d_grn-only.csp b/tests/data/files/lut3d_grn-only.csp new file mode 100644 index 0000000000..e62fa8fce6 --- /dev/null +++ b/tests/data/files/lut3d_grn-only.csp @@ -0,0 +1,22 @@ +CSPLUTV100 +3D + +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 + +2 2 2 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 1.0 0.0 +0.0 1.0 0.0 +0.0 1.0 0.0 +0.0 1.0 0.0 diff --git a/tests/data/files/lut3d_red-only.cp b/tests/data/files/lut3d_red-only.cp new file mode 100644 index 0000000000..7a08c38d81 --- /dev/null +++ b/tests/data/files/lut3d_red-only.cp @@ -0,0 +1,22 @@ +CSPLUTV100 +3D + +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 + +2 2 2 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +1.0 0.0 0.0 +1.0 0.0 0.0 +1.0 0.0 0.0 +1.0 0.0 0.0 diff --git a/tests/gpu/CDLOp_test.cpp b/tests/gpu/CDLOp_test.cpp index 9f32d0d42a..ddf1b43eeb 100644 --- a/tests/gpu/CDLOp_test.cpp +++ b/tests/gpu/CDLOp_test.cpp @@ -9,7 +9,6 @@ #include #include "GPUUnitTest.h" -#include "GPUHelpers.h" namespace OCIO = OCIO_NAMESPACE; diff --git a/tests/gpu/CMakeLists.txt b/tests/gpu/CMakeLists.txt index 4e16243bfd..2c56f2948b 100644 --- a/tests/gpu/CMakeLists.txt +++ b/tests/gpu/CMakeLists.txt @@ -12,7 +12,6 @@ set(SOURCES ECOp_test.cpp FixedFunctionOp_test.cpp GammaOp_test.cpp - GPUHelpers.cpp GPUUnitTest.cpp GradingPrimaryOp_test.cpp GradingRGBCurveOp_test.cpp diff --git a/tests/gpu/GPUHelpers.cpp b/tests/gpu/GPUHelpers.cpp deleted file mode 100644 index 317e772461..0000000000 --- a/tests/gpu/GPUHelpers.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// Copyright Contributors to the OpenColorIO Project. - - -#include -#include - -#if !defined(_WIN32) -#include -#include -#include -#endif - -#include - -#include "GPUHelpers.h" - -namespace OCIO = OCIO_NAMESPACE; - - -// TODO: Make OCIO::Platform::CreateTempFilename() public so it could be used here. - -std::string createTempFile(const std::string& fileExt, const std::string& fileContent) -{ - // Note: because of security issue, tmpnam could not be used - - std::string filename; - -#ifdef _WIN32 - - char tmpFilename[L_tmpnam]; - if(tmpnam_s(tmpFilename)) - { - throw OCIO::Exception("Could not create a temporary file"); - } - - // Note that when a file name is pre-pended with a backslash and no path information, such as \fname21, this - // indicates that the name is valid for the current working directory. - filename = tmpFilename[0] == '\\' ? tmpFilename + 1 : tmpFilename; - filename += fileExt; - -#else - - std::stringstream ss; - ss << "/tmp/ocio"; - ss << std::rand(); - ss << fileExt; - - filename = ss.str(); - -#endif - - std::ofstream ofs(filename.c_str(), std::ios_base::out); - ofs << fileContent; - ofs.close(); - - return filename; -} diff --git a/tests/gpu/GPUHelpers.h b/tests/gpu/GPUHelpers.h deleted file mode 100644 index e49be0e1d3..0000000000 --- a/tests/gpu/GPUHelpers.h +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// Copyright Contributors to the OpenColorIO Project. - - -#ifndef OPENCOLORIO_GPU_HELPERS_H -#define OPENCOLORIO_GPU_HELPERS_H - - -#include - -// FIXME: Duplicate function implemented in `src/OpenColorIO/Platform.h and cpp`. -// Implement a function or class for temporary file creation useable by all tests. -std::string createTempFile(const std::string& fileExt, const std::string& fileContent); - - -#endif \ No newline at end of file diff --git a/tests/gpu/GPUUnitTest.cpp b/tests/gpu/GPUUnitTest.cpp index 07b727f034..d329537abf 100644 --- a/tests/gpu/GPUUnitTest.cpp +++ b/tests/gpu/GPUUnitTest.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include diff --git a/tests/gpu/Lut1DOp_test.cpp b/tests/gpu/Lut1DOp_test.cpp index 91d13446bb..cb76697619 100644 --- a/tests/gpu/Lut1DOp_test.cpp +++ b/tests/gpu/Lut1DOp_test.cpp @@ -9,7 +9,6 @@ #include #include "GPUUnitTest.h" -#include "GPUHelpers.h" namespace OCIO = OCIO_NAMESPACE; diff --git a/tests/gpu/Lut3DOp_test.cpp b/tests/gpu/Lut3DOp_test.cpp index d5fc45a0b6..31960235cb 100644 --- a/tests/gpu/Lut3DOp_test.cpp +++ b/tests/gpu/Lut3DOp_test.cpp @@ -13,40 +13,38 @@ namespace OCIO = OCIO_NAMESPACE; +#ifndef OCIO_UNIT_TEST_FILES_DIR +#error Expecting OCIO_UNIT_TEST_FILES_DIR to be defined for tests. Check relevant CMakeLists.txt +#endif + + +// For explanation, refer to https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html +#define _STR(x) #x +#define STR(x) _STR(x) + +static const std::string ocioTestFilesDir(STR(OCIO_UNIT_TEST_FILES_DIR)); + + +namespace +{ +OCIO::FileTransformRcPtr GetFileTransform(const std::string & filename) +{ + const std::string filepath(ocioTestFilesDir + std::string("/") + filename); + + OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); + file->setSrc(filepath.c_str()); + + return file; +} +} + OCIO_ADD_GPU_TEST(Lut3DOp, red_only_using_CSP_file_legacy_shader) { // Any other 3D LUT file format would have been good also. - std::ostringstream content; - content << "CSPLUTV100" << "\n"; - content << "3D" << "\n"; - content << "" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "" << "\n"; - content << "2 2 2" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "1.0 0.0 0.0" << "\n"; - content << "1.0 0.0 0.0" << "\n"; - content << "1.0 0.0 0.0" << "\n"; - content << "1.0 0.0 0.0" << "\n"; - - - const std::string filename = createTempFile(".csp", content.str()); - // Create the transform & set the unit test - OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); + OCIO::FileTransformRcPtr file = GetFileTransform("lut3d_red-only.csp"); file->setSrc(filename.c_str()); file->setInterpolation(OCIO::INTERP_LINEAR); @@ -60,37 +58,9 @@ OCIO_ADD_GPU_TEST(Lut3DOp, green_only_using_CSP_file_legacy_shader) { // Any other 3D LUT file format would have been good also. - std::ostringstream content; - content << "CSPLUTV100" << "\n"; - content << "3D" << "\n"; - content << "" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "" << "\n"; - content << "2 2 2" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 1.0 0.0" << "\n"; - content << "0.0 1.0 0.0" << "\n"; - content << "0.0 1.0 0.0" << "\n"; - content << "0.0 1.0 0.0" << "\n"; - - - const std::string filename = createTempFile(".csp", content.str()); - // Create the transform & set the unit test - OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); - file->setSrc(filename.c_str()); + OCIO::FileTransformRcPtr file = GetFileTransform("lut3d_grn-only.csp"); file->setInterpolation(OCIO::INTERP_LINEAR); test.setProcessor(file); @@ -103,37 +73,10 @@ OCIO_ADD_GPU_TEST(Lut3DOp, blue_only_using_CSP_file_legacy_shader) { // Any other 3D LUT file format would have been good also. - std::ostringstream content; - content << "CSPLUTV100" << "\n"; - content << "3D" << "\n"; - content << "" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "" << "\n"; - content << "2 2 2" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 1.0" << "\n"; - content << "0.0 0.0 1.0" << "\n"; - content << "0.0 0.0 1.0" << "\n"; - content << "0.0 0.0 1.0" << "\n"; - - - const std::string filename = createTempFile(".csp", content.str()); // Create the transform & set the unit test - OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); - file->setSrc(filename.c_str()); + OCIO::FileTransformRcPtr file = GetFileTransform("lut3d_blu-only.csp"); file->setInterpolation(OCIO::INTERP_LINEAR); test.setProcessor(file); @@ -147,37 +90,9 @@ OCIO_ADD_GPU_TEST(Lut3DOp, arbitrary_using_CSP_file_legacy_shader) { // Any other 3D LUT file format would have been good also. - std::ostringstream content; - content << "CSPLUTV100" << "\n"; - content << "3D" << "\n"; - content << "" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "" << "\n"; - content << "2 2 2" << "\n"; - content << "0.100000 0.100000 0.100000" << "\n"; - content << "1.100000 0.100000 0.100000" << "\n"; - content << "0.100000 1.100000 0.100000" << "\n"; - content << "1.100000 1.100000 0.100000" << "\n"; - content << "0.100000 0.100000 1.100000" << "\n"; - content << "1.100000 0.100000 1.100000" << "\n"; - content << "0.100000 1.100000 1.100000" << "\n"; - content << "1.100000 1.100000 1.100000" << "\n"; - - - const std::string filename = createTempFile(".csp", content.str()); - // Create the transform & set the unit test - OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); - file->setSrc(filename.c_str()); + OCIO::FileTransformRcPtr file = GetFileTransform("lut3d_arbitrary.csp"); file->setInterpolation(OCIO::INTERP_LINEAR); test.setProcessor(file); @@ -189,37 +104,9 @@ OCIO_ADD_GPU_TEST(Lut3DOp, arbitrary_using_CSP_file_legacy_shader) OCIO_ADD_GPU_TEST(Lut3DOp, arbitrary_using_CSP_file) { - std::ostringstream content; - content << "CSPLUTV100" << "\n"; - content << "3D" << "\n"; - content << "" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "" << "\n"; - content << "2 2 2" << "\n"; - content << "0.100000 0.100000 0.100000" << "\n"; - content << "1.100000 0.100000 0.100000" << "\n"; - content << "0.100000 1.100000 0.100000" << "\n"; - content << "1.100000 1.100000 0.100000" << "\n"; - content << "0.100000 0.100000 1.100000" << "\n"; - content << "1.100000 0.100000 1.100000" << "\n"; - content << "0.100000 1.100000 1.100000" << "\n"; - content << "1.100000 1.100000 1.100000" << "\n"; - - - const std::string filename = createTempFile(".csp", content.str()); - // Create the transform & set the unit test - OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); - file->setSrc(filename.c_str()); + OCIO::FileTransformRcPtr file = GetFileTransform("lut3d_arbitrary.csp"); file->setInterpolation(OCIO::INTERP_LINEAR); test.setProcessor(file); @@ -233,31 +120,78 @@ OCIO_ADD_GPU_TEST(Lut3DOp, arbitrary_using_CSP_file) -#ifndef OCIO_UNIT_TEST_FILES_DIR -#error Expecting OCIO_UNIT_TEST_FILES_DIR to be defined for tests. Check relevant CMakeLists.txt -#endif +OCIO_ADD_GPU_TEST(Lut3DOp, red_only_using_CSP_file_legacy_shader) +{ + // Any other 3D LUT file format would have been good also. + // Create the transform & set the unit test -// For explanation, refer to https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html -#define _STR(x) #x -#define STR(x) _STR(x) + OCIO::FileTransformRcPtr file = GetFileTransform("Lut3DOp_red_only_using_CSP_file_legacy_shader.csp"); + file->setInterpolation(OCIO::INTERP_LINEAR); -static const std::string ocioTestFilesDir(STR(OCIO_UNIT_TEST_FILES_DIR)); + test.setProcessor(file); + test.setLegacyShader(true); + test.setErrorThreshold(2e-4f); +} -namespace +OCIO_ADD_GPU_TEST(Lut3DOp, green_only_using_CSP_file_legacy_shader) { -OCIO::FileTransformRcPtr GetFileTransform(const std::string & filename) + // Any other 3D LUT file format would have been good also. + // Create the transform & set the unit test + + OCIO::FileTransformRcPtr file = GetFileTransform("Lut3DOp_green_only_using_CSP_file_legacy_shader.csp"); + file->setInterpolation(OCIO::INTERP_LINEAR); + + test.setProcessor(file); + + test.setLegacyShader(true); + test.setErrorThreshold(2e-4f); +} + +OCIO_ADD_GPU_TEST(Lut3DOp, blue_only_using_CSP_file_legacy_shader) { - const std::string filepath(ocioTestFilesDir + std::string("/") + filename); + // Any other 3D LUT file format would have been good also. + // Create the transform & set the unit test - OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); - file->setSrc(filepath.c_str()); + OCIO::FileTransformRcPtr file = GetFileTransform("Lut3DOp_blue_only_using_CSP_file_legacy_shader.csp"); + file->setInterpolation(OCIO::INTERP_LINEAR); - return file; + test.setProcessor(file); + + test.setLegacyShader(true); + test.setErrorThreshold(2e-4f); } + + +OCIO_ADD_GPU_TEST(Lut3DOp, arbitrary_using_CSP_file_legacy_shader) +{ + // Create the transform & set the unit test + + OCIO::FileTransformRcPtr file = GetFileTransform("Lut3DOp_arbitrary_using_CSP_file_legacy_shader.csp"); + file->setInterpolation(OCIO::INTERP_LINEAR); + + test.setProcessor(file); + + test.setLegacyShader(true); + test.setErrorThreshold(2e-4f); } +OCIO_ADD_GPU_TEST(Lut3DOp, arbitrary_using_CSP_file) +{ + // Create the transform & set the unit test + + OCIO::FileTransformRcPtr file = GetFileTransform("Lut3DOp_arbitrary_using_CSP_file.csp"); + file->setInterpolation(OCIO::INTERP_LINEAR); + + test.setProcessor(file); + + // TODO: Small LUTs not being resampled for now, such error threshold is expected + // The legacy shader has a better error threshold because + // it converts all LUTs in one 3D LUT of dimension LUT3D_EDGE_SIZE + // which performs a resampling of small LUTs. + test.setErrorThreshold(1e-2f); +} OCIO_ADD_GPU_TEST(Lut3DOp, 3dlut_file_legacy_shader) { @@ -389,4 +323,3 @@ OCIO_ADD_GPU_TEST(Lut3DOp, 3dlut_biggest_supported) test.setErrorThreshold(1e-4f); } - diff --git a/tests/gpu/RangeOp_test.cpp b/tests/gpu/RangeOp_test.cpp index c94906cfe9..3ae2c90012 100644 --- a/tests/gpu/RangeOp_test.cpp +++ b/tests/gpu/RangeOp_test.cpp @@ -7,7 +7,6 @@ #include -#include "GPUHelpers.h" #include "GPUUnitTest.h" namespace OCIO = OCIO_NAMESPACE;