Tune deflate

tight-png
Andri Yngvason 2019-10-12 16:42:59 +00:00
parent 007578052c
commit 6dec7287f7
2 changed files with 19 additions and 2 deletions

View File

@ -69,7 +69,11 @@ int run_benchmark(const char *image)
z_stream zs = { 0 };
deflateInit(&zs, Z_DEFAULT_COMPRESSION);
deflateInit2(&zs, /* compression level: */ 1,
/* method: */ Z_DEFLATED,
/* window bits: */ 15,
/* mem level: */ 9,
/* strategy: */ Z_DEFAULT_STRATEGY);
void *dummy = malloc(width * height * 4);
if (!dummy)
@ -92,6 +96,12 @@ int run_benchmark(const char *image)
printf("Encoding %s took %"PRIu64" micro seconds\n", image,
end_time - start_time);
double orig_size = width * height * 4;
double compressed_size = frame.len;
double reduction = (orig_size - compressed_size) / orig_size;
printf("Size reduction: %.1f %%\n", reduction * 100.0);
deflateEnd(&zs);
if (rc < 0)

View File

@ -748,7 +748,14 @@ static void on_connection(uv_stream_t *server_stream, int status)
client->ref = 1;
client->server = server;
if (deflateInit(&client->z_stream, Z_BEST_SPEED) != Z_OK) {
int rc = deflateInit2(&client->z_stream,
/* compression level: */ 1,
/* method: */ Z_DEFLATED,
/* window bits: */ 15,
/* mem level: */ 9,
/* strategy: */ Z_DEFAULT_STRATEGY);
if (rc != Z_OK) {
free(client);
return;
}