diff --git a/process.go b/process.go index ea3fe955..e5cedae9 100644 --- a/process.go +++ b/process.go @@ -376,7 +376,7 @@ func vipsSaveImage(img *C.struct__VipsImage, imgtype imageType) ([]byte, error) } func vipsImageHasAlpha(img *C.struct__VipsImage) bool { - return C.vips_image_hasalpha(img) > 0 + return C.vips_image_hasalpha_go(img) > 0 } func vipsPremultiply(img **C.struct__VipsImage) (C.VipsBandFormat, error) { diff --git a/vips.h b/vips.h index 2db1f6ed..c6b062cb 100644 --- a/vips.h +++ b/vips.h @@ -5,6 +5,9 @@ #define VIPS_SUPPORT_SMARTCROP \ (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 5)) +#define VIPS_SUPPORT_HASALPHA \ + (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 5)) + #define VIPS_SUPPORT_GIF \ VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 3) @@ -119,6 +122,17 @@ vips_band_format(VipsImage *in) { return in->BandFmt; } +gboolean +vips_image_hasalpha_go(VipsImage * in) { +#if VIPS_SUPPORT_HASALPHA + return vips_image_hasalpha(in); +#else + return( image->Bands == 2 || + (image->Bands == 4 && image->Type != VIPS_INTERPRETATION_CMYK) || + image->Bands > 4 ); +#endif +} + int vips_premultiply_go(VipsImage *in, VipsImage **out) { return vips_premultiply(in, out, NULL);