From ce5ae9c7fe14648a27c8ed7c432fa921e7be7b00 Mon Sep 17 00:00:00 2001 From: Mike Stead Date: Sat, 11 Nov 2017 14:56:12 +1100 Subject: [PATCH] Add lossless option for saving webp --- options.go | 1 + resizer.go | 1 + vips.go | 4 +++- vips.h | 3 ++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/options.go b/options.go index 609de60..569d7f4 100644 --- a/options.go +++ b/options.go @@ -206,6 +206,7 @@ type Options struct { Interlace bool StripMetadata bool Trim bool + Lossless bool Extend Extend Rotate Angle Background Color diff --git a/resizer.go b/resizer.go index 4b78b47..52281e8 100644 --- a/resizer.go +++ b/resizer.go @@ -165,6 +165,7 @@ func saveImage(image *C.VipsImage, o Options) ([]byte, error) { Interpretation: o.Interpretation, OutputICC: o.OutputICC, StripMetadata: o.StripMetadata, + Lossless: o.Lossless, } // Finally get the resultant buffer return vipsSave(image, saveOptions) diff --git a/vips.go b/vips.go index 25448b3..51bffa0 100644 --- a/vips.go +++ b/vips.go @@ -56,6 +56,7 @@ type vipsSaveOptions struct { Interlace bool NoProfile bool StripMetadata bool + Lossless bool OutputICC string // Absolute path to the output ICC profile Interpretation Interpretation } @@ -423,6 +424,7 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) { interlace := C.int(boolToInt(o.Interlace)) quality := C.int(o.Quality) strip := C.int(boolToInt(o.StripMetadata)) + lossless := C.int(boolToInt(o.Lossless)) if o.Type != 0 && !IsTypeSupportedSave(o.Type) { return nil, fmt.Errorf("VIPS cannot save to %#v", ImageTypes[o.Type]) @@ -430,7 +432,7 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) { var ptr unsafe.Pointer switch o.Type { case WEBP: - saveErr = C.vips_webpsave_bridge(tmpImage, &ptr, &length, strip, quality) + 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) case TIFF: diff --git a/vips.h b/vips.h index 569086a..0ea1091 100644 --- a/vips.h +++ b/vips.h @@ -306,10 +306,11 @@ vips_pngsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int compr } int -vips_webpsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int quality) { +vips_webpsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int quality, int lossless) { return vips_webpsave_buffer(in, buf, len, "strip", INT_TO_GBOOLEAN(strip), "Q", quality, + "lossless", INT_TO_GBOOLEAN(lossless), NULL ); }