From c3623796c814a574b10c7818b37c223a5a721915 Mon Sep 17 00:00:00 2001 From: michaeldsmith <37905569+michaeldsmith@users.noreply.github.com> Date: Tue, 3 Jan 2023 17:00:36 -0800 Subject: [PATCH] Issues/0108 ctlrender exr file support (#110) * set HAVE_OPENEXR define * add #include to exr_file.cc * add ctlrender unit tests with EXR files * add windows vcpkg debug test workflow * add debugging info output to /unittest/ctlrender/test.sh * print message if input exr file is unavailable * fix run-time check about uninitialized variable * add valgrind tests for ctlrender using EXR files --- .github/workflows/windows_vcpkg_debug.yml | 40 ++++++++++++++++ ctlrender/CMakeLists.txt | 11 ++++- ctlrender/exr_file.cc | 8 ++++ lib/IlmCtl/CtlTypeStorage.cpp | 2 +- resources/test/scripts/run_valgrind.sh | 58 ++++++++++++++++++++++- unittest/ctlrender/CMakeLists.txt | 19 +++++--- unittest/ctlrender/test.sh | 53 +++++++++++++++++++-- 7 files changed, 177 insertions(+), 14 deletions(-) diff --git a/.github/workflows/windows_vcpkg_debug.yml b/.github/workflows/windows_vcpkg_debug.yml index c967d513..89848089 100644 --- a/.github/workflows/windows_vcpkg_debug.yml +++ b/.github/workflows/windows_vcpkg_debug.yml @@ -51,3 +51,43 @@ jobs: # Build your program with the given configuration run: cmake --build ${{github.workspace}}/build --target install --config ${{env.BUILD_TYPE}} working-directory: ${{github.workspace}} + + test: + # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. + # You can convert this to a matrix build if you need cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + runs-on: windows-latest + + steps: + + - name: install dependencies - imath + run: vcpkg install imath + + - name: install dependencies - openexr + run: vcpkg install openexr + + - name: install dependencies - tiff + run: vcpkg install tiff + + - name: check vcpkg install status + run: vcpkg list + + - uses: actions/checkout@v3 + + - name: Configure CMake + # # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -D "CMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake" + + - name: Build + # Build your program with the given configuration + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + + - name: Install + # Build your program with the given configuration + run: cmake --build ${{github.workspace}}/build --target install --config ${{env.BUILD_TYPE}} + working-directory: ${{github.workspace}} + + - name: Test + working-directory: ${{github.workspace}}/build + run: ctest -V --output-on-failure -C ${{env.BUILD_TYPE}} \ No newline at end of file diff --git a/ctlrender/CMakeLists.txt b/ctlrender/CMakeLists.txt index b080e127..8d91ca0e 100644 --- a/ctlrender/CMakeLists.txt +++ b/ctlrender/CMakeLists.txt @@ -26,6 +26,15 @@ target_link_libraries(ctlrender $<$:OpenEXR::IlmImf> ) +if( OpenEXR_FOUND ) + target_compile_definitions(ctlrender + PRIVATE + -DHAVE_OPENEXR=1 + ) +else() + message( STATUS "OPENEXR not found, ctlrender will not support EXR files" ) +endif() + find_package(TIFF) if(TARGET TIFF::TIFF) message( STATUS "found TIFF, TIFF_LIBRARIES : ${TIFF_LIBRARIES}" ) @@ -38,7 +47,7 @@ if(TARGET TIFF::TIFF) TIFF::TIFF ) else() - message( STATUS "TIFF not found" ) + message( STATUS "TIFF not found, ctlrender will not support TIF files" ) endif() find_package(AcesContainer) diff --git a/ctlrender/exr_file.cc b/ctlrender/exr_file.cc index 055807d4..280ac5c9 100644 --- a/ctlrender/exr_file.cc +++ b/ctlrender/exr_file.cc @@ -53,6 +53,7 @@ /////////////////////////////////////////////////////////////////////////// #include "exr_file.hh" +#include #if defined(HAVE_OPENEXR) #include @@ -70,6 +71,13 @@ bool exr_read(const char *name, float scale, ctl::dpx::fb *pixels, ins.open(name); + if (!ins.good()) + { + fprintf(stderr, "WARNING on line %d of file %s in function %s(): unable to open file %s\n", + __LINE__, __FILE__, __FUNCTION__, name); + return false; + } + ins.read((char *)&magic, sizeof(magic)); endian=0x01020304; if(((unsigned char *)(&endian))[0]==0x01) { diff --git a/lib/IlmCtl/CtlTypeStorage.cpp b/lib/IlmCtl/CtlTypeStorage.cpp index d665e21b..c46537a9 100644 --- a/lib/IlmCtl/CtlTypeStorage.cpp +++ b/lib/IlmCtl/CtlTypeStorage.cpp @@ -656,7 +656,7 @@ void TypeStorage::copy(const TypeStoragePtr &src, size_t src_offset, src->type()->cDataType()==UIntTypeEnum || src->type()->cDataType()==HalfTypeEnum || src->type()->cDataType()==StringTypeEnum)) { - va_list empty; + va_list empty = {}; // fprintf(stderr, "_set %p %d %d %d %d %d\n", out, src->type()->cDataType(), type()->cDataType(), type()->objectSize(), dst_offset, count); _set(in, src->type()->cDataType(), src->type()->objectSize(), dst_offset, count, "", empty); diff --git a/resources/test/scripts/run_valgrind.sh b/resources/test/scripts/run_valgrind.sh index 2b97c990..913a9dd0 100644 --- a/resources/test/scripts/run_valgrind.sh +++ b/resources/test/scripts/run_valgrind.sh @@ -24,13 +24,37 @@ test_03_label="IlmImfCtlTest" cd ../ctlrender valgrind -s --error-exitcode=1 --leak-check=full --track-origins=yes --show-leak-kinds=all ../../ctlrender/ctlrender -force -ctl ../../../unittest/ctlrender/unity.ctl ../../../unittest/ctlrender/bars_nuke_10_be.dpx out.dpx test_04_status=$? -test_04_label="ctlrender" +test_04_label="ctlrender-dpx-to-dpx" + +valgrind -s --error-exitcode=1 --leak-check=full --track-origins=yes --show-leak-kinds=all ../../ctlrender/ctlrender -force -ctl ../../../unittest/ctlrender/unity.ctl ../../../unittest/ctlrender/bars_nuke_10_be.dpx out.tif +test_05_status=$? +test_05_label="ctlrender-dpx-to-tif" + +valgrind -s --error-exitcode=1 --leak-check=full --track-origins=yes --show-leak-kinds=all ../../ctlrender/ctlrender -force -ctl ../../../unittest/ctlrender/unity.ctl ../../../unittest/ctlrender/bars_photoshop_16_le_interleaved.tif out.tif +test_06_status=$? +test_06_label="ctlrender-tif-to-tif" + +valgrind -s --error-exitcode=1 --leak-check=full --track-origins=yes --show-leak-kinds=all ../../ctlrender/ctlrender -force -ctl ../../../unittest/ctlrender/unity.ctl ../../../unittest/ctlrender/bars_photoshop_16_le_interleaved.tif out.dpx +test_07_status=$? +test_07_label="ctlrender-tif-to-dpx" + +valgrind -s --error-exitcode=1 --leak-check=full --track-origins=yes --show-leak-kinds=all ../../ctlrender/ctlrender -force -ctl ../../../unittest/ctlrender/unity.ctl ../../../unittest/ctlrender/bars_photoshop.exr out.exr +test_08_status=$? +test_08_label="ctlrender-exr-to-exr" + +valgrind -s --error-exitcode=1 --leak-check=full --track-origins=yes --show-leak-kinds=all ../../ctlrender/ctlrender -force -format exr16 -ctl ../../../unittest/ctlrender/unity.ctl ../../../unittest/ctlrender/bars_photoshop.exr out.exr +test_09_status=$? +test_09_label="ctlrender-exr-to-exr16" + +valgrind -s --error-exitcode=1 --leak-check=full --track-origins=yes --show-leak-kinds=all ../../ctlrender/ctlrender -force -format exr32 -ctl ../../../unittest/ctlrender/unity.ctl ../../../unittest/ctlrender/bars_photoshop.exr out.exr +test_10_status=$? +test_10_label="ctlrender-exr-to-exr32" # go back to initial path cd $SCRIPTPATH # return valgrind exit codes -if [ $test_01_status -eq 0 ] && [ $test_02_status -eq 0 ] && [ $test_03_status -eq 0 ] && [ $test_04_status -eq 0 ] +if [ $test_01_status -eq 0 ] && [ $test_02_status -eq 0 ] && [ $test_03_status -eq 0 ] && [ $test_04_status -eq 0 ] && [ $test_05_status -eq 0 ] && [ $test_06_status -eq 0 ] && [ $test_07_status -eq 0 ] && [ $test_08_status -eq 0 ] && [ $test_09_status -eq 0 ] && [ $test_10_status -eq 0 ] then echo "Success: valgrind detected no errors" exit 0 @@ -57,5 +81,35 @@ else echo "$test_04_label: valgrind detected errors" fi + if [ $test_05_status -ne 0 ] + then + echo "$test_05_label: valgrind detected errors" + fi + + if [ $test_06_status -ne 0 ] + then + echo "$test_06_label: valgrind detected errors" + fi + + if [ $test_07_status -ne 0 ] + then + echo "$test_07_label: valgrind detected errors" + fi + + if [ $test_08_status -ne 0 ] + then + echo "$test_08_label: valgrind detected errors" + fi + + if [ $test_09_status -ne 0 ] + then + echo "$test_09_label: valgrind detected errors" + fi + + if [ $test_10_status -ne 0 ] + then + echo "$test_10_label: valgrind detected errors" + fi + exit 1 fi diff --git a/unittest/ctlrender/CMakeLists.txt b/unittest/ctlrender/CMakeLists.txt index 4a4239a6..dd7d65d7 100644 --- a/unittest/ctlrender/CMakeLists.txt +++ b/unittest/ctlrender/CMakeLists.txt @@ -9,17 +9,24 @@ if (BASH_PROGRAM) COMMAND ${BASH_PROGRAM} ./test.sh $ ) else() - MESSAGE( STATUS "BASH not found, able to run ctlrender unit test" ) + MESSAGE( STATUS "BASH not found, not able to run ctlrender unit test" ) endif (BASH_PROGRAM) find_package(TIFF) -if ( TARGET TIFF::TIFF ) - set_property(TEST ctlrender PROPERTY ENVIRONMENT "IS_TIFF_FOUND=1") -else() - message(WARNING "LibTIFF not found, skipping tiff-related ctlrender unit tests") - set_property(TEST ctlrender PROPERTY ENVIRONMENT "IS_TIFF_FOUND=0") +if ( TARGET TIFF::TIFF AND OpenEXR_FOUND ) + message(WARNING "LibTIFF found, OpenEXR found, including TIF and EXR files in ctlrender unit tests") + set_property(TEST ctlrender PROPERTY ENVIRONMENT "IS_TIFF_FOUND=1;IS_OPENEXR_FOUND=1") +elseif( TARGET TIFF::TIFF AND NOT OpenEXR_FOUND ) + message(WARNING "LibTIFF found, OpenEXR not found, including TIF files in ctlrender unit tests") + set_property(TEST ctlrender PROPERTY ENVIRONMENT "IS_TIFF_FOUND=1;IS_OPENEXR_FOUND=0") +elseif( NOT TARGET TIFF::TIFF AND OpenEXR_FOUND ) + message(WARNING "LibTIFF not found, OpenEXR found, including EXR files in ctlrender unit tests") + set_property(TEST ctlrender PROPERTY ENVIRONMENT "IS_TIFF_FOUND=0;IS_OPENEXR_FOUND=1") +elseif( NOT TARGET TIFF::TIFF AND NOT OpenEXR_FOUND ) + message(WARNING "LibTIFF not found, OpenEXR not found, not including TIF or EXR files in ctlrender unit tests") + set_property(TEST ctlrender PROPERTY ENVIRONMENT "IS_TIFF_FOUND=0;IS_OPENEXR_FOUND=0") endif() diff --git a/unittest/ctlrender/test.sh b/unittest/ctlrender/test.sh index c7f080fa..829613ae 100755 --- a/unittest/ctlrender/test.sh +++ b/unittest/ctlrender/test.sh @@ -3,25 +3,70 @@ CTLRENDER=$1 mkdir output +printf 'printing environment variables...\n' +printenv + +printf 'printing current path...\n' +pwd + +printf 'printing directory contents...\n' +dir + +set -e + for J in tiff8 tiff16 tiff32 dpx8 dpx10 dpx12 dpx16; do + + echo ${J} unity test + for I in bars_cinepaint_10.dpx bars_nuke_10_be.dpx bars_nuke_10_le.dpx bars_nuke_12_be.dpx bars_nuke_12_le.dpx bars_nuke_16_be.dpx bars_nuke_16_le.dpx bars_nuke_8_be.dpx bars_nuke_8_le.dpx bars_photoshop_16_be_interleaved.tif bars_photoshop_16_be_planar.tif bars_photoshop_16_le_interleaved.tif bars_photoshop_16_le_planar.tif bars_photoshop_32_be_interleaved.tif bars_photoshop_32_be_planar.tif bars_photoshop_32_le_interleaved.tif bars_photoshop_32_le_planar.tif bars_photoshop_8_be_interleaved.tif bars_photoshop_8_be_planar.tif bars_photoshop_8_le_interleaved.tif bars_photoshop_8_le_planar.tif ; do name=`echo $I | sed -e 's/\..*//'` ext=`echo $J | sed -e 's/[0-9]//g'` echo ${I} '->' ${J} if [[ $IS_TIFF_FOUND == 0 ]] && [[ $J == *"tif"* ]] ; then - printf 'skipping %s because no tiff\n' $J + printf 'skipping %s because tiff support was not detected\n' $J elif [[ $IS_TIFF_FOUND == 0 ]] && [[ $I == *"tif"* ]] ; then - printf 'skipping %s because no tiff\n' $I + printf 'skipping %s because tiff support was not detected\n' $I else $CTLRENDER -ctl unity.ctl -format ${J} -force ${I} output/${name}_${J}.${ext} fi done - echo ${J} unity test - + # test TIFF32 conversions if [[ $IS_TIFF_FOUND == 1 ]] ; then + printf 'bars_photoshop_32_be_planar.tif -> output/bars_tiff32_%s.%s \n' ${J} ${ext} $CTLRENDER -ctl unity.ctl -format ${J} -force bars_photoshop_32_be_planar.tif output/bars_tiff32_${J}.${ext} + printf 'output/bars_tiff32_%s.%s -> output/bars_tiff32_%s_tiff32.tiff \n' ${J} ${ext} ${J} $CTLRENDER -ctl unity.ctl -format tiff32 -force output/bars_tiff32_${J}.${ext} output/bars_tiff32_${J}_tiff32.tiff fi done +# test EXR to EXR support +if [[ $IS_OPENEXR_FOUND == 1 ]] ; then + printf 'bars_photoshop.exr -> output/bars_exr_exr.exr \n' + $CTLRENDER -ctl unity.ctl -format exr -force bars_photoshop.exr output/bars_exr_exr.exr + printf 'bars_photoshop.exr -> output/bars_exr_exr16.exr \n' + $CTLRENDER -ctl unity.ctl -format exr16 -force bars_photoshop.exr output/bars_exr_exr16.exr + printf 'bars_photoshop.exr -> output/bars_exr_exr32.exr \n' + $CTLRENDER -ctl unity.ctl -format exr32 -force bars_photoshop.exr output/bars_exr_exr32.exr +fi + +# test TIFF32 to EXR and EXR to TIFF32 support +if [[ $IS_OPENEXR_FOUND == 1 ]] && [[ $IS_TIFF_FOUND == 1 ]] ; then + + for J in exr exr16 exr32 tiff32; do + + for I in bars_photoshop_32_be_interleaved.tif bars_photoshop_32_be_planar.tif bars_photoshop_32_le_interleaved.tif bars_photoshop_32_le_planar.tif bars_photoshop.exr; do + name=`echo $I | sed -e 's/\..*//'` + ext=`echo $J | sed -e 's/[0-9]//g'` + echo ${I} '->' ${J} + if [[ $IS_TIFF_FOUND == 0 ]] && [[ $J == *"tif"* ]] ; then + printf 'skipping %s because tiff support was not detected\n' $J + elif [[ $IS_TIFF_FOUND == 0 ]] && [[ $I == *"tif"* ]] ; then + printf 'skipping %s because tiff support was not detected\n' $I + else + $CTLRENDER -ctl unity.ctl -format ${J} -force ${I} output/${name}_${J}.${ext} + fi + + done + done +fi