summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-05-21 08:10:47 +0200
committerskal <pascal.massimino@gmail.com>2026-05-21 08:10:47 +0200
commitd806027dcaeadcdd8d2febd88bc46b2fd2c465de (patch)
tree30bc1ef9f40ccab7c00e31ee20e62bb86755fa26 /src/util
parent680042a18c11ad5e58757e45b260745c2f52417f (diff)
style: apply clang-formatHEADmain
Diffstat (limited to 'src/util')
-rw-r--r--src/util/ans.cc65
-rw-r--r--src/util/ans.h14
-rw-r--r--src/util/asset_manager.cc14
-rw-r--r--src/util/mini_math.h2
4 files changed, 54 insertions, 41 deletions
diff --git a/src/util/ans.cc b/src/util/ans.cc
index aa79e4b..779ef81 100644
--- a/src/util/ans.cc
+++ b/src/util/ans.cc
@@ -58,8 +58,7 @@ struct Stats {
// the slot. Increments the symbol's count on the fly.
void decode_lookup(uint32_t s, uint8_t* sym, uint32_t* p, uint32_t* r) {
// upper_bound(s) - 1; cumul is strictly non-decreasing.
- const uint32_t* it =
- std::upper_bound(cumul, cumul + kNumSymbols + 1, s);
+ const uint32_t* it = std::upper_bound(cumul, cumul + kNumSymbols + 1, s);
const int c = (int)(it - cumul) - 1;
stats[c] += 1;
*sym = (uint8_t)c;
@@ -97,27 +96,31 @@ inline void AppendU32BE(std::vector<uint8_t>* dst, uint32_t v) {
}
#endif
-} // namespace
+} // namespace
uint32_t PeekUncompressedSize(const uint8_t* src, size_t src_size) {
- if (!src || src_size < 4) return 0;
+ if (!src || src_size < 4)
+ return 0;
return ReadU32BE(src);
}
-bool Decode(const uint8_t* src, size_t src_size,
- uint8_t* dst, size_t dst_capacity,
- size_t* out_size,
+bool Decode(const uint8_t* src, size_t src_size, uint8_t* dst,
+ size_t dst_capacity, size_t* out_size,
const uint32_t* initial_counts) {
- if (out_size) *out_size = 0;
- if (!src || src_size < 4) return false;
+ if (out_size)
+ *out_size = 0;
+ if (!src || src_size < 4)
+ return false;
const uint8_t* p = src;
const uint8_t* end = src + src_size;
const uint32_t output_size = ReadU32BE(p);
p += 4;
- if (output_size > dst_capacity) return false;
- if (output_size > 0 && !dst) return false;
+ if (output_size > dst_capacity)
+ return false;
+ if (output_size > 0 && !dst)
+ return false;
Stats stats;
stats.init(initial_counts);
@@ -126,14 +129,16 @@ bool Decode(const uint8_t* src, size_t src_size,
while (t < output_size) {
const uint32_t chunk = std::min<uint32_t>(kChunkSize, output_size - t);
- if (end - p < 4) return false;
+ if (end - p < 4)
+ return false;
uint32_t s = ReadU32BE(p);
p += 4;
for (uint32_t i = 0; i < chunk; ++i) {
if (s <= kMask) {
// Pull in one renorm word.
- if (end - p < 2) return false;
+ if (end - p < 2)
+ return false;
s = (s << kBits) | (uint32_t)ReadU16BE(p);
p += 2;
}
@@ -144,31 +149,37 @@ bool Decode(const uint8_t* src, size_t src_size,
s = proba * (s >> kBits) + residual;
}
// Final-state sanity check: catches stream corruption and model mismatch.
- if (s != kInitState) return false;
+ if (s != kInitState)
+ return false;
stats.normalize();
t += chunk;
}
- if (out_size) *out_size = output_size;
+ if (out_size)
+ *out_size = output_size;
return true;
}
#if defined(ANS_ENABLE_ENCODER)
void Histogram(const uint8_t* src, size_t size, uint32_t* out_counts) {
- if (!src || !out_counts) return;
- for (size_t i = 0; i < size; ++i) out_counts[src[i]] += 1;
+ if (!src || !out_counts)
+ return;
+ for (size_t i = 0; i < size; ++i)
+ out_counts[src[i]] += 1;
}
-bool Encode(const uint8_t* src, size_t size,
- std::vector<uint8_t>* dst,
+bool Encode(const uint8_t* src, size_t size, std::vector<uint8_t>* dst,
const uint32_t* initial_counts) {
- if (!dst) return false;
+ if (!dst)
+ return false;
dst->clear();
- if (size > 0xffffffffu) return false; // header is u32
+ if (size > 0xffffffffu)
+ return false; // header is u32
AppendU32BE(dst, (uint32_t)size);
- if (size == 0) return true;
+ if (size == 0)
+ return true;
Stats stats;
stats.init(initial_counts);
@@ -200,9 +211,11 @@ bool Encode(const uint8_t* src, size_t size,
}
// Invariant: final state must be > kMask so the decoder's first read is
// a valid renormalized state.
- if (s <= kMask) return false;
+ if (s <= kMask)
+ return false;
AppendU32BE(dst, s);
- for (size_t k = pos; k < chunk; ++k) AppendU16BE(dst, tmp[k]);
+ for (size_t k = pos; k < chunk; ++k)
+ AppendU16BE(dst, tmp[k]);
stats.normalize();
t += chunk;
@@ -210,6 +223,6 @@ bool Encode(const uint8_t* src, size_t size,
return true;
}
-#endif // ANS_ENABLE_ENCODER
+#endif // ANS_ENABLE_ENCODER
-} // namespace ans
+} // namespace ans
diff --git a/src/util/ans.h b/src/util/ans.h
index 53c34b1..cf3d83a 100644
--- a/src/util/ans.h
+++ b/src/util/ans.h
@@ -34,25 +34,23 @@ uint32_t PeekUncompressedSize(const uint8_t* src, size_t src_size);
// 'initial_counts' (256 entries) seeds the per-chunk adaptive model; pass
// nullptr for the uniform default (all-ones).
// Returns true on success and writes the decoded size to '*out_size'.
-bool Decode(const uint8_t* src, size_t src_size,
- uint8_t* dst, size_t dst_capacity,
- size_t* out_size,
+bool Decode(const uint8_t* src, size_t src_size, uint8_t* dst,
+ size_t dst_capacity, size_t* out_size,
const uint32_t* initial_counts = nullptr);
#if defined(ANS_ENABLE_ENCODER)
// Encodes 'src[0..size]' into '*dst' (cleared and re-filled).
// 'initial_counts' has the same semantics as in Decode().
// Returns true on success.
-bool Encode(const uint8_t* src, size_t size,
- std::vector<uint8_t>* dst,
+bool Encode(const uint8_t* src, size_t size, std::vector<uint8_t>* dst,
const uint32_t* initial_counts = nullptr);
// Computes a byte histogram over 'src[0..size]', accumulating into
// 'out_counts[256]' (caller must zero-initialize before the first call).
// Useful for deriving a corpus-wide initial distribution from many files.
void Histogram(const uint8_t* src, size_t size, uint32_t* out_counts);
-#endif // ANS_ENABLE_ENCODER
+#endif // ANS_ENABLE_ENCODER
-} // namespace ans
+} // namespace ans
-#endif // ANS_H_
+#endif // ANS_H_
diff --git a/src/util/asset_manager.cc b/src/util/asset_manager.cc
index 82c07be..aef67f3 100644
--- a/src/util/asset_manager.cc
+++ b/src/util/asset_manager.cc
@@ -120,7 +120,8 @@ const uint8_t* GetAsset(AssetId asset_id, size_t* out_size) {
const size_t uncomp = source_record.uncompressed_size;
uint8_t* buffer = new (std::nothrow) uint8_t[uncomp + 1];
CHECK_RETURN_BEGIN(!buffer, nullptr)
- if (out_size) *out_size = 0;
+ if (out_size)
+ *out_size = 0;
ERROR_MSG("Failed to allocate buffer for ANS-compressed asset id=%u",
index);
return nullptr;
@@ -130,7 +131,8 @@ const uint8_t* GetAsset(AssetId asset_id, size_t* out_size) {
&got, GetAnsAsciiHistogram()) ||
got != uncomp) {
delete[] buffer;
- if (out_size) *out_size = 0;
+ if (out_size)
+ *out_size = 0;
ERROR_MSG("ANS decode failed for asset id=%u", index);
return nullptr;
}
@@ -139,7 +141,8 @@ const uint8_t* GetAsset(AssetId asset_id, size_t* out_size) {
cached_record.size = uncomp;
cached_record.uncompressed_size = uncomp;
g_asset_cache[index] = cached_record;
- if (out_size) *out_size = uncomp;
+ if (out_size)
+ *out_size = uncomp;
return buffer;
}
@@ -279,9 +282,8 @@ bool ReloadAssetsFromFile(const char* config_path) {
const AssetRecord& e = g_asset_cache[i];
if (e.data &&
(e.type == AssetType::PROC || e.type == AssetType::PROC_GPU ||
- e.compression != AssetCompression::NONE ||
- e.type == AssetType::SPEC || e.type == AssetType::MP3 ||
- e.type == AssetType::WGSL)) {
+ e.compression != AssetCompression::NONE || e.type == AssetType::SPEC ||
+ e.type == AssetType::MP3 || e.type == AssetType::WGSL)) {
delete[] e.data;
}
g_asset_cache[i] = {};
diff --git a/src/util/mini_math.h b/src/util/mini_math.h
index 0aa66a3..c386134 100644
--- a/src/util/mini_math.h
+++ b/src/util/mini_math.h
@@ -229,7 +229,7 @@ struct mat4 {
mat4 r = {};
float t = 1.0f / std::tan(fov * 0.5f);
r.m[0] = t / asp;
- r.m[5] = -t; // Negate Y: post-process chain samples textures Y-flipped
+ r.m[5] = -t; // Negate Y: post-process chain samples textures Y-flipped
r.m[10] = f / (n - f);
r.m[11] = -1;
r.m[14] = (n * f) / (n - f);