diff --git a/czi-format/czi-parser/compression/rle.h b/czi-format/czi-parser/compression/rle.h index 461e7e04ab5e6c165db9d1caf584931e1fabc8ad..96d5f1d698af1c026d6df6408be062f3a63ee3eb 100644 --- a/czi-format/czi-parser/compression/rle.h +++ b/czi-format/czi-parser/compression/rle.h @@ -6,6 +6,11 @@ constexpr size_t MAX_LITERAL_COUNT = 255; constexpr size_t MAX_RUN_COUNT = 255; +inline float compression_ratio(float uncompressedSize, float compressedSize) +{ + return (uncompressedSize / compressedSize); +} + // Run-Length encode bytes and return compressed bytes. std::vector<byte> rle_encode(const std::vector<byte> &bytes) { diff --git a/czi-format/czi-parser/czi_file.cpp b/czi-format/czi-parser/czi_file.cpp index 981c6f16dab04ba9cc261afabf685afa14532c86..4c6854f4c8d9e079bc58513782b821d17fbe5791 100644 --- a/czi-format/czi-parser/czi_file.cpp +++ b/czi-format/czi-parser/czi_file.cpp @@ -408,3 +408,36 @@ void CziFile::dump_image_data(const std::string &baseName) const printf("Wrote %s\n", binaryFileName.c_str()); } } + +void CziFile::test_rle_encode() const +{ + float dataSize, dataZSize, rleDataSize, rleDataZSize, ratio, ratioZ; + float overall = 0; + float overallZ = 0; + for (size_t i = 0; i < subBlockDirectory.entries.size(); i++) + { + auto data = get_image_data(i, false); + auto dataZ = get_image_data(i, true); + + auto rle_data = rle_encode(data); + auto rle_dataZ = rle_encode(dataZ); + + dataSize = (float)data.size(); + dataZSize = (float)dataZ.size(); + rleDataSize = (float)rle_data.size(); + rleDataZSize = (float)rle_dataZ.size(); + + ratio = compression_ratio(dataSize, rleDataSize); + ratioZ = compression_ratio(dataZSize, rleDataZSize); + + overall += ratio; + overallZ += ratioZ; + + printf("Subblock %-3i Compression ratios: Normal: %8f Z-Ordered: %8f\n", (int)i, ratio, ratioZ); + } + float dataCount = (float)subBlockDirectory.entries.size(); + overall /= dataCount; + overallZ /= dataCount; + + printf("Overall Normal %8f Z-Ordered: %8f\n", overall, overallZ); +} \ No newline at end of file diff --git a/czi-format/czi-parser/czi_file.h b/czi-format/czi-parser/czi_file.h index 5cd7a9d4e8a80f8aabde47bc43f50ffd601acb6a..05d0a9d0df34ad9faccd263d256154d176f7586e 100644 --- a/czi-format/czi-parser/czi_file.h +++ b/czi-format/czi-parser/czi_file.h @@ -48,6 +48,8 @@ public: void extract_images(const std::string &baseName) const; // Save differences between next images, so 0x1;1x2;... void differences_between_next(const std::string baseName) const; + // Report compression ratios for images if RLE is used, also tries to do RLE in Z order. + void test_rle_encode() const; }; #include "czi_file.cpp" \ No newline at end of file diff --git a/czi-format/czi-parser/main.cpp b/czi-format/czi-parser/main.cpp index 8dc1320c38c8661789a9b2319ef02dd294e31669..9c600a6d88ded4a5a9281fe8eeaba97f67151372 100644 --- a/czi-format/czi-parser/main.cpp +++ b/czi-format/czi-parser/main.cpp @@ -25,6 +25,7 @@ int main(int argc, char **argv) bool dumpRawImageData = method == "--dump-raw-image-data"; bool dumpImageData = method == "--dump-images"; bool nextImageDiff = method == "--diff-next"; + bool testRle = method == "--rle-report"; auto name = get_filename_without_extension(cziFile); auto x = get_files_in_parent_directory(cziFile, true); @@ -39,12 +40,7 @@ int main(int argc, char **argv) parseResult.report(); else if (dumpRawImageData) { - auto zData = parseResult.get_image_data(0, true); - // auto rleEncodedData = rle_encode(zData); - // auto rleDecoded = rle_decode(rleEncodedData); - // bool same = vecUtil::vector_eq(zData, rleDecoded); - printf("Size of z-data: %lu\n", (ulong)zData.size()); - //parseResult.dump_image_data(dumpName); + parseResult.dump_image_data(dumpName); } else if (dumpImageData) { @@ -55,6 +51,10 @@ int main(int argc, char **argv) always_assert(dumpName != ""); parseResult.differences_between_next(dumpName); } + else if (testRle) + { + parseResult.test_rle_encode(); + } printf("Finished.\n");