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/module.hpp"
13#include "../geometry/module.hpp"
14#include "../SIMD/module.hpp"
15#include "../utility/utility.hpp"
16#include "../macros.hpp"
17#include <algorithm>
18#include <bit>
19#include <array>
20
21
22
23namespace hi::inline v1 {
24
30 // Red, Green, Blue, Alpha in binary16 (native endian).
32
33public:
34 constexpr sfloat_rgba16() noexcept : v() {}
35
36 constexpr sfloat_rgba16(sfloat_rgba16 const &rhs) noexcept = default;
37 constexpr sfloat_rgba16(sfloat_rgba16 &&rhs) noexcept = default;
38 constexpr sfloat_rgba16 &operator=(sfloat_rgba16 const &rhs) noexcept = default;
39 constexpr sfloat_rgba16 &operator=(sfloat_rgba16 &&rhs) noexcept = default;
40
41 constexpr sfloat_rgba16(f16x4 const &rhs) noexcept : v(std::bit_cast<decltype(v)>(rhs)) {}
42
43 constexpr sfloat_rgba16 &operator=(f16x4 const &rhs) noexcept
44 {
45 v = std::bit_cast<decltype(v)>(rhs);
46 return *this;
47 }
48
49 constexpr explicit operator f16x4() const noexcept
50 {
51 return std::bit_cast<f16x4>(v);
52 }
53
54 constexpr sfloat_rgba16(f32x4 const &rhs) noexcept : sfloat_rgba16(static_cast<f16x4>(rhs)) {}
55
56 constexpr sfloat_rgba16 &operator=(f32x4 const &rhs) noexcept
57 {
58 return *this = static_cast<f16x4>(rhs);
59 }
60
61 constexpr sfloat_rgba16(color const &rhs) noexcept : sfloat_rgba16(static_cast<f16x4>(rhs)) {}
62
63 constexpr sfloat_rgba16 &operator=(color const &rhs) noexcept
64 {
65 return *this = static_cast<f16x4>(rhs);
66 }
67
68 constexpr explicit operator color() const noexcept
69 {
70 return color{static_cast<f16x4>(*this)};
71 }
72
73 [[nodiscard]] constexpr sfloat_rgba16(corner_radii const &rhs) noexcept : sfloat_rgba16(static_cast<f32x4>(rhs)) {}
74
75 [[nodiscard]] std::size_t hash() const noexcept
76 {
77 return hash_mix(v[0], v[1], v[2], v[3]);
78 }
79
80 [[nodiscard]] constexpr friend bool operator==(sfloat_rgba16 const &lhs, sfloat_rgba16 const &rhs) noexcept = default;
81
82 [[nodiscard]] friend sfloat_rgba16 make_transparent(sfloat_rgba16 const &rhs) noexcept
83 {
85 r.v = rhs.v;
86 std::get<3>(r.v) = 0x0000; // 0.0f
87 return r;
88 }
89};
90
91constexpr void fill(pixmap_span<sfloat_rgba16> image, f32x4 color) noexcept
92{
93 for (std::size_t y = 0; y != image.height(); ++y) {
94 hilet row = image[y];
95 for (std::size_t x = 0; x != image.width(); ++x) {
96 row[x] = color;
97 }
98 }
99}
100
102{
103 hi_assert(over.height() >= under.height());
104 hi_assert(over.width() >= under.width());
105
106 for (auto y = 0_uz; y != under.height(); ++y) {
107 hilet over_line = over[y];
108 hilet under_line = under[y];
109 for (auto x = 0_uz; x != under.width(); ++x) {
110 hilet &overPixel = over_line[x];
111 auto &underPixel = under_line[x];
112
113 underPixel = composit(static_cast<f16x4>(underPixel), static_cast<f16x4>(overPixel));
114 }
115 }
116}
117
119{
120 hi_assert(mask.height() >= under.height());
121 hi_assert(mask.width() >= under.width());
122
123 auto mask_pixel = color{1.0f, 1.0f, 1.0f, 1.0f};
124
125 for (auto y = 0_uz; y != under.height(); ++y) {
126 hilet mask_line = mask[y];
127 hilet under_line = under[y];
128 for (auto x = 0_uz; x != under.width(); ++x) {
129 hilet mask_value = mask_line[x] / 255.0f;
131
132 auto &pixel = under_line[x];
133 pixel = composit(static_cast<color>(pixel), over * mask_pixel);
134 }
135 }
136}
137
138} // namespace hi::inline v1
139
140template<>
141struct std::hash<hi::sfloat_rgba16> {
142 std::size_t operator()(hi::sfloat_rgba16 const &rhs) const noexcept
143 {
144 return rhs.hash();
145 }
146};
Defines the pixmap_span type.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
hi_export void composit(pixmap_span< sfloat_rgba16 > dst, hi::color color, graphic_path const &mask) noexcept
Composit color onto the destination image where the mask is solid.
Definition graphic_path.hpp:667
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:667
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
4 x float16 pixel format.
Definition sfloat_rgba16.hpp:29
T operator()(T... args)