From 8e4a6b476abbcff3e4764aff297f9d6eb0bca4bc Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Wed, 2 Oct 2024 13:18:14 -0700 Subject: [PATCH] tools: Add decompression mode to codectest When the vertex count is specified, instead of compressing the input we decompress it; it's also possible to pipe the output through codectest again to re-compress it. This makes it easier to experiment with already-compressed data, including intermediate measurements with other compresors and prefiltering. --- tools/codectest.cpp | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/tools/codectest.cpp b/tools/codectest.cpp index 1f1116ba..cebc2b05 100644 --- a/tools/codectest.cpp +++ b/tools/codectest.cpp @@ -17,9 +17,9 @@ int main(int argc, char** argv) _setmode(_fileno(stdout), _O_BINARY); #endif - if (argc != 2 || atoi(argv[1]) <= 0) + if (argc < 2 || argc > 3 || atoi(argv[1]) <= 0) { - fprintf(stderr, "Usage: %s \n", argv[0]); + fprintf(stderr, "Usage: %s []\n", argv[0]); return 1; } @@ -32,10 +32,29 @@ int main(int argc, char** argv) while ((bytes_read = fread(buffer, 1, sizeof(buffer), stdin)) > 0) input.insert(input.end(), buffer, buffer + bytes_read); - size_t vertex_count = input.size() / stride; - std::vector output(meshopt_encodeVertexBufferBound(vertex_count, stride)); - size_t output_size = meshopt_encodeVertexBuffer(output.data(), output.size(), input.data(), vertex_count, stride); + if (argc == 3) + { + // if count is specified, we assume input is meshopt-encoded and decode it first + size_t count = atoi(argv[2]); - fwrite(output.data(), 1, output_size, stdout); - return 0; + std::vector decoded(count * stride); + int res = meshopt_decodeVertexBuffer(&decoded[0], count, stride, &input[0], input.size()); + if (res != 0) + { + fprintf(stderr, "Error decoding input: %d\n", res); + return 2; + } + + fwrite(decoded.data(), 1, decoded.size(), stdout); + return 0; + } + else + { + size_t vertex_count = input.size() / stride; + std::vector output(meshopt_encodeVertexBufferBound(vertex_count, stride)); + size_t output_size = meshopt_encodeVertexBuffer(output.data(), output.size(), input.data(), vertex_count, stride); + + fwrite(output.data(), 1, output_size, stdout); + return 0; + } }