v1.0.0-rc.40
This commit is contained in:
@@ -85,46 +85,65 @@ inline void CBOR_ENC_2D_TYPED_ARRAY(CborEncoder &encoder, const CompressedImage&
|
||||
// throw JFJochException(JFJochExceptionCategory::CBORError, "Mismatch in array size");
|
||||
|
||||
CborEncoder arrayEncoder, arrayEncoder_2;
|
||||
cborErr(cbor_encode_text_stringz(&encoder, image.channel.c_str()));
|
||||
cborErr(cbor_encode_text_stringz(&encoder, image.GetChannel().c_str()));
|
||||
|
||||
cbor_encode_tag(&encoder, TagMultiDimArray);
|
||||
|
||||
cborErr(cbor_encoder_create_array(&encoder, &arrayEncoder, 2));
|
||||
cborErr(cbor_encoder_create_array(&arrayEncoder, &arrayEncoder_2, 2));
|
||||
cborErr(cbor_encode_uint(&arrayEncoder_2, image.ypixel));
|
||||
cborErr(cbor_encode_uint(&arrayEncoder_2, image.xpixel));
|
||||
cborErr(cbor_encoder_close_container(&arrayEncoder, &arrayEncoder_2));
|
||||
|
||||
if (image.GetMode() == CompressedImageMode::RGB) {
|
||||
cborErr(cbor_encoder_create_array(&arrayEncoder, &arrayEncoder_2, 3));
|
||||
cborErr(cbor_encode_uint(&arrayEncoder_2, 3));
|
||||
cborErr(cbor_encode_uint(&arrayEncoder_2, image.GetHeight()));
|
||||
cborErr(cbor_encode_uint(&arrayEncoder_2, image.GetWidth()));
|
||||
cborErr(cbor_encoder_close_container(&arrayEncoder, &arrayEncoder_2));
|
||||
} else {
|
||||
cborErr(cbor_encoder_create_array(&arrayEncoder, &arrayEncoder_2, 2));
|
||||
cborErr(cbor_encode_uint(&arrayEncoder_2, image.GetHeight()));
|
||||
cborErr(cbor_encode_uint(&arrayEncoder_2, image.GetWidth()));
|
||||
cborErr(cbor_encoder_close_container(&arrayEncoder, &arrayEncoder_2));
|
||||
}
|
||||
|
||||
CborTag typed_array_tag;
|
||||
|
||||
if (image.pixel_is_float) {
|
||||
if (image.pixel_depth_bytes == 4)
|
||||
typed_array_tag = TagFloatLE;
|
||||
else
|
||||
throw JFJochException(JFJochExceptionCategory::CBORError, "Array size not supported");
|
||||
} else if (image.pixel_is_signed) {
|
||||
if (image.pixel_depth_bytes == 4)
|
||||
typed_array_tag = TagSignedInt32BitLE;
|
||||
else if (image.pixel_depth_bytes == 2)
|
||||
typed_array_tag = TagSignedInt16BitLE;
|
||||
else if (image.pixel_depth_bytes == 1)
|
||||
typed_array_tag = TagSignedInt8Bit;
|
||||
else
|
||||
throw JFJochException(JFJochExceptionCategory::CBORError, "Array size not supported");
|
||||
} else {
|
||||
if (image.pixel_depth_bytes == 4)
|
||||
typed_array_tag = TagUnsignedInt32BitLE;
|
||||
else if (image.pixel_depth_bytes == 2)
|
||||
typed_array_tag = TagUnsignedInt16BitLE;
|
||||
else if (image.pixel_depth_bytes == 1)
|
||||
switch (image.GetMode()) {
|
||||
case CompressedImageMode::RGB:
|
||||
case CompressedImageMode::Uint8:
|
||||
typed_array_tag = TagUnsignedInt8Bit;
|
||||
else
|
||||
throw JFJochException(JFJochExceptionCategory::CBORError, "Array size not supported");
|
||||
break;
|
||||
case CompressedImageMode::Uint16:
|
||||
typed_array_tag = TagUnsignedInt16BitLE;
|
||||
break;
|
||||
case CompressedImageMode::Uint32:
|
||||
typed_array_tag = TagUnsignedInt32BitLE;
|
||||
break;
|
||||
case CompressedImageMode::Int8:
|
||||
typed_array_tag = TagSignedInt8Bit;
|
||||
break;
|
||||
case CompressedImageMode::Int16:
|
||||
typed_array_tag = TagSignedInt16BitLE;
|
||||
break;
|
||||
case CompressedImageMode::Int32:
|
||||
typed_array_tag = TagSignedInt32BitLE;
|
||||
break;
|
||||
case CompressedImageMode::Float16:
|
||||
typed_array_tag = TagHalfLE;
|
||||
break;
|
||||
case CompressedImageMode::Float32:
|
||||
typed_array_tag = TagFloatLE;
|
||||
break;
|
||||
case CompressedImageMode::Float64:
|
||||
typed_array_tag = TagDoubleLE;
|
||||
break;
|
||||
default:
|
||||
throw JFJochException(JFJochExceptionCategory::CBORError, "Image mode not supported");
|
||||
}
|
||||
|
||||
cbor_encode_tag(&arrayEncoder, typed_array_tag);
|
||||
|
||||
CBOR_ENC_COMPRESSED(arrayEncoder, image.data, image.size, image.algorithm, image.pixel_depth_bytes);
|
||||
CBOR_ENC_COMPRESSED(arrayEncoder, image.GetCompressed(),
|
||||
image.GetCompressedSize(), image.GetCompressionAlgorithm(),
|
||||
image.GetByteDepth());
|
||||
cborErr(cbor_encoder_close_container(&encoder, &arrayEncoder));
|
||||
}
|
||||
|
||||
@@ -189,6 +208,16 @@ inline void CBOR_ENC(CborEncoder &encoder, const SpotToSave& spot) {
|
||||
cborErr(cbor_encoder_close_container(&encoder, &mapEncoder));
|
||||
}
|
||||
|
||||
inline void CBOR_ENC(CborEncoder &encoder, const char* key, const Coord& coord) {
|
||||
CborEncoder arrayEncoder;
|
||||
cborErr(cbor_encode_text_stringz(&encoder, key));
|
||||
cborErr(cbor_encoder_create_array(&encoder, &arrayEncoder, 3));
|
||||
cborErr(cbor_encode_float(&arrayEncoder, coord[0]));
|
||||
cborErr(cbor_encode_float(&arrayEncoder, coord[1]));
|
||||
cborErr(cbor_encode_float(&arrayEncoder, coord[2]));
|
||||
cborErr(cbor_encoder_close_container(&encoder, &arrayEncoder));
|
||||
}
|
||||
|
||||
inline void CBOR_ENC(CborEncoder &encoder, const char* key, const std::vector<SpotToSave>& spots) {
|
||||
CborEncoder arrayEncoder, mapEncoder;
|
||||
|
||||
@@ -223,10 +252,26 @@ inline void CBOR_ENC_AXIS(CborEncoder &encoder, const char* key, const float det
|
||||
inline void CBOR_ENC_GONIOMETER(CborEncoder &encoder, const GoniometerAxis &g) {
|
||||
CborEncoder mapEncoder;
|
||||
|
||||
cborErr(cbor_encode_text_stringz(&encoder, g.name.c_str()));
|
||||
cborErr(cbor_encoder_create_map(&encoder, &mapEncoder, 2));
|
||||
CBOR_ENC(mapEncoder, "increment", g.increment);
|
||||
CBOR_ENC(mapEncoder, "start", g.start);
|
||||
cborErr(cbor_encode_text_stringz(&encoder, g.GetName().c_str()));
|
||||
cborErr(cbor_encoder_create_map(&encoder, &mapEncoder, CborIndefiniteLength));
|
||||
CBOR_ENC(mapEncoder, "increment", g.GetIncrement_deg());
|
||||
CBOR_ENC(mapEncoder, "start", g.GetStart_deg());
|
||||
CBOR_ENC(mapEncoder, "axis", g.GetAxis());
|
||||
if (g.GetHelicalStep().has_value())
|
||||
CBOR_ENC(mapEncoder, "helical_step", g.GetHelicalStep().value());
|
||||
cborErr(cbor_encoder_close_container(&encoder, &mapEncoder));
|
||||
}
|
||||
|
||||
inline void CBOR_ENC_GRID_SCAN(CborEncoder &encoder, const char* key, const GridScanSettings &g) {
|
||||
CborEncoder mapEncoder;
|
||||
cborErr(cbor_encode_text_stringz(&encoder, key));
|
||||
cborErr(cbor_encoder_create_map(&encoder, &mapEncoder, 6));
|
||||
CBOR_ENC(mapEncoder, "n_fast", g.GetNFast());
|
||||
CBOR_ENC(mapEncoder, "n_slow", g.GetNSlow());
|
||||
CBOR_ENC(mapEncoder, "step_x_axis", g.GetGridStepX_um() * 1e-6f);
|
||||
CBOR_ENC(mapEncoder, "step_y_axis", g.GetGridStepY_um() * 1e-6f);
|
||||
CBOR_ENC(mapEncoder, "snake_scan", g.IsSnakeScan());
|
||||
CBOR_ENC(mapEncoder, "vertical_scan", g.IsVerticalScan());
|
||||
cborErr(cbor_encoder_close_container(&encoder, &mapEncoder));
|
||||
}
|
||||
|
||||
@@ -293,17 +338,11 @@ inline void CBOR_ENC_PIXEL_MASK(CborEncoder &encoder, const StartMessage &msg) {
|
||||
|
||||
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
|
||||
};
|
||||
CompressedImage image(mask_compressed.data(), mask_compressed.size(),
|
||||
msg.image_size_x, msg.image_size_y,
|
||||
CompressedImageMode::Uint32,
|
||||
CompressionAlgorithm::BSHUF_LZ4,
|
||||
key);
|
||||
CBOR_ENC_2D_TYPED_ARRAY(mapEncoder, image);
|
||||
}
|
||||
cborErr(cbor_encoder_close_container(&encoder, &mapEncoder));
|
||||
@@ -369,7 +408,6 @@ inline void CBOR_ENC_START_USER_DATA(CborEncoder& encoder, const char* key,
|
||||
j["attenuator_transmission"] = message.attenuator_transmission.value();
|
||||
if (message.total_flux)
|
||||
j["total_flux"] = message.total_flux.value();
|
||||
j["rotation_axis"] = {message.rotation_axis[0], message.rotation_axis[1], message.rotation_axis[2]};
|
||||
j["space_group_number"] = message.space_group_number;
|
||||
|
||||
j["roi"] = CBOR_ENC_ROI_CONFIG(message.rois);
|
||||
@@ -447,7 +485,10 @@ void CBORStream2Serializer::SerializeSequenceStart(const StartMessage& message)
|
||||
CBOR_ENC(mapEncoder, "series_unique_id", message.run_name);
|
||||
CBOR_ENC(mapEncoder, "series_id", message.run_number);
|
||||
|
||||
CBOR_ENC_GONIOMETER_MAP(mapEncoder, "goniometer", message);
|
||||
if (message.goniometer)
|
||||
CBOR_ENC_GONIOMETER_MAP(mapEncoder, "goniometer", message);
|
||||
else if (message.grid_scan)
|
||||
CBOR_ENC_GRID_SCAN(mapEncoder, "grid_scan", message.grid_scan.value());
|
||||
|
||||
CBOR_ENC(mapEncoder, "jungfrau_conversion_enabled", message.jungfrau_conversion_enabled);
|
||||
CBOR_ENC(mapEncoder, "jungfrau_conversion_factor", message.jungfrau_conversion_factor);
|
||||
@@ -531,6 +572,7 @@ void CBORStream2Serializer::SerializeImageInternal(CborEncoder &mapEncoder, cons
|
||||
CBOR_ENC(mapEncoder, "indexing_result", message.indexing_result);
|
||||
if (!message.indexing_lattice.empty())
|
||||
CBOR_ENC(mapEncoder, "indexing_lattice", message.indexing_lattice);
|
||||
CBOR_ENC(mapEncoder, "indexing_time", message.indexing_time_s);
|
||||
CBOR_ENC(mapEncoder, "indexing_unit_cell", message.indexing_unit_cell);
|
||||
CBOR_ENC(mapEncoder, "xfel_pulse_id", message.xfel_pulse_id);
|
||||
CBOR_ENC(mapEncoder, "xfel_event_code", message.xfel_event_code);
|
||||
|
||||
Reference in New Issue
Block a user