From 30e462180a7387ba191f36fe439323535850064f Mon Sep 17 00:00:00 2001 From: "D. Bohdan" Date: Sat, 5 Oct 2024 10:10:10 +0000 Subject: [PATCH] perf(cli): reduce libpng compression level to 6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit zlib compression hits heavy diminishing returns after level 6 according to benchmarks like https://aws.amazon.com/blogs/opensource/improving-zlib-cloudflare-and-comparing-performance-with-other-zlib-forks/ and https://facebook.github.io/zstd/. Compression at level 7–9 keeps getting slower with little impact on size. HiColor currently uses 9. zlib will not match OptiPNG and Oxipng in any case. Let's use level 6 to recover the performance of v0.5.0. v0.6.1 --- README.md | 2 +- cli.c | 3 ++- hicolor.h | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5164822..2c83bb9 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ Use `quantize` to create high-color images readable by other programs. `info` prints information about a HiColor file: version (`5` for 15-bit or `6` for 16), width, and height. ```none -HiColor 0.6.0 +HiColor 0.6.1 Create 15/16-bit color RGB images. usage: diff --git a/cli.c b/cli.c index eb7fce3..5150134 100644 --- a/cli.c +++ b/cli.c @@ -16,6 +16,7 @@ #define HICOLOR_CLI_ERROR "error: " #define HICOLOR_CLI_LIB_NAME_FORMAT "%-9s" +#define HICOLOR_CLI_LIBPNG_COMPRESSION_LEVEL 6 #define HICOLOR_CLI_NO_MEMORY_EXIT_CODE 255 #define HICOLOR_CLI_CMD_ENCODE "encode" @@ -197,7 +198,7 @@ bool save_png( PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT ); - png_set_compression_level(png, 9); + png_set_compression_level(png, HICOLOR_CLI_LIBPNG_COMPRESSION_LEVEL); png_write_info(png, info); png_bytep row = malloc(png_get_rowbytes(png, info)); diff --git a/hicolor.h b/hicolor.h index e356924..27fa86e 100644 --- a/hicolor.h +++ b/hicolor.h @@ -19,7 +19,7 @@ #include #define HICOLOR_BAYER_SIZE 8 -#define HICOLOR_LIBRARY_VERSION 600 +#define HICOLOR_LIBRARY_VERSION 601 /* Types. */