Skip to content

Commit

Permalink
test: add test infrastructure for cpp decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
william-silversmith committed Aug 10, 2022
1 parent c8b5325 commit 901eeac
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
Binary file added cpp/test/0-128_0-128_0-10
Binary file not shown.
2 changes: 2 additions & 0 deletions cpp/test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
g++ -lzfp -Izfp-1.0.0/include -std=c++14 main.cpp -o test
Binary file added cpp/test/libzfp.a
Binary file not shown.
42 changes: 42 additions & 0 deletions cpp/test/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "zfp.hpp"
#include "zfpc.hpp"
#include <cstdio>


#include <fstream>
#include <sstream>
#include <string>

std::string slurp(const char *filename) {
std::ifstream in;
in.open(filename, std::ifstream::in | std::ifstream::binary);
std::stringstream sstr;
sstr << in.rdbuf();
in.close();
return sstr.str();
}


int main () {
std::string data = slurp("/Users/wms/code/zfpc/wasm/0-128_0-128_0-10");


size_t voxels = 128 * 128 * 10 * 2;
float* out = new float[voxels]();
const unsigned char* ptr = reinterpret_cast<unsigned char*>(const_cast<char*>(data.c_str()));

int err = zfpc::decompress(ptr, data.size(), out, voxels * 4);

std::ofstream f;
f.open("/Users/wms/code/zfpc/wasm/0-128_0-128_0-10.raw");

unsigned char* outc = reinterpret_cast<unsigned char*>(out);

for (int i = 0; i < voxels * 4; i++) {
f << outc[i];
}

f.close();

return 0;
}
9 changes: 9 additions & 0 deletions cpp/test/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import numpy as np
from cloudvolume import view
import zfpy

data = open("0-128_0-128_0-10-1.zfp", "rb").read()
img = zfpy.decompress_numpy(data)

print(img)
view(img, port=8081)

0 comments on commit 901eeac

Please sign in to comment.