Compressor: make Compress size-aware, drop frames that don't fit

JFJochBitShuffleCompressor::Compress now takes a dest_size and returns a
negative value when the compressed output would not fit, instead of writing
past the destination buffer. The check is lazy: before each block it verifies
the remaining space still covers that block's worst case (mirrored by the new
MaxCompressedBlockSize helper, consistent with MaxCompressedSize so a dest
sized to MaxCompressedSize never fails). On overflow the dest content is
undefined - no rescue.

The receiver uses this to compress directly into the writer buffer slot and
drop just the oversized frame instead of pre-reserving the full worst-case
image size next to the per-image CBOR metadata.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-26 20:10:52 +02:00
co-authored by Claude Opus 4.8
parent 5aad009cd7
commit c332e45a54
6 changed files with 53 additions and 23 deletions
+2 -2
View File
@@ -240,7 +240,7 @@ TEST_CASE("JFJochCompressor_JFJochDecompressor_ZSTD","[ZSTD]") {
std::vector<char> tmp(x.GetPixelsNum() * sizeof(int32_t) * 4 + 12);
auto tmp_size = compressor.Compress(tmp.data(), image);
auto tmp_size = compressor.Compress(tmp.data(), tmp.size(), image);
tmp.resize(tmp_size);
std::vector<int32_t> output;
@@ -262,7 +262,7 @@ TEST_CASE("JFJochCompressor_JFJochDecompressor_LZ4","[ZSTD]") {
std::vector<char> tmp(x.GetPixelsNum() * sizeof(int32_t) * 4 + 12);
auto tmp_size = compressor.Compress(tmp.data(), image);
auto tmp_size = compressor.Compress(tmp.data(), tmp.size(), image);
tmp.resize(tmp_size);
std::vector<int32_t> output;