From 5e7975929760d3079d6f3b3b86ea8875018d01ff Mon Sep 17 00:00:00 2001 From: Tomas Aparicio Date: Tue, 27 Sep 2016 21:31:44 +0100 Subject: [PATCH 1/7] refactor(types): do proper image typ casting --- resize.go | 2 +- type.go | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--- vips.go | 53 +++++++++++++++++++++++++++++++++++++++-------------- vips.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 133 insertions(+), 18 deletions(-) diff --git a/resize.go b/resize.go index 8d732fb..9d78f7d 100644 --- a/resize.go +++ b/resize.go @@ -28,7 +28,7 @@ func Resize(buf []byte, o Options) ([]byte, error) { // Clone and define default options o = applyDefaults(o, imageType) - if IsTypeSupported(o.Type) == false { + if !IsTypeSupported(o.Type) { return nil, errors.New("Unsupported image output type") } diff --git a/type.go b/type.go index 60722eb..b660e4e 100644 --- a/type.go +++ b/type.go @@ -1,7 +1,9 @@ package bimg -// ImageType represents an image type value. -type ImageType int +import ( + "regexp" + "unicode/utf8" +) const ( // UNKNOWN represents an unknow image type value. @@ -24,6 +26,14 @@ const ( MAGICK ) +// ImageType represents an image type value. +type ImageType int + +var ( + htmlCommentRegex = regexp.MustCompile("") + svgRegex = regexp.MustCompile(`^\s*(?:<\?xml[^>]*>\s*)?(?:]*>\s*)?]*>[^*]*<\/svg>\s*$`) +) + // ImageTypes stores as pairs of image types supported and its alias names. var ImageTypes = map[ImageType]string{ JPEG: "jpeg", @@ -36,6 +46,35 @@ var ImageTypes = map[ImageType]string{ MAGICK: "magick", } +// SupportedImageTypes stores the optional image type supported +// by the current libvips compilation. +var SupportedImageTypes = map[ImageType]bool{ + JPEG: HasJPEGSupport, + PNG: HasPNGSupport, + WEBP: HasWEBPSupport, + TIFF: HasTIFFSupport, + GIF: HasGIFSupport, + SVG: HasSVGSupport, + PDF: HasPDFSupport, + MAGICK: HasMagickSupport, +} + +// isBinary checks if the given buffer is a binary file. +func isBinary(buf []byte) bool { + for i := 0; i < 24; i++ { + charCode, _ := utf8.DecodeRuneInString(string(buf[i])) + if charCode == 65533 || charCode <= 8 { + return true + } + } + return false +} + +// IsSVGImage returns true if the given buffer is a valid SVG image. +func IsSVGImage(buf []byte) bool { + return !isBinary(buf) && svgRegex.Match(htmlCommentRegex.ReplaceAll(buf, []byte{0})) +} + // DetermineImageType determines the image type format (jpeg, png, webp or tiff) func DetermineImageType(buf []byte) ImageType { return vipsImageType(buf) @@ -46,9 +85,17 @@ func DetermineImageTypeName(buf []byte) string { return ImageTypeName(vipsImageType(buf)) } +// IsImageTypeSupportedByVips returns true if the given image type +// is supported by current libvips compilation. +func IsImageTypeSupportedByVips(t ImageType) bool { + isSupported, ok := SupportedImageTypes[t] + return ok && isSupported +} + // IsTypeSupported checks if a given image type is supported func IsTypeSupported(t ImageType) bool { - return ImageTypes[t] != "" + _, ok := ImageTypes[t] + return ok } // IsTypeNameSupported checks if a given image type name is supported diff --git a/vips.go b/vips.go index 1fec575..c494aa3 100644 --- a/vips.go +++ b/vips.go @@ -30,10 +30,38 @@ const VipsMajorVersion = int(C.VIPS_MAJOR_VERSION) // VipsMinorVersion exposes the current libvips minor version number const VipsMinorVersion = int(C.VIPS_MINOR_VERSION) +// HasJPEGSupport exposes if the current libvips compilation +// supports JPEG images. +const HasJPEGSupport = int(C.VIPS_JPEG_SUPPORT) == 1 + +// HasWEBPSupport exposes if the current libvips compilation +// supports WEBP images. +const HasWEBPSupport = int(C.VIPS_WEBP_SUPPORT) == 1 + +// HasPNGSupport exposes if the current libvips compilation +// supports PNG images. +const HasPNGSupport = int(C.VIPS_PNG_SUPPORT) == 1 + // HasMagickSupport exposes if the current libvips compilation // supports libmagick bindings. const HasMagickSupport = int(C.VIPS_MAGICK_SUPPORT) == 1 +// HasGIFSupport exposes if the current libvips compilation +// supports GIF images. +const HasGIFSupport = int(C.VIPS_GIF_SUPPORT) == 1 + +// HasSVGSupport exposes if the current libvips compilation +// supports SVG images. +const HasSVGSupport = int(C.VIPS_SVG_SUPPORT) == 1 + +// HasPDFSupport exposes if the current libvips compilation +// supports PDF images. +const HasPDFSupport = int(C.VIPS_PDF_SUPPORT) == 1 + +// HasTIFFSupport exposes if the current libvips compilation +// supports TIFF images. +const HasTIFFSupport = int(C.VIPS_TIFF_SUPPORT) == 1 + const ( maxCacheMem = 100 * 1024 * 1024 maxCacheSize = 500 @@ -461,39 +489,36 @@ func vipsAffine(input *C.VipsImage, residualx, residualy float64, i Interpolator return image, nil } -func vipsImageType(bytes []byte) ImageType { - if len(bytes) == 0 { +func vipsImageType(buf []byte) ImageType { + if len(buf) == 0 { return UNKNOWN } - if bytes[0] == 0x89 && bytes[1] == 0x50 && bytes[2] == 0x4E && bytes[3] == 0x47 { + if buf[0] == 0x89 && buf[1] == 0x50 && buf[2] == 0x4E && buf[3] == 0x47 { return PNG } - if bytes[0] == 0xFF && bytes[1] == 0xD8 && bytes[2] == 0xFF { + if buf[0] == 0xFF && buf[1] == 0xD8 && buf[2] == 0xFF { return JPEG } - if bytes[8] == 0x57 && bytes[9] == 0x45 && bytes[10] == 0x42 && bytes[11] == 0x50 { + if buf[8] == 0x57 && buf[9] == 0x45 && buf[10] == 0x42 && buf[11] == 0x50 { return WEBP } - if (bytes[0] == 0x49 && bytes[1] == 0x49 && bytes[2] == 0x2A && bytes[3] == 0x0) || - (bytes[0] == 0x4D && bytes[1] == 0x4D && bytes[2] == 0x0 && bytes[3] == 0x2A) { + if (buf[0] == 0x49 && buf[1] == 0x49 && buf[2] == 0x2A && buf[3] == 0x0) || + (buf[0] == 0x4D && buf[1] == 0x4D && buf[2] == 0x0 && buf[3] == 0x2A) { return TIFF } - if bytes[0] == 'G' && bytes[1] == 'I' && bytes[2] == 'F' && bytes[3] == '8' && - bytes[4] == '9' && bytes[5] == 'a' { + if buf[0] == 0x47 && buf[1] == 0x49 && buf[2] == 0x46 { return GIF } - if bytes[0] == '%' && bytes[1] == 'P' && bytes[2] == 'D' && bytes[3] == 'F' { + if buf[0] == 0x25 && buf[1] == 0x50 && buf[2] == 0x44 && buf[3] == 0x46 { return PDF } - if bytes[0] == '<' && bytes[1] == '?' && bytes[2] == 'x' && bytes[3] == 'm' && - bytes[4] == 'l' && bytes[5] == ' ' { + if IsSVGImage(buf) { return SVG } - if HasMagickSupport && strings.HasSuffix(readImageType(bytes), "MagickBuffer") { + if HasMagickSupport && strings.HasSuffix(readImageType(buf), "MagickBuffer") { return MAGICK } - return UNKNOWN } diff --git a/vips.h b/vips.h index b5b3bb2..ab1054e 100644 --- a/vips.h +++ b/vips.h @@ -1,5 +1,6 @@ #include #include +#include #include #ifdef VIPS_MAGICK_H @@ -8,6 +9,48 @@ #define VIPS_MAGICK_SUPPORT 0 #endif +#ifdef HAVE_JPEG +#define VIPS_JPEG_SUPPORT 1 +#else +#define VIPS_JPEG_SUPPORT 0 +#endif + +#ifdef HAVE_PNG +#define VIPS_PNG_SUPPORT 1 +#else +#define VIPS_PNG_SUPPORT 0 +#endif + +#ifdef HAVE_LIBWEBP +#define VIPS_WEBP_SUPPORT 1 +#else +#define VIPS_WEBP_SUPPORT 0 +#endif + +#ifdef HAVE_GIFLIB +#define VIPS_GIF_SUPPORT 1 +#else +#define VIPS_GIF_SUPPORT 0 +#endif + +#ifdef HAVE_RSVG +#define VIPS_SVG_SUPPORT 1 +#else +#define VIPS_SVG_SUPPORT 0 +#endif + +#ifdef HAVE_POPPLER +#define VIPS_PDF_SUPPORT 1 +#else +#define VIPS_PDF_SUPPORT 0 +#endif + +#ifdef HAVE_TIFF +#define VIPS_TIFF_SUPPORT 1 +#else +#define VIPS_TIFF_SUPPORT 0 +#endif + /** * Starting libvips 7.41, VIPS_ANGLE_x has been renamed to VIPS_ANGLE_Dx * "to help python". So we provide the macro to correctly build for versions From ac42bba8516151773566d4936bc6575fc7bf6d74 Mon Sep 17 00:00:00 2001 From: Tomas Aparicio Date: Tue, 27 Sep 2016 21:40:26 +0100 Subject: [PATCH 2/7] fix(type): check buffer length --- type.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/type.go b/type.go index b660e4e..889fdc7 100644 --- a/type.go +++ b/type.go @@ -61,6 +61,9 @@ var SupportedImageTypes = map[ImageType]bool{ // isBinary checks if the given buffer is a binary file. func isBinary(buf []byte) bool { + if len(buf) < 24 { + return false + } for i := 0; i < 24; i++ { charCode, _ := utf8.DecodeRuneInString(string(buf[i])) if charCode == 65533 || charCode <= 8 { From de76daee9cdd3cf8a1268efcabcc29c0adf6e8cc Mon Sep 17 00:00:00 2001 From: Tomas Aparicio Date: Tue, 27 Sep 2016 22:21:59 +0100 Subject: [PATCH 3/7] fix(type): svg type checking --- type.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/type.go b/type.go index 889fdc7..3356af5 100644 --- a/type.go +++ b/type.go @@ -30,8 +30,8 @@ const ( type ImageType int var ( - htmlCommentRegex = regexp.MustCompile("") - svgRegex = regexp.MustCompile(`^\s*(?:<\?xml[^>]*>\s*)?(?:]*>\s*)?]*>[^*]*<\/svg>\s*$`) + htmlCommentRegex = regexp.MustCompile("(?i)") + svgRegex = regexp.MustCompile(`(?i)^\s*(?:<\?xml[^>]*>\s*)?(?:]*>\s*)?]*>[^*]*<\/svg>\s*$`) ) // ImageTypes stores as pairs of image types supported and its alias names. @@ -75,7 +75,7 @@ func isBinary(buf []byte) bool { // IsSVGImage returns true if the given buffer is a valid SVG image. func IsSVGImage(buf []byte) bool { - return !isBinary(buf) && svgRegex.Match(htmlCommentRegex.ReplaceAll(buf, []byte{0})) + return !isBinary(buf) && svgRegex.Match(htmlCommentRegex.ReplaceAll(buf, []byte{})) } // DetermineImageType determines the image type format (jpeg, png, webp or tiff) From bffc7652bbbad2b1105146a54886ec8a550dadd6 Mon Sep 17 00:00:00 2001 From: Tomas Aparicio Date: Tue, 27 Sep 2016 23:56:18 +0100 Subject: [PATCH 4/7] feat(types): infer types in runtime --- type.go | 50 ++++++++++++++++++++++++++++--------- vips.go | 75 ++++++++++++++++++++++++++----------------------------- vips.h | 77 ++++++++++++++++++++++----------------------------------- 3 files changed, 102 insertions(+), 100 deletions(-) diff --git a/type.go b/type.go index 3356af5..beb5b3d 100644 --- a/type.go +++ b/type.go @@ -2,6 +2,7 @@ package bimg import ( "regexp" + "sync" "unicode/utf8" ) @@ -46,17 +47,28 @@ var ImageTypes = map[ImageType]string{ MAGICK: "magick", } +// imageMutex is used to provide thread-safe synchronization +// for SupportedImageTypes map. +var imageMutex = &sync.RWMutex{} + // SupportedImageTypes stores the optional image type supported // by the current libvips compilation. -var SupportedImageTypes = map[ImageType]bool{ - JPEG: HasJPEGSupport, - PNG: HasPNGSupport, - WEBP: HasWEBPSupport, - TIFF: HasTIFFSupport, - GIF: HasGIFSupport, - SVG: HasSVGSupport, - PDF: HasPDFSupport, - MAGICK: HasMagickSupport, +// Note: lazy evaluation as demand is required due +// to bootstrap runtime limitation with C/libvips world. +var SupportedImageTypes = map[ImageType]bool{} + +// discoverSupportedImageTypes is used to fill SupportedImageTypes map. +func discoverSupportedImageTypes() { + imageMutex.Lock() + SupportedImageTypes[JPEG] = VipsIsTypeSupported(JPEG) + SupportedImageTypes[PNG] = VipsIsTypeSupported(PNG) + SupportedImageTypes[GIF] = VipsIsTypeSupported(GIF) + SupportedImageTypes[WEBP] = VipsIsTypeSupported(WEBP) + SupportedImageTypes[SVG] = VipsIsTypeSupported(SVG) + SupportedImageTypes[TIFF] = VipsIsTypeSupported(TIFF) + SupportedImageTypes[PDF] = VipsIsTypeSupported(PDF) + SupportedImageTypes[MAGICK] = VipsIsTypeSupported(MAGICK) + imageMutex.Unlock() } // isBinary checks if the given buffer is a binary file. @@ -91,21 +103,35 @@ func DetermineImageTypeName(buf []byte) string { // IsImageTypeSupportedByVips returns true if the given image type // is supported by current libvips compilation. func IsImageTypeSupportedByVips(t ImageType) bool { + imageMutex.RLock() + + // Discover supported image types and cache the result + itShouldDiscovery := len(SupportedImageTypes) == 0 + if itShouldDiscovery { + imageMutex.RUnlock() + discoverSupportedImageTypes() + } + + // Check if image type is actually supported isSupported, ok := SupportedImageTypes[t] + if !itShouldDiscovery { + imageMutex.RUnlock() + } + return ok && isSupported } // IsTypeSupported checks if a given image type is supported func IsTypeSupported(t ImageType) bool { _, ok := ImageTypes[t] - return ok + return ok && IsImageTypeSupportedByVips(t) } // IsTypeNameSupported checks if a given image type name is supported func IsTypeNameSupported(t string) bool { - for _, name := range ImageTypes { + for imageType, name := range ImageTypes { if name == t { - return true + return IsImageTypeSupportedByVips(imageType) } } return false diff --git a/vips.go b/vips.go index c494aa3..535f5ad 100644 --- a/vips.go +++ b/vips.go @@ -30,38 +30,6 @@ const VipsMajorVersion = int(C.VIPS_MAJOR_VERSION) // VipsMinorVersion exposes the current libvips minor version number const VipsMinorVersion = int(C.VIPS_MINOR_VERSION) -// HasJPEGSupport exposes if the current libvips compilation -// supports JPEG images. -const HasJPEGSupport = int(C.VIPS_JPEG_SUPPORT) == 1 - -// HasWEBPSupport exposes if the current libvips compilation -// supports WEBP images. -const HasWEBPSupport = int(C.VIPS_WEBP_SUPPORT) == 1 - -// HasPNGSupport exposes if the current libvips compilation -// supports PNG images. -const HasPNGSupport = int(C.VIPS_PNG_SUPPORT) == 1 - -// HasMagickSupport exposes if the current libvips compilation -// supports libmagick bindings. -const HasMagickSupport = int(C.VIPS_MAGICK_SUPPORT) == 1 - -// HasGIFSupport exposes if the current libvips compilation -// supports GIF images. -const HasGIFSupport = int(C.VIPS_GIF_SUPPORT) == 1 - -// HasSVGSupport exposes if the current libvips compilation -// supports SVG images. -const HasSVGSupport = int(C.VIPS_SVG_SUPPORT) == 1 - -// HasPDFSupport exposes if the current libvips compilation -// supports PDF images. -const HasPDFSupport = int(C.VIPS_PDF_SUPPORT) == 1 - -// HasTIFFSupport exposes if the current libvips compilation -// supports TIFF images. -const HasTIFFSupport = int(C.VIPS_TIFF_SUPPORT) == 1 - const ( maxCacheMem = 100 * 1024 * 1024 maxCacheSize = 500 @@ -169,6 +137,33 @@ func VipsMemory() VipsMemoryInfo { } } +// VipsIsTypeSupported returns true if the given image type +// is supported by the current libvips compilation. +func VipsIsTypeSupported(t ImageType) bool { + if t == JPEG { + return int(C.vips_type_find_bridge(C.JPEG)) != 0 + } + if t == WEBP { + return int(C.vips_type_find_bridge(C.WEBP)) != 0 + } + if t == PNG { + return int(C.vips_type_find_bridge(C.PNG)) != 0 + } + if t == GIF { + return int(C.vips_type_find_bridge(C.GIF)) != 0 + } + if t == PDF { + return int(C.vips_type_find_bridge(C.PDF)) != 0 + } + if t == SVG { + return int(C.vips_type_find_bridge(C.SVG)) != 0 + } + if t == TIFF { + return int(C.vips_type_find_bridge(C.TIFF)) != 0 + } + return false +} + func vipsExifOrientation(image *C.VipsImage) int { return int(C.vips_exif_orientation(image)) } @@ -493,30 +488,30 @@ func vipsImageType(buf []byte) ImageType { if len(buf) == 0 { return UNKNOWN } - if buf[0] == 0x89 && buf[1] == 0x50 && buf[2] == 0x4E && buf[3] == 0x47 { return PNG } if buf[0] == 0xFF && buf[1] == 0xD8 && buf[2] == 0xFF { return JPEG } - if buf[8] == 0x57 && buf[9] == 0x45 && buf[10] == 0x42 && buf[11] == 0x50 { + if IsImageTypeSupportedByVips(WEBP) && buf[8] == 0x57 && buf[9] == 0x45 && buf[10] == 0x42 && buf[11] == 0x50 { return WEBP } - if (buf[0] == 0x49 && buf[1] == 0x49 && buf[2] == 0x2A && buf[3] == 0x0) || - (buf[0] == 0x4D && buf[1] == 0x4D && buf[2] == 0x0 && buf[3] == 0x2A) { + if IsImageTypeSupportedByVips(TIFF) && + ((buf[0] == 0x49 && buf[1] == 0x49 && buf[2] == 0x2A && buf[3] == 0x0) || + (buf[0] == 0x4D && buf[1] == 0x4D && buf[2] == 0x0 && buf[3] == 0x2A)) { return TIFF } - if buf[0] == 0x47 && buf[1] == 0x49 && buf[2] == 0x46 { + if IsImageTypeSupportedByVips(GIF) && buf[0] == 0x47 && buf[1] == 0x49 && buf[2] == 0x46 { return GIF } - if buf[0] == 0x25 && buf[1] == 0x50 && buf[2] == 0x44 && buf[3] == 0x46 { + if IsImageTypeSupportedByVips(PDF) && buf[0] == 0x25 && buf[1] == 0x50 && buf[2] == 0x44 && buf[3] == 0x46 { return PDF } - if IsSVGImage(buf) { + if IsImageTypeSupportedByVips(SVG) && IsSVGImage(buf) { return SVG } - if HasMagickSupport && strings.HasSuffix(readImageType(buf), "MagickBuffer") { + if strings.HasSuffix(readImageType(buf), "MagickBuffer") { return MAGICK } return UNKNOWN diff --git a/vips.h b/vips.h index ab1054e..c4e6ed8 100644 --- a/vips.h +++ b/vips.h @@ -3,54 +3,6 @@ #include #include -#ifdef VIPS_MAGICK_H -#define VIPS_MAGICK_SUPPORT 1 -#else -#define VIPS_MAGICK_SUPPORT 0 -#endif - -#ifdef HAVE_JPEG -#define VIPS_JPEG_SUPPORT 1 -#else -#define VIPS_JPEG_SUPPORT 0 -#endif - -#ifdef HAVE_PNG -#define VIPS_PNG_SUPPORT 1 -#else -#define VIPS_PNG_SUPPORT 0 -#endif - -#ifdef HAVE_LIBWEBP -#define VIPS_WEBP_SUPPORT 1 -#else -#define VIPS_WEBP_SUPPORT 0 -#endif - -#ifdef HAVE_GIFLIB -#define VIPS_GIF_SUPPORT 1 -#else -#define VIPS_GIF_SUPPORT 0 -#endif - -#ifdef HAVE_RSVG -#define VIPS_SVG_SUPPORT 1 -#else -#define VIPS_SVG_SUPPORT 0 -#endif - -#ifdef HAVE_POPPLER -#define VIPS_PDF_SUPPORT 1 -#else -#define VIPS_PDF_SUPPORT 0 -#endif - -#ifdef HAVE_TIFF -#define VIPS_TIFF_SUPPORT 1 -#else -#define VIPS_TIFF_SUPPORT 0 -#endif - /** * Starting libvips 7.41, VIPS_ANGLE_x has been renamed to VIPS_ANGLE_Dx * "to help python". So we provide the macro to correctly build for versions @@ -163,6 +115,35 @@ vips_shrink_bridge(VipsImage *in, VipsImage **out, double xshrink, double yshrin return vips_shrink(in, out, xshrink, yshrink, NULL); } +int +vips_type_find_bridge(int t) { + if (t == GIF) { + return vips_type_find("VipsOperation", "gifload"); + } + if (t == PDF) { + return vips_type_find("VipsOperation", "pdfload"); + } + if (t == TIFF) { + return vips_type_find("VipsOperation", "tiffload"); + } + if (t == SVG) { + return vips_type_find("VipsOperation", "svgload"); + } + if (t == WEBP) { + return vips_type_find("VipsOperation", "webpload"); + } + if (t == PNG) { + return vips_type_find("VipsOperation", "pngload"); + } + if (t == JPEG) { + return vips_type_find("VipsOperation", "jpegload"); + } + if (t == MAGICK) { + return vips_type_find("VipsOperation", "magickload"); + } + return 0; +} + int vips_rotate(VipsImage *in, VipsImage **out, int angle) { int rotate = VIPS_ANGLE_D0; From 5ca57a1e6846e95bb8ab22f928c64f38bcabeccd Mon Sep 17 00:00:00 2001 From: Tomas Aparicio Date: Wed, 28 Sep 2016 00:14:29 +0100 Subject: [PATCH 5/7] fix(background): pass proper background RGB color --- resize.go | 1 - vips.go | 3 ++- vips.h | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/resize.go b/resize.go index 9d78f7d..4ccc92b 100644 --- a/resize.go +++ b/resize.go @@ -330,7 +330,6 @@ func imageFlatten(image *C.VipsImage, imageType ImageType, o Options) (*C.VipsIm if imageType != PNG || o.Background == ColorBlack { return image, nil } - return vipsFlattenBackground(image, o.Background) } diff --git a/vips.go b/vips.go index 535f5ad..33ab442 100644 --- a/vips.go +++ b/vips.go @@ -304,7 +304,8 @@ func vipsFlattenBackground(image *C.VipsImage, background Color) (*C.VipsImage, } if vipsHasAlpha(image) { - err := C.vips_flatten_background_brigde(image, &outImage, (*C.double)(&backgroundC[0])) + err := C.vips_flatten_background_brigde(image, &outImage, + backgroundC[0], backgroundC[1], backgroundC[2]) if int(err) != 0 { return nil, catchVipsError() } diff --git a/vips.h b/vips.h index c4e6ed8..3cbe6cf 100644 --- a/vips.h +++ b/vips.h @@ -277,12 +277,10 @@ vips_is_16bit (VipsInterpretation interpretation) { } int -vips_flatten_background_brigde(VipsImage *in, VipsImage **out, double background[3]) { - background[0] *= 256; - background[1] *= 256; - background[2] *= 256; - +vips_flatten_background_brigde(VipsImage *in, VipsImage **out, double r, double g, double b) { + double background[3] = {r, g, b}; VipsArrayDouble *vipsBackground = vips_array_double_new(background, 3); + return vips_flatten(in, out, "background", vipsBackground, "max_alpha", vips_is_16bit(in->Type) ? 65535.0 : 255.0, From 1d16b40629bbe7b73226a4797584bc1ed714a13a Mon Sep 17 00:00:00 2001 From: Tomas Aparicio Date: Wed, 28 Sep 2016 00:30:19 +0100 Subject: [PATCH 6/7] feat(version): bump to 1.0.3 --- History.md | 11 +++++++++-- version.go | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/History.md b/History.md index 62a07fd..663e04b 100644 --- a/History.md +++ b/History.md @@ -1,7 +1,14 @@ +## 1.0.3 / 28-09-2016 + +- fix(#95): better image type inference and support check. +- fix(background): pass proper background RGB color for PNG image conversion. +- feat(types): validate supported image types by current `libvips` compilation. +- feat(types): consistent SVG image checking. + ## 1.0.2 / 27-09-2016 -- feat(#95): support GIF, SVG and PDF formats -- fix(#108): auto-width and height calculations now round instead of floor +- feat(#95): support GIF, SVG and PDF formats. +- fix(#108): auto-width and height calculations now round instead of floor. ## 1.0.1 / 22-06-2016 diff --git a/version.go b/version.go index b10c1e9..d03c288 100644 --- a/version.go +++ b/version.go @@ -1,4 +1,4 @@ package bimg // Version represents the current package semantic version. -const Version = "1.0.2" +const Version = "1.0.3" From dfd6e8fe2df2b8e48dc1a575605134321cfefcb6 Mon Sep 17 00:00:00 2001 From: Tomas Aparicio Date: Wed, 28 Sep 2016 00:35:17 +0100 Subject: [PATCH 7/7] feat(docs): update History with API changes --- History.md | 1 + 1 file changed, 1 insertion(+) diff --git a/History.md b/History.md index 663e04b..11d7ba8 100644 --- a/History.md +++ b/History.md @@ -4,6 +4,7 @@ - fix(background): pass proper background RGB color for PNG image conversion. - feat(types): validate supported image types by current `libvips` compilation. - feat(types): consistent SVG image checking. +- feat(api): add public functions `VipsIsTypeSupported()`, `IsImageTypeSupportedByVips()` and `IsSVGImage()`. ## 1.0.2 / 27-09-2016