HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
A8B8G8R8SrgbPack32.hpp
1// Copyright 2020 Pokitec
2// All rights reserved.
3
4#pragma once
5
6#include "TTauri/Foundation/R16G16B16A16SFloat.hpp"
7#include "TTauri/Foundation/sRGB.hpp"
8#include <immintrin.h>
9#include <emmintrin.h>
10#include <algorithm>
11
12namespace tt {
13
15 uint32_t v;
16
17public:
18 tt_force_inline A8B8G8R8SrgbPack32() = default;
19 tt_force_inline A8B8G8R8SrgbPack32(A8B8G8R8SrgbPack32 const &rhs) noexcept = default;
20 tt_force_inline A8B8G8R8SrgbPack32(A8B8G8R8SrgbPack32 &&rhs) noexcept = default;
21 tt_force_inline A8B8G8R8SrgbPack32 &operator=(A8B8G8R8SrgbPack32 const &rhs) noexcept = default;
22 tt_force_inline A8B8G8R8SrgbPack32 &operator=(A8B8G8R8SrgbPack32 &&rhs) noexcept = default;
23
24 //tt_force_inline A8B8G8R8SrgbPack32(vec const &rhs) noexcept {
25 //}
26
27 //tt_force_inline A8B8G8R8SrgbPack32 &operator=(vec const &rhs) noexcept {
28 // return *this;
29 //}
30
31 //operator vec () const noexcept {
32 //}
33
34 tt_force_inline A8B8G8R8SrgbPack32(uint32_t const &rhs) noexcept : v(rhs) {}
35 tt_force_inline A8B8G8R8SrgbPack32 &operator=(uint32_t const &rhs) noexcept { v = rhs; return *this; }
36 tt_force_inline operator uint32_t () noexcept { return v; }
37
38 tt_force_inline A8B8G8R8SrgbPack32(R16G16B16A16SFloat const &rhs) noexcept {
39 ttlet &rhs_v = rhs.get();
40
41 ttlet r = sRGB_linear16_to_gamma8(rhs_v[0].get());
42 ttlet g = sRGB_linear16_to_gamma8(rhs_v[1].get());
43 ttlet b = sRGB_linear16_to_gamma8(rhs_v[2].get());
44 ttlet a = static_cast<uint8_t>(std::clamp(rhs_v[3] * 255.0f, 0.0f, 255.0f));
45 v = (static_cast<uint32_t>(a) << 24) |
46 (static_cast<uint32_t>(b) << 16) |
47 (static_cast<uint32_t>(g) << 8) |
48 static_cast<uint32_t>(r);
49 }
50
51 tt_force_inline A8B8G8R8SrgbPack32 &operator=(R16G16B16A16SFloat const &rhs) noexcept {
52 ttlet &rhs_v = rhs.get();
53
54 ttlet r = sRGB_linear16_to_gamma8(rhs_v[0]);
55 ttlet g = sRGB_linear16_to_gamma8(rhs_v[1]);
56 ttlet b = sRGB_linear16_to_gamma8(rhs_v[2]);
57 ttlet a = static_cast<uint8_t>(std::clamp(rhs_v[3] * 255.0f, 0.0f, 255.0f));
58 v = (static_cast<uint32_t>(a) << 24) |
59 (static_cast<uint32_t>(b) << 16) |
60 (static_cast<uint32_t>(g) << 8) |
61 static_cast<uint32_t>(r);
62 return *this;
63 }
64
65 [[nodiscard]] tt_force_inline friend bool operator==(A8B8G8R8SrgbPack32 const &lhs, A8B8G8R8SrgbPack32 const &rhs) noexcept {
66 return lhs.v == rhs.v;
67 }
68 [[nodiscard]] tt_force_inline friend bool operator!=(A8B8G8R8SrgbPack32 const &lhs, A8B8G8R8SrgbPack32 const &rhs) noexcept {
69 return !(lhs == rhs);
70 }
71
72 [[nodiscard]] tt_force_inline friend A8B8G8R8SrgbPack32 makeTransparent(A8B8G8R8SrgbPack32 const &rhs) noexcept {
73 return {rhs.v & 0x00ffffff};
74 }
75};
76
77
78
79inline void fill(PixelMap<A8B8G8R8SrgbPack32>& dst, PixelMap<R16G16B16A16SFloat> const& src) noexcept
80{
81 tt_assert(dst.width >= src.width);
82 tt_assert(dst.height >= src.height);
83
84 for (auto rowNr = 0; rowNr < src.height; rowNr++) {
85 ttlet srcRow = src.at(rowNr);
86 auto dstRow = dst.at(rowNr);
87 for (auto columnNr = 0; columnNr < src.width; columnNr++) {
88 dstRow[columnNr] = srcRow[columnNr];
89 }
90 }
91}
92
93
94}
Definition A8B8G8R8SrgbPack32.hpp:14
A 2D canvas of pixels.
Definition PixelMap.hpp:83
Definition R16G16B16A16SFloat.hpp:15