Blender V5.0
util_rgbe_test.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include <gtest/gtest.h>
6
7#include "util/log.h"
8#include "util/types_rgbe.h"
9
11
12TEST(RGBE, round_trip)
13{
14 {
15 const float3 f = make_float3(7.334898f, 5.811583f, 2.414717f);
16 EXPECT_EQ(rgbe_to_rgb(rgb_to_rgbe(f)), make_float3(7.34375f, 5.8125f, 2.40625f));
17 }
18
19 {
20 const float3 f = make_float3(0.08750992f, 0.05150064f, 0.24991725f);
21 EXPECT_EQ(rgbe_to_rgb(rgb_to_rgbe(f)), make_float3(0.087890625f, 0.05078125f, 0.25f));
22 }
23
24 {
25 const float3 f = make_float3(4e-6f, 30257.0f, 1.0f);
26 EXPECT_EQ(rgbe_to_rgb(rgb_to_rgbe(f)), make_float3(0.0f, 30208.0f, 0.0f));
27 }
28
29 {
30 const float3 f = zero_float3();
32 }
33
34 {
35 const float3 f = make_float3(5.9e-8f, 0.0f, 0.0f);
37 }
38
39 {
40 const float3 f = make_float3(6.0e-8f, 0.0f, 0.0f);
41 EXPECT_EQ(rgbe_to_rgb(rgb_to_rgbe(f)), make_float3(1.1920928955078125e-7f, 0.0f, 0.0f));
42 }
43
44 {
45 const float3 f = make_float3(-0.863880f, 0.558654f, -0.223357f);
46 EXPECT_EQ(rgbe_to_rgb(rgb_to_rgbe(f)), make_float3(-0.86328125f, 0.55859375f, -0.22265625f));
47 }
48
49 {
50 const float3 f = make_float3(-FLT_MAX, FLT_MAX, 0.0f);
51 EXPECT_EQ(rgbe_to_rgb(rgb_to_rgbe(f)), make_float3(-65280.0f, 65280.0f, 0.0f));
52 }
53
54 {
55 const float inf = __uint_as_float(0x7f800000);
56 const float3 f = make_float3(inf, 127.0f, 129.0f);
57 EXPECT_EQ(rgbe_to_rgb(rgb_to_rgbe(f)), make_float3(65280.0f, 0.0f, 256.0f));
58 }
59
60 {
61 /* No test for NaN, undefined behavior. */
62 }
63}
64
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
#define __uint_as_float(x)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
Definition math_float3.h:17
#define FLT_MAX
Definition stdcycles.h:14
ccl_device_inline float3 rgbe_to_rgb(const RGBE rgbe)
Definition types_rgbe.h:92
ccl_device RGBE rgb_to_rgbe(float3 rgb)
Definition types_rgbe.h:60
CCL_NAMESPACE_BEGIN TEST(RGBE, round_trip)