12#if defined(__CUDACC__)
13 #define CUDA_PIXEL_FN __host__ __device__ inline
15 #define CUDA_PIXEL_FN inline
18namespace cuda::pixel {
32 CUDA_PIXEL_FN
rgb_t unpack(
layout_e layout, std::uint32_t word) {
35 return {((word >> 20) & 1023u) / 1023.0f, ((word >> 10) & 1023u) / 1023.0f, (word & 1023u) / 1023.0f};
37 return {(word & 1023u) / 1023.0f, ((word >> 10) & 1023u) / 1023.0f, ((word >> 20) & 1023u) / 1023.0f};
40 return {((word >> 16) & 255u) / 255.0f, ((word >> 8) & 255u) / 255.0f, (word & 255u) / 255.0f};
45 return {a.r + (b.r - a.r) * t, a.g + (b.g - a.g) * t, a.b + (b.b - a.b) * t};
49 return {(a.r + b.r + c.r + d.r) * 0.25f, (a.g + b.g + c.g + d.g) * 0.25f, (a.b + b.b + c.b + d.b) * 0.25f};
67 CUDA_PIXEL_FN
float encode(
const vec4_t &vec,
rgb_t p) {
68 return p.r * vec.x + p.g * vec.y + p.b * vec.z + vec.w;
72 CUDA_PIXEL_FN std::uint32_t
quantize(
float value, std::uint32_t max_code) {
73 if (!(value > 0.0f)) {
76 if (value >=
static_cast<float>(max_code)) {
79 return static_cast<std::uint32_t
>(value);
83 template<
class sample_t>
84 CUDA_PIXEL_FN sample_t
store(std::uint32_t code);
88 return static_cast<std::uint8_t
>(code);
92 CUDA_PIXEL_FN std::uint16_t store<std::uint16_t>(std::uint32_t code) {
93 return static_cast<std::uint16_t
>(code << 6);
std::uint32_t quantize(float value, std::uint32_t max_code)
Truncate a rounded code value into [0, max_code]; NaN becomes 0.
sample_t store(std::uint32_t code)
A sample as stored in the plane: 8-bit codes as they are, P010 codes in bits 15:6.
layout_e
How the 32-bit little-endian words of a CPU-copied frame hold their channels.
@ bgra8
DRM XRGB8888 / ARGB8888: bytes B, G, R, X.
@ bgr10
DRM XBGR2101010 / ABGR2101010: B in bits 29:20, G in 19:10, R in 9:0.
@ rgb10
DRM XRGB2101010 / ARGB2101010: R in bits 29:20, G in 19:10, B in 9:0.
Layout-compatible with video::color_t.
Colour channels normalized to [0, 1].