Skip to content

Commit

Permalink
Issues/0108 ctlrender exr file support (ampas#110)
Browse files Browse the repository at this point in the history
* set HAVE_OPENEXR define

* add #include <fstream> 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
  • Loading branch information
michaeldsmith authored Jan 4, 2023
1 parent 0fb587b commit c362379
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 14 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/windows_vcpkg_debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
11 changes: 10 additions & 1 deletion ctlrender/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ target_link_libraries(ctlrender
$<$<TARGET_EXISTS:OpenEXR::IlmImf>: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}" )
Expand All @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions ctlrender/exr_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
///////////////////////////////////////////////////////////////////////////

#include "exr_file.hh"
#include <fstream>

#if defined(HAVE_OPENEXR)
#include <ImfInputFile.h>
Expand All @@ -70,6 +71,13 @@ bool exr_read(const char *name, float scale, ctl::dpx::fb<float> *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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/IlmCtl/CtlTypeStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
58 changes: 56 additions & 2 deletions resources/test/scripts/run_valgrind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
19 changes: 13 additions & 6 deletions unittest/ctlrender/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@ if (BASH_PROGRAM)
COMMAND ${BASH_PROGRAM} ./test.sh $<TARGET_FILE:ctlrender>
)
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()


53 changes: 49 additions & 4 deletions unittest/ctlrender/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c362379

Please sign in to comment.