Skip to content

Commit 876797e

Browse files
Issues/0129 unittests for exr_ctl_exr (#136)
* add exr_ctl_exr unit tests, closes #129 * add valgrind tests for exr_ctl_exr * free memory used by extraAttrs, closes #135
1 parent fddefc7 commit 876797e

File tree

6 files changed

+206
-1
lines changed

6 files changed

+206
-1
lines changed

OpenEXR_CTL/exr_ctl_exr/main.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,5 +351,15 @@ main(int argc, char **argv)
351351
exitStatus = 1;
352352
}
353353

354+
// clean up dynamically allocated memory
355+
if(extraAttrs.size() > 0)
356+
{
357+
for(AttrMap::iterator it=extraAttrs.begin() ; it!=extraAttrs.end() ; it++)
358+
{
359+
delete it->second;
360+
}
361+
}
362+
extraAttrs.clear();
363+
354364
return exitStatus;
355365
}

resources/test/scripts/run_valgrind.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,21 @@ valgrind -s --error-exitcode=1 --leak-check=full --track-origins=yes --show-leak
9292
test_20_status=$?
9393
test_20_label="exrdpx-exr-to-dpx"
9494

95+
cd ../exr_ctl_exr
96+
cp ../../OpenEXR_CTL/exr_ctl_exr/*.ctl .
97+
valgrind -s --error-exitcode=1 --leak-check=full --track-origins=yes --show-leak-kinds=all ../../OpenEXR_CTL/exr_ctl_exr/exr_ctl_exr -C change_saturation ../../../unittest/exr_ctl_exr/marci-512.exr ./output/exr_ctl_exr-no-args.exr
98+
test_21_status=$?
99+
test_21_label="exr_ctl_exr"
100+
101+
valgrind -s --error-exitcode=1 --leak-check=full --track-origins=yes --show-leak-kinds=all ../../OpenEXR_CTL/exr_ctl_exr/exr_ctl_exr -C change_saturation -float sScale 1.2 ../../../unittest/exr_ctl_exr/marci-512.exr ./output/exr_ctl_exr-sScale-1.2.exr
102+
test_22_status=$?
103+
test_22_label="exr_ctl_exr-float"
104+
95105
# go back to initial path
96106
cd $SCRIPTPATH
97107

98108
# return valgrind exit codes
99-
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 ] && [ $test_11_status -eq 0 ] && [ $test_12_status -eq 0 ] && [ $test_13_status -eq 0 ] && [ $test_14_status -eq 0 ] && [ $test_15_status -eq 0 ] && [ $test_16_status -eq 0 ] && [ $test_17_status -eq 0 ] && [ $test_18_status -eq 0 ] && [ $test_19_status -eq 0 ] && [ $test_20_status -eq 0 ]
109+
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 ] && [ $test_11_status -eq 0 ] && [ $test_12_status -eq 0 ] && [ $test_13_status -eq 0 ] && [ $test_14_status -eq 0 ] && [ $test_15_status -eq 0 ] && [ $test_16_status -eq 0 ] && [ $test_17_status -eq 0 ] && [ $test_18_status -eq 0 ] && [ $test_19_status -eq 0 ] && [ $test_20_status -eq 0 ] && [ $test_21_status -eq 0 ] && [ $test_22_status -eq 0 ]
100110
then
101111
echo "Success: valgrind detected no errors"
102112
exit 0
@@ -203,5 +213,15 @@ else
203213
echo "$test_20_label: valgrind detected errors"
204214
fi
205215

216+
if [ $test_21_status -ne 0 ]
217+
then
218+
echo "$test_21_label: valgrind detected errors"
219+
fi
220+
221+
if [ $test_22_status -ne 0 ]
222+
then
223+
echo "$test_22_label: valgrind detected errors"
224+
fi
225+
206226
exit 1
207227
fi

unittest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ add_subdirectory(IlmImfCtl)
44
if (CTL_BUILD_TOOLS)
55
add_subdirectory(ctlrender)
66
add_subdirectory(exrdpx)
7+
add_subdirectory(exr_ctl_exr)
78
endif()
89

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
if(NOT DEFINED EXR_CTL_EXR_BUILD_DIR)
2+
set(EXR_CTL_EXR_BUILD_DIR "${CMAKE_BINARY_DIR}/OpenEXR_CTL/exr_ctl_exr")
3+
message("exr_ctl_exr build director: ${EXR_CTL_EXR_BUILD_DIR}")
4+
endif()
5+
6+
if(NOT DEFINED EXR_CTL_EXR_EXECUTABLE_PATH)
7+
set(EXR_CTL_EXR_EXECUTABLE_PATH "${EXR_CTL_EXR_BUILD_DIR}/exr_ctl_exr")
8+
message("exr_ctl_exr test executable: ${EXR_CTL_EXR_EXECUTABLE_PATH}")
9+
endif()
10+
11+
set(EXR_CTL_EXR_OUTPUT_FOLDER "${CMAKE_BINARY_DIR}/unittest/exr_ctl_exr/output")
12+
message("exr_ctl_exr test output folder will be created at: ${EXR_CTL_EXR_OUTPUT_FOLDER}")
13+
add_custom_target(exr-ctl-exr-build-time-make-directory ALL
14+
COMMAND ${CMAKE_COMMAND} -E make_directory ${EXR_CTL_EXR_OUTPUT_FOLDER})
15+
16+
set(TEST_FILES "${PROJECT_SOURCE_DIR}/unittest/exr_ctl_exr")
17+
18+
# copy CTL files to build folder
19+
add_custom_target(
20+
exr-ctl-exr-build-time-copy-CTL-file1 ALL
21+
COMMAND ${CMAKE_COMMAND} -E copy
22+
${TEST_FILES}/change_saturation.ctl
23+
"${EXR_CTL_EXR_BUILD_DIR}")
24+
25+
if(OpenEXR_FOUND)
26+
27+
add_test(NAME "exr-ctl-exr-noargs" COMMAND ${EXR_CTL_EXR_EXECUTABLE_PATH} -C change_saturation "${TEST_FILES}/marci-512.exr" "${EXR_CTL_EXR_OUTPUT_FOLDER}/exr-ctl-exr-noargs.exr" WORKING_DIRECTORY "${EXR_CTL_EXR_BUILD_DIR}")
28+
29+
add_test(NAME "exr-ctl-exr-t-3" COMMAND ${EXR_CTL_EXR_EXECUTABLE_PATH} -C change_saturation -t 3 "${TEST_FILES}/marci-512.exr" "${EXR_CTL_EXR_OUTPUT_FOLDER}/exr-ctl-exr-t-3.exr" WORKING_DIRECTORY "${EXR_CTL_EXR_BUILD_DIR}")
30+
31+
add_test(NAME "exr-ctl-exr-t-4" COMMAND ${EXR_CTL_EXR_EXECUTABLE_PATH} -C change_saturation -t 4 "${TEST_FILES}/marci-512.exr" "${EXR_CTL_EXR_OUTPUT_FOLDER}/exr-ctl-exr-t-4.exr" WORKING_DIRECTORY "${EXR_CTL_EXR_BUILD_DIR}")
32+
33+
add_test(NAME "exr-ctl-exr-sScale-1.0" COMMAND ${EXR_CTL_EXR_EXECUTABLE_PATH} -C change_saturation -float sScale 1.0 "${TEST_FILES}/marci-512.exr" "${EXR_CTL_EXR_OUTPUT_FOLDER}/exr-ctl-exr-sScale-1.0.exr" WORKING_DIRECTORY "${EXR_CTL_EXR_BUILD_DIR}")
34+
35+
add_test(NAME "exr-ctl-exr-sScale-1.2" COMMAND ${EXR_CTL_EXR_EXECUTABLE_PATH} -C change_saturation -float sScale 1.2 "${TEST_FILES}/marci-512.exr" "${EXR_CTL_EXR_OUTPUT_FOLDER}/exr-ctl-exr-sScale-1.2.exr" WORKING_DIRECTORY "${EXR_CTL_EXR_BUILD_DIR}")
36+
37+
add_test(NAME "exr-ctl-exr-sScale-0.8" COMMAND ${EXR_CTL_EXR_EXECUTABLE_PATH} -C change_saturation -float sScale 0.8 "${TEST_FILES}/marci-512.exr" "${EXR_CTL_EXR_OUTPUT_FOLDER}/exr-ctl-exr-sScale-0.8.exr" WORKING_DIRECTORY "${EXR_CTL_EXR_BUILD_DIR}")
38+
39+
add_test(NAME "exr-ctl-exr-sScale-1.2-adoptedNeutral-D65" COMMAND ${EXR_CTL_EXR_EXECUTABLE_PATH} -C change_saturation -float sScale 1.2 -float2 adoptedNeutral 0.31271 0.32902 "${TEST_FILES}/marci-512.exr" "${EXR_CTL_EXR_OUTPUT_FOLDER}/exr-ctl-exr-sScale-1.2-adoptedNeutral-D65.exr" WORKING_DIRECTORY "${EXR_CTL_EXR_BUILD_DIR}")
40+
41+
add_test(NAME "exr-ctl-exr-sScale-1.2-adoptedNeutral-D93" COMMAND ${EXR_CTL_EXR_EXECUTABLE_PATH} -C change_saturation -float sScale 1.2 -float2 adoptedNeutral 0.28315 0.29711 "${TEST_FILES}/marci-512.exr" "${EXR_CTL_EXR_OUTPUT_FOLDER}/exr-ctl-exr-sScale-1.2-adoptedNeutral-D93.exr" WORKING_DIRECTORY "${EXR_CTL_EXR_BUILD_DIR}")
42+
43+
endif()
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
///////////////////////////////////////////////////////////////////////////
2+
// Copyright (c) 2013 Academy of Motion Picture Arts and Sciences
3+
// ("A.M.P.A.S."). Portions contributed by others as indicated.
4+
// All rights reserved.
5+
//
6+
// A worldwide, royalty-free, non-exclusive right to copy, modify, create
7+
// derivatives, and use, in source and binary forms, is hereby granted,
8+
// subject to acceptance of this license. Performance of any of the
9+
// aforementioned acts indicates acceptance to be bound by the following
10+
// terms and conditions:
11+
//
12+
// * Copies of source code, in whole or in part, must retain the
13+
// above copyright notice, this list of conditions and the
14+
// Disclaimer of Warranty.
15+
//
16+
// * Use in binary form must retain the above copyright notice,
17+
// this list of conditions and the Disclaimer of Warranty in the
18+
// documentation and/or other materials provided with the distribution.
19+
//
20+
// * Nothing in this license shall be deemed to grant any rights to
21+
// trademarks, copyrights, patents, trade secrets or any other
22+
// intellectual property of A.M.P.A.S. or any contributors, except
23+
// as expressly stated herein.
24+
//
25+
// * Neither the name "A.M.P.A.S." nor the name of any other
26+
// contributors to this software may be used to endorse or promote
27+
// products derivative of or based on this software without express
28+
// prior written permission of A.M.P.A.S. or the contributors, as
29+
// appropriate.
30+
//
31+
// This license shall be construed pursuant to the laws of the State of
32+
// California, and any disputes related thereto shall be subject to the
33+
// jurisdiction of the courts therein.
34+
//
35+
// Disclaimer of Warranty: THIS SOFTWARE IS PROVIDED BY A.M.P.A.S. AND
36+
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
37+
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
38+
// FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE DISCLAIMED. IN NO
39+
// EVENT SHALL A.M.P.A.S., OR ANY CONTRIBUTORS OR DISTRIBUTORS, BE LIABLE
40+
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, RESITUTIONARY,
41+
// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
42+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
43+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
44+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
46+
// THE POSSIBILITY OF SUCH DAMAGE.
47+
//
48+
// WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE ACADEMY
49+
// SPECIFICALLY DISCLAIMS ANY REPRESENTATIONS OR WARRANTIES WHATSOEVER
50+
// RELATED TO PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS IN THE ACADEMY
51+
// COLOR ENCODING SYSTEM, OR APPLICATIONS THEREOF, HELD BY PARTIES OTHER
52+
// THAN A.M.P.A.S., WHETHER DISCLOSED OR UNDISCLOSED.
53+
///////////////////////////////////////////////////////////////////////////
54+
55+
//
56+
// Function change_saturation() saturates or desaturates an RGB image by
57+
// converting the pixels to CIELAB, multiplying the a* and b* components
58+
// by a caller-supplied factor, sScale, and converting back to RGB.
59+
//
60+
// Parameters:
61+
//
62+
// R, G, B Input pixel value
63+
//
64+
// ROut, GOut, BOut Output pixel value
65+
//
66+
// sScale Saturation scale factor:
67+
// sScale > 1 increases saturation,
68+
// 0 <= sScale < 1 decreases saturation,
69+
//
70+
// chromaticities CIE (x,y) coordinates of the primaries
71+
// and white point for the input and output
72+
// pixels
73+
//
74+
// whiteLuminance Luminance of pixels with R = G = B = 1
75+
//
76+
// adoptedNeutral CIE (x,y) coordinates of the white stimulus
77+
// for RGB-to-LAB and LAB-to-RGB conversion.
78+
// Decreasing or increasing saturation makes
79+
// the pixel colors move towards or away from
80+
// the adoptedNeutral value.
81+
//
82+
83+
void
84+
change_saturation
85+
(output varying half ROut,
86+
output varying half GOut,
87+
output varying half BOut,
88+
varying half R,
89+
varying half G,
90+
varying half B,
91+
float adoptedNeutral[2],
92+
Chromaticities chromaticities,
93+
float whiteLuminance = 1.0,
94+
float sScale = 1.0)
95+
{
96+
//
97+
// Compute the XYZ coordinates of the white stimulus.
98+
//
99+
100+
float XYZn[3];
101+
XYZn[0] = adoptedNeutral[0] * whiteLuminance / adoptedNeutral[1];
102+
XYZn[1] = whiteLuminance;
103+
XYZn[2] = whiteLuminance / adoptedNeutral[1] - XYZn[0] - whiteLuminance;
104+
105+
//
106+
// Convert input RGB value first to XYZ, then to LAB
107+
//
108+
109+
float toXYZ[4][4] = RGBtoXYZ (chromaticities, whiteLuminance);
110+
float RGB[3] = {R, G, B};
111+
float XYZ[3] = mult_f3_f44 (RGB, toXYZ);
112+
float Lab[3] = XYZtoLab (XYZ, XYZn);
113+
114+
//
115+
// Change saturation by scaling the a* and b* coordinates.
116+
//
117+
118+
Lab[1] = Lab[1] * sScale;
119+
Lab[2] = Lab[2] * sScale;
120+
121+
//
122+
// Convert back to XYZ and then to RGB
123+
//
124+
125+
XYZ = LabtoXYZ (Lab, XYZn);
126+
float toRGB[4][4] = XYZtoRGB (chromaticities, whiteLuminance);
127+
RGB = mult_f3_f44 (XYZ, toRGB);
128+
ROut = RGB[0];
129+
GOut = RGB[1];
130+
BOut = RGB[2];
131+
}

unittest/exr_ctl_exr/marci-512.exr

496 KB
Binary file not shown.

0 commit comments

Comments
 (0)