1 /*-------------------------------------------------------------------------
2 * drawElements Internal Test Module
3 * ---------------------------------
5 * Copyright 2015 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief 8-bit sRGB conversion test.
22 *//*--------------------------------------------------------------------*/
24 #include "ditSRGB8ConversionTest.hpp"
26 #include "tcuFloat.hpp"
27 #include "tcuTestLog.hpp"
28 #include "tcuTextureUtil.hpp"
29 #include "tcuVectorUtil.hpp"
36 deUint32 calculateDiscreteFloatDistance (float a, float b)
38 const deUint32 au = tcu::Float32(a).bits();
39 const deUint32 bu = tcu::Float32(b).bits();
41 const bool asign = (au & (0x1u << 31u)) != 0u;
42 const bool bsign = (bu & (0x1u << 31u)) != 0u;
44 const deUint32 avalue = (au & ((0x1u << 31u) - 1u));
45 const deUint32 bvalue = (bu & ((0x1u << 31u) - 1u));
48 return avalue + bvalue + 1u;
49 else if (avalue < bvalue)
50 return bvalue - avalue;
52 return avalue - bvalue;
55 const tcu::UVec4 calculateDiscreteFloatDistance (const tcu::Vec4& ref, const tcu::Vec4& res)
57 return tcu::UVec4(calculateDiscreteFloatDistance(ref[0], res[0]), calculateDiscreteFloatDistance(ref[1], res[1]), calculateDiscreteFloatDistance(ref[2], res[2]), calculateDiscreteFloatDistance(ref[3], res[3]));
60 class SRGB8ConversionTest : public tcu::TestCase
63 SRGB8ConversionTest (tcu::TestContext& context)
64 : tcu::TestCase (context, "srgb8", "SRGB8 conversion test")
68 IterateResult iterate (void)
71 tcu::TestLog& log = m_testCtx.getLog();
73 for (int i = 0; i < 256; i++)
75 const tcu::UVec4 src (i);
76 const tcu::Vec4 res (tcu::sRGBA8ToLinear(src));
77 const tcu::Vec4 ref (tcu::sRGBToLinear(src.cast<float>() / tcu::Vec4(255.0f)));
78 const tcu::Vec4 diff (res - ref);
79 const tcu::UVec4 discreteFloatDiff (calculateDiscreteFloatDistance(ref, res));
81 if (tcu::anyNotEqual(res, ref))
82 log << tcu::TestLog::Message << i << ", Res: " << res << ", Ref: " << ref << ", Diff: " << diff << ", Discrete float diff: " << discreteFloatDiff << tcu::TestLog::EndMessage;
84 if (tcu::boolAny(tcu::greaterThan(discreteFloatDiff, tcu::UVec4(1u))))
89 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
91 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got ulp diffs greater than one.");
99 tcu::TestCase* createSRGB8ConversionTest (tcu::TestContext& context)
101 return new SRGB8ConversionTest(context);