diff --git a/.travis.yml b/.travis.yml index 4391782..11b8a54 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ env: # - LIBVIPS=8.8.4 # - LIBVIPS=8.9.2 - LIBVIPS=8.10.1 + - LIBVIPS=8.10.2 matrix: allow_failures: diff --git a/options.go b/options.go index b893e97..248fbe3 100644 --- a/options.go +++ b/options.go @@ -226,6 +226,8 @@ type Options struct { OutputICC string InputICC string Palette bool + // Speed defines the AVIF encoders CPU effort. + Speed int // private fields autoRotateOnly bool diff --git a/resizer.go b/resizer.go index c9ffe5a..b4695d6 100644 --- a/resizer.go +++ b/resizer.go @@ -187,6 +187,7 @@ func saveImage(image *C.VipsImage, o Options) ([]byte, error) { StripMetadata: o.StripMetadata, Lossless: o.Lossless, Palette: o.Palette, + Speed: o.Speed, } // Finally get the resultant buffer return vipsSave(image, saveOptions) diff --git a/vips.go b/vips.go index a7a6536..f04d027 100644 --- a/vips.go +++ b/vips.go @@ -45,6 +45,7 @@ type VipsMemoryInfo struct { // vipsSaveOptions represents the internal option used to talk with libvips. type vipsSaveOptions struct { + Speed int Quality int Compression int Type ImageType @@ -493,6 +494,7 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) { strip := C.int(boolToInt(o.StripMetadata)) lossless := C.int(boolToInt(o.Lossless)) palette := C.int(boolToInt(o.Palette)) + speed := C.int(o.Speed) if o.Type != 0 && !IsTypeSupportedSave(o.Type) { return nil, fmt.Errorf("VIPS cannot save to %#v", ImageTypes[o.Type]) @@ -508,7 +510,7 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) { case HEIF: saveErr = C.vips_heifsave_bridge(tmpImage, &ptr, &length, strip, quality, lossless) case AVIF: - saveErr = C.vips_avifsave_bridge(tmpImage, &ptr, &length, strip, quality, lossless) + saveErr = C.vips_avifsave_bridge(tmpImage, &ptr, &length, strip, quality, lossless, speed) default: saveErr = C.vips_jpegsave_bridge(tmpImage, &ptr, &length, strip, quality, interlace) } diff --git a/vips.h b/vips.h index a7d0c4f..c8036f7 100644 --- a/vips.h +++ b/vips.h @@ -369,8 +369,17 @@ vips_tiffsave_bridge(VipsImage *in, void **buf, size_t *len) { } int -vips_avifsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int quality, int lossless) { -#if (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 9)) +vips_avifsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int quality, int lossless, int speed) { +#if (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION >= 8 && VIPS_MINOR_VERSION > 10) || (VIPS_MAJOR_VERSION >= 8 && VIPS_MINOR_VERSION >= 10 && VIPS_MICRO_VERSION >= 2)) + return vips_heifsave_buffer(in, buf, len, + "strip", INT_TO_GBOOLEAN(strip), + "Q", quality, + "lossless", INT_TO_GBOOLEAN(lossless), + "compression", VIPS_FOREIGN_HEIF_COMPRESSION_AV1, + "speed", speed, + NULL + ); +#elif (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 9)) return vips_heifsave_buffer(in, buf, len, "strip", INT_TO_GBOOLEAN(strip), "Q", quality, diff --git a/vips_test.go b/vips_test.go index a792054..00c1987 100644 --- a/vips_test.go +++ b/vips_test.go @@ -33,7 +33,7 @@ func TestVipsSave(t *testing.T) { for _, typ := range types { image, _, _ := vipsRead(readImage("test.jpg")) - options := vipsSaveOptions{Quality: 95, Type: typ, StripMetadata: true} + options := vipsSaveOptions{Quality: 95, Type: typ, StripMetadata: true, Speed: 8} buf, err := vipsSave(image, options) if err != nil {