mirror of
https://github.com/openharmony/third_party_meshoptimizer.git
synced 2026-07-01 09:25:03 -04:00
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:
+26
-7
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user