Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow effort param for png encoding when palette is true #398

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions resizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ func applyDefaults(o Options, imageType ImageType) Options {
if o.Interpretation == 0 {
o.Interpretation = InterpretationSRGB
}
if o.Palette {
// Default value of effort in libvips is 7.
o.Speed = 3
}
return o
}

Expand Down
2 changes: 1 addition & 1 deletion vips.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion vips.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down