v1.0.0-rc.36
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "tinycbor/cbor.h"
|
||||
#include "CborErr.h"
|
||||
#include "CborUtil.h"
|
||||
#include "../compression/JFJochCompressor.h"
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
inline void CBOR_ENC(CborEncoder &encoder, const char* key, const char* value) {
|
||||
@@ -277,6 +278,36 @@ inline void CBOR_ENC(CborEncoder &encoder, const char* key, const std::map<std::
|
||||
cborErr(cbor_encoder_close_container(&encoder, &mapEncoder));
|
||||
}
|
||||
|
||||
inline void CBOR_ENC_PIXEL_MASK(CborEncoder &encoder, const StartMessage &msg) {
|
||||
if (msg.pixel_mask.empty())
|
||||
return;
|
||||
|
||||
CborEncoder mapEncoder;
|
||||
|
||||
cborErr(cbor_encode_text_stringz(&encoder, "pixel_mask"));
|
||||
cborErr(cbor_encoder_create_map(&encoder, &mapEncoder, msg.pixel_mask.size()));
|
||||
for (const auto &[key, value]: msg.pixel_mask) {
|
||||
if (value.size() != msg.image_size_x * msg.image_size_y)
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
||||
"Mismatch in size of pixel mask");
|
||||
|
||||
JFJochBitShuffleCompressor compressor(CompressionAlgorithm::BSHUF_LZ4);
|
||||
auto mask_compressed = compressor.Compress(value);
|
||||
CompressedImage image{
|
||||
.data = mask_compressed.data(),
|
||||
.size = mask_compressed.size(),
|
||||
.xpixel = msg.image_size_x,
|
||||
.ypixel = msg.image_size_y,
|
||||
.pixel_depth_bytes = sizeof(uint32_t),
|
||||
.pixel_is_signed = false,
|
||||
.pixel_is_float = false,
|
||||
.algorithm = CompressionAlgorithm::BSHUF_LZ4,
|
||||
.channel = key
|
||||
};
|
||||
CBOR_ENC_2D_TYPED_ARRAY(mapEncoder, image);
|
||||
}
|
||||
cborErr(cbor_encoder_close_container(&encoder, &mapEncoder));
|
||||
}
|
||||
|
||||
inline void CBOR_ENC(CborEncoder &encoder, const char* key, const UnitCell &val) {
|
||||
CborEncoder mapEncoder;
|
||||
@@ -292,16 +323,6 @@ inline void CBOR_ENC(CborEncoder &encoder, const char* key, const UnitCell &val)
|
||||
cborErr(cbor_encoder_close_container(&encoder, &mapEncoder));
|
||||
}
|
||||
|
||||
inline void CBOR_ENC(CborEncoder &encoder, const char* key, const std::vector<CompressedImage> &v) {
|
||||
CborEncoder mapEncoder;
|
||||
|
||||
cborErr(cbor_encode_text_stringz(&encoder, key));
|
||||
cborErr(cbor_encoder_create_map(&encoder, &mapEncoder, v.size()));
|
||||
for (const auto &i: v)
|
||||
CBOR_ENC_2D_TYPED_ARRAY(mapEncoder, i);
|
||||
cborErr(cbor_encoder_close_container(&encoder, &mapEncoder));
|
||||
}
|
||||
|
||||
inline nlohmann::json CBOR_ENC_ROI_CONFIG(const std::vector<ROIConfig> &roi) {
|
||||
nlohmann::json j;
|
||||
for (const auto &r: roi) {
|
||||
@@ -372,8 +393,8 @@ inline void CBOR_ENC_START_USER_DATA(CborEncoder& encoder, const char* key,
|
||||
j["overwrite"] = message.overwrite.value();
|
||||
if (message.xfel_pulse_id.has_value())
|
||||
j["xfel_pulse_id"] = message.xfel_pulse_id.value();
|
||||
if (message.hdf5_format_version.has_value())
|
||||
j["hdf5_format_version"] = static_cast<int>(message.hdf5_format_version.value());
|
||||
if (message.file_format.has_value())
|
||||
j["file_format"] = static_cast<int>(message.file_format.value());
|
||||
auto str = j.dump();
|
||||
|
||||
CBOR_ENC(encoder, key, str);
|
||||
@@ -432,7 +453,8 @@ void CBORStream2Serializer::SerializeSequenceStart(const StartMessage& message)
|
||||
CBOR_ENC(mapEncoder, "jungfrau_conversion_factor", message.jungfrau_conversion_factor);
|
||||
CBOR_ENC(mapEncoder, "geometry_transformation_enabled", message.geometry_transformation_enabled);
|
||||
|
||||
CBOR_ENC(mapEncoder, "pixel_mask", message.pixel_mask);
|
||||
CBOR_ENC_PIXEL_MASK(mapEncoder, message);
|
||||
|
||||
CBOR_ENC(mapEncoder, "channels", message.channels);
|
||||
CBOR_ENC(mapEncoder, "max_spot_count", message.max_spot_count);
|
||||
|
||||
@@ -521,6 +543,7 @@ void CBORStream2Serializer::SerializeImageInternal(CborEncoder &mapEncoder, cons
|
||||
CBOR_ENC(mapEncoder, "strong_pixel_count", message.strong_pixel_count);
|
||||
CBOR_ENC(mapEncoder, "min_viable_pixel_value", message.min_viable_pixel_value);
|
||||
CBOR_ENC(mapEncoder, "max_viable_pixel_value", message.max_viable_pixel_value);
|
||||
CBOR_ENC(mapEncoder, "resolution_estimate", message.resolution_estimate);
|
||||
CBOR_ENC(mapEncoder, "data_collection_efficiency", message.image_collection_efficiency);
|
||||
CBOR_ENC(mapEncoder, "packets_expected", message.packets_expected);
|
||||
CBOR_ENC(mapEncoder, "packets_received", message.packets_received);
|
||||
|
||||
Reference in New Issue
Block a user