From e9a32a966d49ab798a4c6f24471669fc03adb395 Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 2 Apr 2026 11:58:24 +1300 Subject: feat: Added basic zlib compression Currently not incredibly well implemented, but it can handle fixed codes --- test/main.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test/main.cpp') diff --git a/test/main.cpp b/test/main.cpp index d4c2e64..8dc9de5 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,7 +1,9 @@ +#include #include #include #include #include +#include #include #include #include @@ -16,6 +18,40 @@ int main(int argc, char* argv[]) cout << "usage: " << argv[0] << " " << endl; return 1; } + + TehImage::ZLib encoder; + TehImage::ZLib decoder; + + const int inSize = 1000; + uint8_t in[inSize]; + for(int i = 0; i < 10; i++) + { + for(int j = 0; j < 100; j++) + { + in[i*100+j] = i; + } + } + + const int encodedSize = 1024; + uint8_t encoded[encodedSize]; + + int compressedSize = encoder.encodeData(in, inSize, encoded, encodedSize); + + // for(int i = 0; i < compressedSize; i++) + // { + // cout << std::bitset<8>(encoded[i]) << endl; + // } + + uint8_t out[inSize]; + int decodedSize = decoder.decodeData(encoded, encodedSize, out, inSize); + cout << ((memcmp(in, out, inSize) == 0)?"Pass":"Fail") << ", Size: " << compressedSize << endl; + + // for(int i = 0; i < inSize; i++) + // { + // cout << 0 + in[i] << " " << 0 + out[i] << endl; + // } + + return 0; std::string infile = argv[1]; std::string outfile = argv[2]; -- cgit v1.2.3