chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
7 / 8
87.5%
Branches:
5 / 6
83.3%
Functions:
1 / 1
100.0%

texture/texels.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <array>
5 #include <cstddef>
6 #include <cstdint>
7 #include <cstring>
8 #include <optional>
9
10 #include "chrono_batch_render/util/span.h"
11
12 namespace chrono::batch_render {
13
14 inline constexpr std::array<char, 8> kTexelMagic = {'C', 'B', 'R', 'T', 'E', 'X', 0, 1};
15
16 struct TexelHeader {
17 std::array<char, 8> magic = kTexelMagic;
18 uint32_t width = 0;
19 uint32_t height = 0;
20 uint32_t channels = 0;
21 uint32_t floats = 0;
22 };
23
24 static_assert(sizeof(TexelHeader) == 24);
25
26 14 inline std::optional<TexelHeader> ReadTexelHeader(Span<const std::byte> bytes) {
27 14 TexelHeader header;
28
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (bytes.size() < sizeof(header)) {
29 ✗ return std::nullopt;
30 }
31
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 3 times.
14 std::memcpy(&header, bytes.data(), sizeof(header));
32
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 3 times.
14 if (header.magic != kTexelMagic) {
33 11 return std::nullopt;
34 }
35 3 return header;
36 }
37
38 }
39