Files
Jungfraujoch/receiver/FrameTransformation.h
T
leonarski_fandClaude Opus 4.8 c332e45a54 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>
2026-06-26 20:10:52 +02:00

30 lines
1.1 KiB
C++

// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include "../common/DiffractionExperiment.h"
#include "JFJochCompressor.h"
#include "../common/JFJochMessages.h"
#include "../fpga/pcie_driver/jfjoch_fpga.h"
class FrameTransformation {
const DiffractionExperiment& experiment;
JFJochBitShuffleCompressor compressor;
std::vector<char> precompression_buffer;
std::vector<char> compressed_buffer;
std::vector<char> err_value;
const size_t pixel_depth;
const CompressedImageMode image_mode;
public:
explicit FrameTransformation(const DiffractionExperiment &experiment);
void ProcessModule(const DeviceOutput *output, int data_stream);
void ProcessModule(const void *input, uint16_t module_number, int data_stream);
void FillNotCollectedModule(uint16_t module_number, int data_stream);
CompressedImage GetCompressedImage();
int64_t CompressImage(void *output, size_t output_size); // < 0 - error in Compression
const void *GetImage() const;
};