Generalized serializer

This commit is contained in:
2023-12-11 06:49:24 +01:00
parent 75913b83eb
commit f1935526a7
52 changed files with 579 additions and 557 deletions
+40 -41
View File
@@ -10,6 +10,16 @@
using namespace std::literals::chrono_literals;
inline uint32_t read_be32(const void *ptr) {
auto ptr32 = (uint32_t *) ptr;
return __builtin_bswap32(ptr32[0]);
}
inline uint64_t read_be64(const void *ptr) {
auto ptr64 = (uint64_t *) ptr;
return __builtin_bswap64(ptr64[0]);
}
TEST_CASE("Bshuf_SSE", "[bitshuffle]") {
REQUIRE (bshuf_using_SSE2() == 1);
}
@@ -36,14 +46,13 @@ TEST_CASE("FrameTransformation_Raw_NoCompression" ,"") {
for (int i = 0; i < nmodules*RAW_MODULE_SIZE; i++)
input_1[i] = dist(g1);
std::vector<int16_t> output(experiment.GetPixelsNum());
for (int i = 0; i < nmodules; i++) {
REQUIRE_NOTHROW(transformation.ProcessModule(input_0.data() + i * RAW_MODULE_SIZE, i, 0));
REQUIRE_NOTHROW(transformation.ProcessModule(input_1.data() + i * RAW_MODULE_SIZE, i, 1));
}
REQUIRE(transformation.SaveCompressedImage(output.data()) == experiment.GetPixelDepth() * experiment.GetPixelsNum());
auto image = transformation.GetCompressedImage();
REQUIRE(image.size == experiment.GetPixelDepth() * experiment.GetPixelsNum());
auto output = (int16_t *) image.data;
uint32_t diff_0 = 0;
uint32_t diff_1 = 0;
@@ -76,14 +85,14 @@ TEST_CASE("FrameTransformation_Converted_NoCompression" ,"") {
for (int i = 0; i < nmodules*RAW_MODULE_SIZE; i++)
input_1[i] = dist(g1);
std::vector<int16_t> output(experiment.GetPixelsNum());
for (int i = 0; i < nmodules; i++) {
REQUIRE_NOTHROW(transformation.ProcessModule(input_0.data() + i * RAW_MODULE_SIZE, i, 0));
REQUIRE_NOTHROW(transformation.ProcessModule(input_1.data() + i * RAW_MODULE_SIZE, i, 1));
}
REQUIRE(transformation.SaveCompressedImage(output.data()) == experiment.GetPixelDepth() * experiment.GetPixelsNum());
auto image = transformation.GetCompressedImage();
REQUIRE(image.size == experiment.GetPixelDepth() * experiment.GetPixelsNum());
auto output = (int16_t *) image.data;
REQUIRE(input_0[511*1024] == output[CONVERTED_MODULE_SIZE * (2 * nmodules - 2) + 0]);
REQUIRE(input_0[511*1024+256]/2 == output[CONVERTED_MODULE_SIZE * (2 * nmodules - 2) + 258]);
@@ -134,15 +143,13 @@ TEST_CASE("FrameTransformation_Converted_bshuf_lz4" ,"") {
REQUIRE_NOTHROW(transformation.ProcessModule(input_1.data() + i * RAW_MODULE_SIZE, i, 1));
}
size_t compressed_size;
REQUIRE_NOTHROW(compressed_size = transformation.SaveCompressedImage(output_compressed.data()));
output_compressed.resize(compressed_size);
auto image = transformation.GetCompressedImage();
REQUIRE(bshuf_read_uint64_BE(output_compressed.data()) == experiment.GetPixelsNum() * experiment.GetPixelDepth());
REQUIRE(bshuf_read_uint32_BE(output_compressed.data()+8) == JFJochBitShuffleCompressor::DefaultBlockSize * experiment.GetPixelDepth());
REQUIRE(read_be64(image.data) == experiment.GetPixelsNum() * experiment.GetPixelDepth());
REQUIRE(read_be32(image.data+8) == JFJochBitShuffleCompressor::DefaultBlockSize * experiment.GetPixelDepth());
std::vector<int16_t> output;
REQUIRE_NOTHROW(JFJochDecompress(output, experiment.GetCompressionAlgorithm(), output_compressed,
std::vector<uint16_t> output;
REQUIRE_NOTHROW(JFJochDecompress(output, experiment.GetCompressionAlgorithm(), image.data, image.size,
experiment.GetPixelsNum()));
REQUIRE(input_0[511*1024] == output[CONVERTED_MODULE_SIZE * (2 * nmodules - 2) + 0]);
@@ -193,15 +200,13 @@ TEST_CASE("FrameTransformation_Converted_bshuf_zstd" ,"") {
REQUIRE_NOTHROW(transformation.ProcessModule(input_1.data() + i * RAW_MODULE_SIZE, i, 1));
}
size_t compressed_size;
REQUIRE_NOTHROW(compressed_size = transformation.SaveCompressedImage(output_compressed.data()));
auto image = transformation.GetCompressedImage();
REQUIRE(bshuf_read_uint64_BE(output_compressed.data()) == experiment.GetPixelsNum() * experiment.GetPixelDepth());
REQUIRE(bshuf_read_uint32_BE(output_compressed.data()+8) == JFJochBitShuffleCompressor::DefaultBlockSize * experiment.GetPixelDepth());
REQUIRE(read_be64(image.data) == experiment.GetPixelsNum() * experiment.GetPixelDepth());
REQUIRE(read_be32(image.data+8) == JFJochBitShuffleCompressor::DefaultBlockSize * experiment.GetPixelDepth());
output_compressed.resize(compressed_size);
std::vector<int16_t> output;
REQUIRE_NOTHROW(JFJochDecompress(output, experiment.GetCompressionAlgorithm(), output_compressed,
std::vector<uint16_t> output;
REQUIRE_NOTHROW(JFJochDecompress(output, experiment.GetCompressionAlgorithm(), image.data, image.size,
experiment.GetPixelsNum()));
REQUIRE(input_0[511*1024] == output[CONVERTED_MODULE_SIZE * (2 * nmodules - 2) + 0]);
@@ -252,15 +257,13 @@ TEST_CASE("FrameTransformation_Converted_bshuf_zstd_rle" ,"") {
REQUIRE_NOTHROW(transformation.ProcessModule(input_1.data() + i * RAW_MODULE_SIZE, i, 1));
}
size_t compressed_size;
REQUIRE_NOTHROW(compressed_size = transformation.SaveCompressedImage(output_compressed.data()));
auto image = transformation.GetCompressedImage();
REQUIRE(bshuf_read_uint64_BE(output_compressed.data()) == experiment.GetPixelsNum() * experiment.GetPixelDepth());
REQUIRE(bshuf_read_uint32_BE(output_compressed.data()+8) == JFJochBitShuffleCompressor::DefaultBlockSize * experiment.GetPixelDepth());
REQUIRE(read_be64(image.data) == experiment.GetPixelsNum() * experiment.GetPixelDepth());
REQUIRE(read_be32(image.data+8) == JFJochBitShuffleCompressor::DefaultBlockSize * experiment.GetPixelDepth());
output_compressed.resize(compressed_size);
std::vector<int16_t> output;
REQUIRE_NOTHROW(JFJochDecompress(output, experiment.GetCompressionAlgorithm(), output_compressed,
std::vector<uint16_t> output;
REQUIRE_NOTHROW(JFJochDecompress(output, experiment.GetCompressionAlgorithm(), image.data, image.size,
experiment.GetPixelsNum()));
REQUIRE(input_0[511*1024] == output[CONVERTED_MODULE_SIZE * (2 * nmodules - 2) + 0]);
@@ -314,15 +317,13 @@ TEST_CASE("FrameTransformation_Converted_bshuf_zstd_32bit" ,"") {
REQUIRE_NOTHROW(transformation.ProcessModule(input_1.data() + i * RAW_MODULE_SIZE, i, 1));
}
size_t compressed_size;
REQUIRE_NOTHROW(compressed_size = transformation.SaveCompressedImage(output_compressed.data()));
auto image = transformation.GetCompressedImage();
REQUIRE(bshuf_read_uint64_BE(output_compressed.data()) == experiment.GetPixelsNum() * experiment.GetPixelDepth());
REQUIRE(bshuf_read_uint32_BE(output_compressed.data()+8) == JFJochBitShuffleCompressor::DefaultBlockSize * experiment.GetPixelDepth());
REQUIRE(read_be64(image.data) == experiment.GetPixelsNum() * experiment.GetPixelDepth());
REQUIRE(read_be32(image.data+8) == JFJochBitShuffleCompressor::DefaultBlockSize * experiment.GetPixelDepth());
output_compressed.resize(compressed_size);
std::vector<int32_t> output;
REQUIRE_NOTHROW(JFJochDecompress(output, experiment.GetCompressionAlgorithm(), output_compressed,
std::vector<uint32_t> output;
REQUIRE_NOTHROW(JFJochDecompress(output, experiment.GetCompressionAlgorithm(), image.data, image.size,
experiment.GetPixelsNum()));
REQUIRE(input_0[511*1024] == output[CONVERTED_MODULE_SIZE * (2 * nmodules - 2) + 0]);
@@ -381,15 +382,13 @@ TEST_CASE("FrameTransformation_Converted_bshuf_zstd_unsigned_16bit" ,"") {
REQUIRE_NOTHROW(transformation.ProcessModule(input_1.data() + i * RAW_MODULE_SIZE, i, 1));
}
size_t compressed_size;
REQUIRE_NOTHROW(compressed_size = transformation.SaveCompressedImage(output_compressed.data()));
auto image = transformation.GetCompressedImage();
REQUIRE(bshuf_read_uint64_BE(output_compressed.data()) == experiment.GetPixelsNum() * experiment.GetPixelDepth());
REQUIRE(bshuf_read_uint32_BE(output_compressed.data()+8) == JFJochBitShuffleCompressor::DefaultBlockSize * experiment.GetPixelDepth());
REQUIRE(read_be64(image.data) == experiment.GetPixelsNum() * experiment.GetPixelDepth());
REQUIRE(read_be32(image.data+8) == JFJochBitShuffleCompressor::DefaultBlockSize * experiment.GetPixelDepth());
output_compressed.resize(compressed_size);
std::vector<uint16_t> output;
REQUIRE_NOTHROW(JFJochDecompress(output, experiment.GetCompressionAlgorithm(), output_compressed,
REQUIRE_NOTHROW(JFJochDecompress(output, experiment.GetCompressionAlgorithm(), image.data, image.size,
experiment.GetPixelsNum()));
REQUIRE(input_0[511*1024] == output[CONVERTED_MODULE_SIZE * (2 * nmodules - 2) + 0]);