From dfd363a962df8ee4afb3d7a254a923301f082b29 Mon Sep 17 00:00:00 2001 From: Azuma Fan Date: Mon, 8 Jun 2020 16:43:04 +0800 Subject: [PATCH] support Palette option for png --- options.go | 1 + resizer.go | 1 + vips.go | 4 +++- vips.h | 5 +++-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/options.go b/options.go index dd59031..5212ef9 100644 --- a/options.go +++ b/options.go @@ -225,4 +225,5 @@ type Options struct { Gamma float64 OutputICC string InputICC string + Palette bool } diff --git a/resizer.go b/resizer.go index 461af5e..6056f7b 100644 --- a/resizer.go +++ b/resizer.go @@ -176,6 +176,7 @@ func saveImage(image *C.VipsImage, o Options) ([]byte, error) { OutputICC: o.OutputICC, StripMetadata: o.StripMetadata, Lossless: o.Lossless, + Palette: o.Palette, } // Finally get the resultant buffer return vipsSave(image, saveOptions) diff --git a/vips.go b/vips.go index 77dd7ac..2e233eb 100644 --- a/vips.go +++ b/vips.go @@ -55,6 +55,7 @@ type vipsSaveOptions struct { InputICC string // Absolute path to the input ICC profile OutputICC string // Absolute path to the output ICC profile Interpretation Interpretation + Palette bool } type vipsWatermarkOptions struct { @@ -458,6 +459,7 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) { quality := C.int(o.Quality) strip := C.int(boolToInt(o.StripMetadata)) lossless := C.int(boolToInt(o.Lossless)) + palette := C.int(boolToInt(o.Palette)) if o.Type != 0 && !IsTypeSupportedSave(o.Type) { return nil, fmt.Errorf("VIPS cannot save to %#v", ImageTypes[o.Type]) @@ -467,7 +469,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) + saveErr = C.vips_pngsave_bridge(tmpImage, &ptr, &length, strip, C.int(o.Compression), quality, interlace, palette) case TIFF: saveErr = C.vips_tiffsave_bridge(tmpImage, &ptr, &length) case HEIF: diff --git a/vips.h b/vips.h index 69e3903..4107d17 100644 --- a/vips.h +++ b/vips.h @@ -309,13 +309,14 @@ 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) { -#if (VIPS_MAJOR_VERSION >= 8 || (VIPS_MAJOR_VERSION >= 7 && VIPS_MINOR_VERSION >= 42)) +vips_pngsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int compression, int quality, int interlace, int palette) { +#if (VIPS_MAJOR_VERSION >= 8 && VIPS_MINOR_VERSION >= 7) 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), NULL ); #else