allow effort param for png encoding when palette is true

This commit is contained in:
Vaibhav Sharma 2022-02-16 16:09:13 +05:30
parent 83be955624
commit 0b6895720c
4 changed files with 11 additions and 3 deletions

View file

@ -226,7 +226,9 @@ type Options struct {
OutputICC string OutputICC string
InputICC string InputICC string
Palette bool 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 Speed int
// private fields // private fields

View file

@ -171,6 +171,9 @@ func applyDefaults(o Options, imageType ImageType) Options {
if o.Interpretation == 0 { if o.Interpretation == 0 {
o.Interpretation = InterpretationSRGB o.Interpretation = InterpretationSRGB
} }
if o.Palette {
o.Speed = 3
}
return o return o
} }

View file

@ -517,7 +517,7 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) {
case WEBP: case WEBP:
saveErr = C.vips_webpsave_bridge(tmpImage, &ptr, &length, strip, quality, lossless) saveErr = C.vips_webpsave_bridge(tmpImage, &ptr, &length, strip, quality, lossless)
case PNG: 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: case TIFF:
saveErr = C.vips_tiffsave_bridge(tmpImage, &ptr, &length) saveErr = C.vips_tiffsave_bridge(tmpImage, &ptr, &length)
case HEIF: case HEIF:

5
vips.h
View file

@ -330,14 +330,17 @@ vips_jpegsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int qual
} }
int 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) #if (VIPS_MAJOR_VERSION >= 8 && VIPS_MINOR_VERSION >= 7)
int effort = 10 - speed;
return vips_pngsave_buffer(in, buf, len, return vips_pngsave_buffer(in, buf, len,
"strip", INT_TO_GBOOLEAN(strip), "strip", INT_TO_GBOOLEAN(strip),
"compression", compression, "compression", compression,
"interlace", INT_TO_GBOOLEAN(interlace), "interlace", INT_TO_GBOOLEAN(interlace),
"filter", VIPS_FOREIGN_PNG_FILTER_ALL, "filter", VIPS_FOREIGN_PNG_FILTER_ALL,
"palette", INT_TO_GBOOLEAN(palette), "palette", INT_TO_GBOOLEAN(palette),
"Q", quality,
"effort", effort,
NULL NULL
); );
#else #else