HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
snorm_r8.hpp
Go to the documentation of this file.
1// Copyright Take Vos 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
9#pragma once
10
11#include "../utility/utility.hpp"
12#include "../macros.hpp"
13#include <algorithm>
14#include <cmath>
15#include <bit>
16#include <cstdint>
17
18hi_export_module(hikogui.image.snorm_r8);
19
20hi_export namespace hi::inline v1 {
21
22[[nodiscard]] constexpr int8_t make_snorm_r8_value(float rhs) noexcept
23{
24 return round_cast<int8_t>(std::round(std::clamp(rhs, -1.0f, 1.0f) * 127.0f));
25}
26
31struct snorm_r8 {
32 int8_t value;
33
34 snorm_r8() = default;
35 snorm_r8(snorm_r8 const &rhs) noexcept = default;
36 snorm_r8(snorm_r8 &&rhs) noexcept = default;
37 snorm_r8 &operator=(snorm_r8 const &rhs) noexcept = default;
38 snorm_r8 &operator=(snorm_r8 &&rhs) noexcept = default;
39 ~snorm_r8() = default;
40
41 explicit snorm_r8(float rhs) noexcept : value(make_snorm_r8_value(rhs)) {}
42
43 snorm_r8 &operator=(float rhs) noexcept
44 {
45 value = make_snorm_r8_value(rhs);
46 return *this;
47 }
48
49 explicit operator float() const noexcept
50 {
51 return narrow_cast<float>(value) / 127.0f;
52 }
53};
54
55} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
1 x int8_t pixel format.
Definition snorm_r8.hpp:31
T round(T... args)