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.
This commit is contained in:
Arseny Kapoulkine
2024-10-02 13:18:14 -07:00
parent a1c3d1e782
commit 8e4a6b476a
+26 -7
View File
@@ -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 <stride>\n", argv[0]);
fprintf(stderr, "Usage: %s <stride> [<count>]\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<unsigned char> 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<unsigned char> 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<unsigned char> 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;
}
}