Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
quantumbloom_tests.cpp
Go to the documentation of this file.
1/**
2 * @file quantumbloom_tests.cpp
3 * @brief Implements regression and invariant tests for quantumbloom tests.
4 * @ingroup qpe_tests
5 *
6 * Source: @c tests/quantumbloom_tests.cpp. This file is part of Quantum Phenomena Explorer (QPE),
7 * maintained by Officina Turini. See LICENSE_IT.txt / LICENSE.txt for the
8 * QPE freeware source-available terms and THIRD_PARTY_NOTICES.txt for
9 * third-party components.
10 */
11
12#include "quantumbloom_tests.h"
13
15
16#include <cmath>
17#include <sstream>
18
19namespace qpe {
20namespace tests {
21
22namespace {
23
24/**
25 * @brief Performs nearly equal.
26 * @param a The a value used by the operation.
27 * @param b The b value used by the operation.
28 * @param epsilon The epsilon value used by the operation.
29 */
30bool nearlyEqual(float a, float b, float epsilon = 1.0e-6f)
31{
32 return std::fabs(a - b) <= epsilon;
33}
34
35} // namespace
36
37/**
38 * @brief Runs quantum bloom tests.
39 * @param error Output diagnostic text on failure.
40 */
41bool runQuantumBloomTests(std::string &error)
42{
43 if (!nearlyEqual(QuantumBloom::clampStrength(-1.0f), 0.0f) ||
44 !nearlyEqual(QuantumBloom::clampStrength(2.0f), 2.0f) ||
45 !nearlyEqual(QuantumBloom::clampStrength(9.0f), 5.0f)) {
46 error = "Bloom strength clamp failed";
47 return false;
48 }
49
51 scene.r = 0.20f;
52 scene.g = 0.30f;
53 scene.b = 0.40f;
54
56 glow.r = 0.10f;
57 glow.g = 0.20f;
58 glow.b = 0.30f;
59
60 const QuantumBloomSample noBloom = QuantumBloom::combine(scene, glow, 0.0f);
61 if (!nearlyEqual(noBloom.r, scene.r) ||
62 !nearlyEqual(noBloom.g, scene.g) ||
63 !nearlyEqual(noBloom.b, scene.b)) {
64 error = "Zero-strength bloom must reproduce the scene exactly";
65 return false;
66 }
67
68 const QuantumBloomSample combined = QuantumBloom::combine(scene, glow, 1.5f);
69 if (!nearlyEqual(combined.r, 0.35f) ||
70 !nearlyEqual(combined.g, 0.60f) ||
71 !nearlyEqual(combined.b, 0.85f)) {
72 std::ostringstream stream;
73 stream << "Bloom combination failed: "
74 << combined.r << ", " << combined.g << ", " << combined.b;
75 error = stream.str();
76 return false;
77 }
78
79 // HDR values above one are intentional here; the final Step 6.5 pass tone-maps them.
80 QuantumBloomSample hotScene;
81 hotScene.r = 0.9f;
82 QuantumBloomSample hotGlow;
83 hotGlow.r = 0.8f;
84 const QuantumBloomSample hdr = QuantumBloom::combine(hotScene, hotGlow, 2.0f);
85 if (!(hdr.r > 1.0f)) {
86 error = "Bloom composition must preserve HDR values above 1.0";
87 return false;
88 }
89
90 error.clear();
91 return true;
92}
93
94} // namespace tests
95} // namespace qpe
static float clampStrength(float strength)
Performs clamp strength.
static QuantumBloomSample combine(const QuantumBloomSample &scene, const QuantumBloomSample &blurredHighlights, float strength)
Performs combine.
bool runQuantumBloomTests(std::string &error)
Runs quantum bloom tests.
Declares the quantumbloom visualization component used by QPE.
Declares regression and invariant tests for quantumbloom tests.
Data record containing Quantum Bloom Sample.