HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
sfloat_rgba16.hpp
Go to the documentation of this file.
1// Copyright Take Vos 2020-2022.
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 "pixmap_span.hpp"
12#include "../color/color.hpp"
13#include "../geometry/geometry.hpp"
14#include "../utility/utility.hpp"
15#include "../macros.hpp"
16#include <hikocpu/hikocpu.hpp>
17#include <algorithm>
18#include <bit>
19#include <cstdint>
20#include <array>
21
22hi_export_module(hikogui.image.sfloat_rgba16);
23
24hi_export namespace hi::inline v1 {
25
31 // Red, Green, Blue, Alpha in binary16 (native endian).
33
34public:
35 constexpr sfloat_rgba16() noexcept : v() {}
36
37 constexpr sfloat_rgba16(sfloat_rgba16 const &rhs) noexcept = default;
38 constexpr sfloat_rgba16(sfloat_rgba16 &&rhs) noexcept = default;
39 constexpr sfloat_rgba16 &operator=(sfloat_rgba16 const &rhs) noexcept = default;
40 constexpr sfloat_rgba16 &operator=(sfloat_rgba16 &&rhs) noexcept = default;
41
42 constexpr sfloat_rgba16(f16x4 const &rhs) noexcept : v(std::bit_cast<decltype(v)>(rhs)) {}
43
44 constexpr sfloat_rgba16 &operator=(f16x4 const &rhs) noexcept
45 {
46 v = std::bit_cast<decltype(v)>(rhs);
47 return *this;
48 }
49
50 constexpr explicit operator f16x4() const noexcept
51 {
52 return std::bit_cast<f16x4>(v);
53 }
54
55 constexpr sfloat_rgba16(f32x4 const &rhs) noexcept : sfloat_rgba16(static_cast<f16x4>(rhs)) {}
56
57 constexpr sfloat_rgba16 &operator=(f32x4 const &rhs) noexcept
58 {
59 return *this = static_cast<f16x4>(rhs);
60 }
61
62 constexpr sfloat_rgba16(color const &rhs) noexcept : sfloat_rgba16(static_cast<f16x4>(rhs)) {}
63
64 constexpr sfloat_rgba16 &operator=(color const &rhs) noexcept
65 {
66 return *this = static_cast<f16x4>(rhs);
67 }
68
69 constexpr explicit operator color() const noexcept
70 {
71 return color{static_cast<f16x4>(*this)};
72 }
73
74 [[nodiscard]] constexpr sfloat_rgba16(corner_radii const &rhs) noexcept : sfloat_rgba16(static_cast<f32x4>(rhs)) {}
75
76 [[nodiscard]] std::size_t hash() const noexcept
77 {
78 return hash_mix(v[0], v[1], v[2], v[3]);
79 }
80
81 [[nodiscard]] constexpr friend bool operator==(sfloat_rgba16 const &lhs, sfloat_rgba16 const &rhs) noexcept = default;
82
83 [[nodiscard]] friend sfloat_rgba16 make_transparent(sfloat_rgba16 const &rhs) noexcept
84 {
86 r.v = rhs.v;
87 std::get<3>(r.v) = 0x0000; // 0.0f
88 return r;
89 }
90};
91
92constexpr void fill(pixmap_span<sfloat_rgba16> image, f32x4 color) noexcept
93{
94 for (std::size_t y = 0; y != image.height(); ++y) {
95 auto const row = image[y];
96 for (std::size_t x = 0; x != image.width(); ++x) {
97 row[x] = color;
98 }
99 }
100}
101
102} // namespace hi::inline v1
103
104template<>
105struct std::hash<hi::sfloat_rgba16> {
106 std::size_t operator()(hi::sfloat_rgba16 const &rhs) const noexcept
107 {
108 return rhs.hash();
109 }
110};
Defines the pixmap_span type.
Defined the color type.
The HikoGUI namespace.
Definition array_generic.hpp:20
constexpr void fill(pixmap_span< uint8_t > image, std::vector< bezier_curve > const &curves) noexcept
Fill a linear gray scale image by filling a curve with anti-aliasing.
Definition bezier_curve.hpp:693
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
4 x half pixel format.
Definition sfloat_rgba16.hpp:30
T operator()(T... args)