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
15
16
17namespace hi::inline v1 {
18
19[[nodiscard]] constexpr int8_t make_snorm_r8_value(float rhs) noexcept
20{
21 return round_cast<int8_t>(std::round(std::clamp(rhs, -1.0f, 1.0f) * 127.0f));
22}
23
28struct snorm_r8 {
29 int8_t value;
30
31 snorm_r8() = default;
32 snorm_r8(snorm_r8 const &rhs) noexcept = default;
33 snorm_r8(snorm_r8 &&rhs) noexcept = default;
34 snorm_r8 &operator=(snorm_r8 const &rhs) noexcept = default;
35 snorm_r8 &operator=(snorm_r8 &&rhs) noexcept = default;
36 ~snorm_r8() = default;
37
38 explicit snorm_r8(float rhs) noexcept : value(make_snorm_r8_value(rhs)) {}
39
40 snorm_r8 &operator=(float rhs) noexcept
41 {
42 value = make_snorm_r8_value(rhs);
43 return *this;
44 }
45
46 explicit operator float() const noexcept
47 {
48 return narrow_cast<float>(value) / 127.0f;
49 }
50};
51
52} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:16
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
1 x int8_t pixel format.
Definition snorm_r8.hpp:28
T round(T... args)