Skip to content

Commit

Permalink
perf(cli): reduce libpng compression level to 6
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dbohdan committed Oct 5, 2024
1 parent 31b83ef commit 30e4621
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion hicolor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <stdio.h>

#define HICOLOR_BAYER_SIZE 8
#define HICOLOR_LIBRARY_VERSION 600
#define HICOLOR_LIBRARY_VERSION 601

/* Types. */

Expand Down

0 comments on commit 30e4621

Please sign in to comment.