MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenColorIO / TestAntiLog

Function TestAntiLog

tests/cpu/ops/log/LogOpCPU_tests.cpp:110–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108}
109
110void TestAntiLog(float logBase)
111{
112 const float rgbaImage[32] = { 0.0367126f, 0.5f, 1.f, 0.f,
113 0.2f, 0.f, .99f, 128.f,
114 qnan, qnan, qnan, 0.f,
115 0.f, 0.f, 0.f, qnan,
116 inf, inf, inf, 0.f,
117 0.f, 0.f, 0.f, inf,
118 -inf, -inf, -inf, 0.f,
119 0.f, 0.f, 0.f, -inf };
120
121 float rgba[32] = {};
122
123 OCIO::ConstLogOpDataRcPtr logOp = std::make_shared<OCIO::LogOpData>(
124 logBase, OCIO::TRANSFORM_DIR_INVERSE);
125
126 OCIO::ConstOpCPURcPtr pRenderer = OCIO::GetLogRenderer(logOp, true);
127 pRenderer->apply(rgbaImage, rgba, 8);
128
129 // Relative error tolerance for the log2 approximation.
130 const float rtol = powf(2.f, -14.f);
131
132 for (unsigned i = 0; i < 8; ++i)
133 {
134 const bool isAlpha = (i % 4 == 3);
135
136 const float result = rgba[i];
137 float expected = rgbaImage[i];
138 if (!isAlpha)
139 {
140 expected = powf(logBase, expected);
141 }
142
143 // LogOpCPU implementation uses optimized logarithm approximation
144 // cannot use strict comparison.
145 // Evaluating output for input rgbaImage[0-7] = { 0.0367126f, 0.5f, 1.f, 0.f,
146 // 0.2f, 0.f, .99f, 128.f,
147 // ... }
148 OCIO_CHECK_ASSERT(OCIO::EqualWithSafeRelError(result, expected, rtol, 1.0f));
149 }
150
151 // Evaluating output for input rgbaImage[8-11] = {qnan, qnan, qnan, 0.}.
152 OCIO_CHECK_ASSERT(OCIO::IsNan(rgba[8]));
153 OCIO_CHECK_EQUAL(rgba[11], 0.0f);
154
155 // Evaluating output for input rgbaImage[12-15] = {0., 0., 0., qnan.}.
156 OCIO_CHECK_CLOSE(rgba[12], 1.0f, rtol);
157 OCIO_CHECK_ASSERT(OCIO::IsNan(rgba[15]));
158
159 // Evaluating output for input rgbaImage[16-19] = {inf, inf, inf, 0.}.
160 OCIO_CHECK_EQUAL(rgba[16], inf);
161 OCIO_CHECK_EQUAL(rgba[19], 0.0f);
162
163 // Evaluating output for input rgbaImage[20-23] = {0., 0., 0., inf}.
164 OCIO_CHECK_CLOSE(rgba[20], 1.0f, rtol);
165 OCIO_CHECK_EQUAL(rgba[23], inf);
166
167 // Evaluating output for input rgbaImage[24-27] = {-inf, -inf, -inf, 0.}.

Callers 1

OCIO_ADD_TESTFunction · 0.85

Calls 4

GetLogRendererFunction · 0.85
EqualWithSafeRelErrorFunction · 0.85
IsNanFunction · 0.85
applyMethod · 0.45

Tested by

no test coverage detected