Loading...
Searching...
No Matches
PackedBitfield.hpp
Go to the documentation of this file.
1#pragma once
2
24#include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
25#include <Gfx/Graph/decoders/RGBA.hpp>
26
27#include <QString>
28
29namespace score::gfx
30{
31
34{
35 int offset{};
36 int width{};
37};
38
40{
42 bool bigEndian{false};
43 BitField r, g, b, a;
44};
45
52{
53 QString word;
54 if(l.containerBytes == 1)
55 {
56 word = "uint(tex.r * 255.0 + 0.5)";
57 }
58 else
59 {
60 // tex.r is the first byte in memory, tex.g the second.
61 word = l.bigEndian
62 ? "(uint(tex.r * 255.0 + 0.5) << 8) | uint(tex.g * 255.0 + 0.5)"
63 : "(uint(tex.g * 255.0 + 0.5) << 8) | uint(tex.r * 255.0 + 0.5)";
64 }
65
66 auto chan = [](const BitField& f) -> QString {
67 if(f.width <= 0)
68 return "1.0";
69 const unsigned mask = (1u << f.width) - 1u;
70 return QString("float((w >> %1) & %2u) / %3.0")
71 .arg(f.offset)
72 .arg(mask)
73 .arg(mask);
74 };
75
76 return QString("uint w = %1;"
77 "processed.rgba = vec4(%2, %3, %4, %5);")
78 .arg(word)
79 .arg(chan(l.r))
80 .arg(chan(l.g))
81 .arg(chan(l.b))
82 .arg(chan(l.a));
83}
84
86inline std::unique_ptr<GPUVideoDecoder>
88{
89 return std::make_unique<PackedDecoder>(
90 l.containerBytes == 1 ? QRhiTexture::R8 : QRhiTexture::RG8,
91 l.containerBytes, d, packedBitfieldFilter(l), /*invertY=*/false,
92 /*nearest=*/true);
93}
94
95} // namespace score::gfx
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
QString packedBitfieldFilter(const PackedBitfieldLayout &l)
Definition PackedBitfield.hpp:51
std::unique_ptr< GPUVideoDecoder > makePackedBitfieldDecoder(const PackedBitfieldLayout &l, Video::ImageFormat &d)
Convenience: the decoder for a packed-bitfield format.
Definition PackedBitfield.hpp:87
Definition VideoInterface.hpp:26
One channel's placement inside the packed container.
Definition PackedBitfield.hpp:34
int width
Bit count; 0 means "channel absent, use 1.0".
Definition PackedBitfield.hpp:36
int offset
LSB position within the reassembled word.
Definition PackedBitfield.hpp:35
Definition PackedBitfield.hpp:40
int containerBytes
1 or 2.
Definition PackedBitfield.hpp:41
bool bigEndian
Byte order of the container, not the host's.
Definition PackedBitfield.hpp:42