Blender V5.3
spz_header.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "spz_header.hh"
6
7#include <fmt/format.h>
8
9#include "BLT_translation.hh"
10
11#include "IO_validate.hh"
12
13namespace blender::io::spz {
14
15template<typename Header>
16static std::optional<std::string> check_common_header_for_errors(const Header &header,
17 const uint32_t min_version,
18 const uint32_t max_version)
19{
20 if (header.magic != SPZ_HEADER_MAGIC) {
21 return fmt::format(fmt::runtime(RPT_("Unexpected SPZ header magic 0x{:X}")), header.magic);
22 }
23 if (header.version < min_version || header.version > max_version) {
24 return fmt::format(fmt::runtime(RPT_("Unsupported SPZ version {}")), header.version);
25 }
26 if (!validate::size_fits_in_int(header.num_points)) {
27 return RPT_("Too many points");
28 }
29 /* Blender supports spherical harmonics up to degree 4. */
30 if (header.sh_degree > 4) {
31 return fmt::format(fmt::runtime(RPT_("Unsupported SH degree {}")), header.sh_degree);
32 }
33 /* Match the range supported by the 24-bit fixed-point position decoder. */
34 if (header.fractional_bits >= 24) {
35 return fmt::format(fmt::runtime(RPT_("Unsupported number of position fractional bits {}")),
36 header.fractional_bits);
37 }
38 return std::nullopt;
39}
40
41std::optional<std::string> check_header_for_errors(const PackedGaussiansHeader &header)
42{
43 return check_common_header_for_errors(header, 2, 3);
44}
45
46std::optional<std::string> check_header_for_errors(const NgspFileHeader &header)
47{
48 if (const std::optional<std::string> error = check_common_header_for_errors(header, 4, 4)) {
49 return error;
50 }
51 if (header.toc_byte_offset < sizeof(NgspFileHeader)) {
52 return RPT_("TOC byte offset is less than the size of the header");
53 }
54 /* Positions, alphas, colors, scales, rotations, and spherical harmonics. */
55 if (header.num_streams < 6) {
56 return RPT_("Unexpected number of Zstd streams");
57 }
58 return std::nullopt;
59}
60
61} // namespace blender::io::spz
#define RPT_(msgid)
static std::optional< std::string > check_common_header_for_errors(const Header &header, const uint32_t min_version, const uint32_t max_version)
Definition spz_header.cc:16
std::optional< std::string > check_header_for_errors(const PackedGaussiansHeader &header)
Definition spz_header.cc:41
constexpr uint32_t SPZ_HEADER_MAGIC
Definition spz_header.hh:14
bool size_fits_in_int(const int64_t size)
unsigned int uint32_t
Definition BKE_text.h:81