Skip to content
Snippets Groups Projects
Commit 1b3350b0 authored by theazgra's avatar theazgra
Browse files

Added RLE test report method.

parent ed687417
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,11 @@ ...@@ -6,6 +6,11 @@
constexpr size_t MAX_LITERAL_COUNT = 255; constexpr size_t MAX_LITERAL_COUNT = 255;
constexpr size_t MAX_RUN_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. // Run-Length encode bytes and return compressed bytes.
std::vector<byte> rle_encode(const std::vector<byte> &bytes) std::vector<byte> rle_encode(const std::vector<byte> &bytes)
{ {
......
...@@ -408,3 +408,36 @@ void CziFile::dump_image_data(const std::string &baseName) const ...@@ -408,3 +408,36 @@ void CziFile::dump_image_data(const std::string &baseName) const
printf("Wrote %s\n", binaryFileName.c_str()); 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
...@@ -48,6 +48,8 @@ public: ...@@ -48,6 +48,8 @@ public:
void extract_images(const std::string &baseName) const; void extract_images(const std::string &baseName) const;
// Save differences between next images, so 0x1;1x2;... // Save differences between next images, so 0x1;1x2;...
void differences_between_next(const std::string baseName) const; 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" #include "czi_file.cpp"
\ No newline at end of file
...@@ -25,6 +25,7 @@ int main(int argc, char **argv) ...@@ -25,6 +25,7 @@ int main(int argc, char **argv)
bool dumpRawImageData = method == "--dump-raw-image-data"; bool dumpRawImageData = method == "--dump-raw-image-data";
bool dumpImageData = method == "--dump-images"; bool dumpImageData = method == "--dump-images";
bool nextImageDiff = method == "--diff-next"; bool nextImageDiff = method == "--diff-next";
bool testRle = method == "--rle-report";
auto name = get_filename_without_extension(cziFile); auto name = get_filename_without_extension(cziFile);
auto x = get_files_in_parent_directory(cziFile, true); auto x = get_files_in_parent_directory(cziFile, true);
...@@ -39,12 +40,7 @@ int main(int argc, char **argv) ...@@ -39,12 +40,7 @@ int main(int argc, char **argv)
parseResult.report(); parseResult.report();
else if (dumpRawImageData) else if (dumpRawImageData)
{ {
auto zData = parseResult.get_image_data(0, true); parseResult.dump_image_data(dumpName);
// 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);
} }
else if (dumpImageData) else if (dumpImageData)
{ {
...@@ -55,6 +51,10 @@ int main(int argc, char **argv) ...@@ -55,6 +51,10 @@ int main(int argc, char **argv)
always_assert(dumpName != ""); always_assert(dumpName != "");
parseResult.differences_between_next(dumpName); parseResult.differences_between_next(dumpName);
} }
else if (testRle)
{
parseResult.test_rle_encode();
}
printf("Finished.\n"); printf("Finished.\n");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment