From 0b6895720cfed35493f3cd88408175ba8f75b77e Mon Sep 17 00:00:00 2001 From: Vaibhav Sharma Date: Wed, 16 Feb 2022 16:09:13 +0530 Subject: [PATCH 1/2] allow effort param for png encoding when palette is true --- options.go | 4 +++- resizer.go | 3 +++ vips.go | 2 +- vips.h | 5 ++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/options.go b/options.go index 9a4d5ae..93a40bd 100644 --- a/options.go +++ b/options.go @@ -226,7 +226,9 @@ type Options struct { OutputICC string InputICC string Palette bool - // Speed defines the AVIF encoders CPU effort. Valid values are 0-8. + // Speed defines the AVIF encoders CPU effort. Valid values are: + // 0-8 for AVIF encoding. + // 0-9 for PNG encoding. Speed int // private fields diff --git a/resizer.go b/resizer.go index ef1abfc..6aa0de3 100644 --- a/resizer.go +++ b/resizer.go @@ -171,6 +171,9 @@ func applyDefaults(o Options, imageType ImageType) Options { if o.Interpretation == 0 { o.Interpretation = InterpretationSRGB } + if o.Palette { + o.Speed = 3 + } return o } diff --git a/vips.go b/vips.go index 906a935..5b8067a 100644 --- a/vips.go +++ b/vips.go @@ -517,7 +517,7 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) { case WEBP: saveErr = C.vips_webpsave_bridge(tmpImage, &ptr, &length, strip, quality, lossless) case PNG: - saveErr = C.vips_pngsave_bridge(tmpImage, &ptr, &length, strip, C.int(o.Compression), quality, interlace, palette) + saveErr = C.vips_pngsave_bridge(tmpImage, &ptr, &length, strip, C.int(o.Compression), quality, interlace, palette, speed) case TIFF: saveErr = C.vips_tiffsave_bridge(tmpImage, &ptr, &length) case HEIF: diff --git a/vips.h b/vips.h index ab2c82e..e4ee4ca 100644 --- a/vips.h +++ b/vips.h @@ -330,14 +330,17 @@ vips_jpegsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int qual } int -vips_pngsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int compression, int quality, int interlace, int palette) { +vips_pngsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int compression, int quality, int interlace, int palette, int speed) { #if (VIPS_MAJOR_VERSION >= 8 && VIPS_MINOR_VERSION >= 7) + int effort = 10 - speed; return vips_pngsave_buffer(in, buf, len, "strip", INT_TO_GBOOLEAN(strip), "compression", compression, "interlace", INT_TO_GBOOLEAN(interlace), "filter", VIPS_FOREIGN_PNG_FILTER_ALL, "palette", INT_TO_GBOOLEAN(palette), + "Q", quality, + "effort", effort, NULL ); #else From ec6491c55cf987aca4302a188b3c169e64bdc201 Mon Sep 17 00:00:00 2001 From: Vaibhav Sharma Date: Wed, 16 Feb 2022 16:13:46 +0530 Subject: [PATCH 2/2] reason for speed=3 added --- resizer.go | 1 + 1 file changed, 1 insertion(+) diff --git a/resizer.go b/resizer.go index 6aa0de3..2316be2 100644 --- a/resizer.go +++ b/resizer.go @@ -172,6 +172,7 @@ func applyDefaults(o Options, imageType ImageType) Options { o.Interpretation = InterpretationSRGB } if o.Palette { + // Default value of effort in libvips is 7. o.Speed = 3 } return o