LibGfx/PNGWriter: Change default PNG compression level to Default

The numbers in the previous commit show that going from n = 2 to
n = 3 comes with a big cost in runtime (3-4 times as long) for a
very modest to modest size win (0.5% to 2.5%). The jumps from n = 0
to n = 1 and from n = 1 to n = 2 look much more reasonable.

If image size is the main concern, webp is a better option now.
If PNG size is a big concern, recompressing with something like
zopflipng is currently still necessary anyways.

All in all, I think Default is the better default compression level now.

This effectively reverts #14738.

Affects PNGs written by all apps in the system (PixelPaint, Mandelbrot,
LibWeb's HTMLCanvasElement png serialization, LibWeb's screenshot
feature, `shot`, SpiceAgent, Magnify, `pdf` output, `image` without
--png-compression-level flag).
This commit is contained in:
Nico Weber 2024-07-30 20:53:22 -07:00
parent fd6142eba4
commit 28af4aa4ff
2 changed files with 3 additions and 3 deletions

View file

@ -19,7 +19,7 @@ class PNGChunk;
// This is not a nested struct to work around https://llvm.org/PR36684
struct PNGWriterOptions {
Compress::ZlibCompressionLevel compression_level { Compress::ZlibCompressionLevel::Best };
Compress::ZlibCompressionLevel compression_level { Compress::ZlibCompressionLevel::Default };
// Data for the iCCP chunk.
// FIXME: Allow writing cICP, sRGB, or gAMA instead too.

View file

@ -223,7 +223,7 @@ struct Options {
StringView assign_color_profile_path;
StringView convert_color_profile_path;
bool strip_color_profile = false;
Compress::ZlibCompressionLevel png_compression_level { Compress::ZlibCompressionLevel::Best };
Compress::ZlibCompressionLevel png_compression_level { Compress::ZlibCompressionLevel::Default };
bool ppm_ascii = false;
u8 quality = 75;
unsigned webp_color_cache_bits = 6;
@ -286,7 +286,7 @@ static ErrorOr<Options> parse_options(Main::Arguments arguments)
args_parser.add_option(options.assign_color_profile_path, "Load color profile from file and assign it to output image", "assign-color-profile", {}, "FILE");
args_parser.add_option(options.convert_color_profile_path, "Load color profile from file and convert output image from current profile to loaded profile", "convert-to-color-profile", {}, "FILE");
args_parser.add_option(options.strip_color_profile, "Do not write color profile to output", "strip-color-profile", {});
auto png_compression_level = static_cast<unsigned>(Compress::ZlibCompressionLevel::Best);
auto png_compression_level = static_cast<unsigned>(Compress::ZlibCompressionLevel::Default);
args_parser.add_option(png_compression_level, "PNG compression level, in [0, 3]. Higher values take longer and produce smaller outputs. Default: 2", "png-compression-level", {}, {});
args_parser.add_option(options.ppm_ascii, "Convert to a PPM in ASCII", "ppm-ascii", {});
args_parser.add_option(options.quality, "Quality used for the JPEG encoder, the default value is 75 on a scale from 0 to 100", "quality", {}, {});