From 6524efa8007c756b8346f26af70a6c074b67446f Mon Sep 17 00:00:00 2001 From: Albert-Jan de Vries Date: Fri, 31 Mar 2017 20:31:17 +0200 Subject: [PATCH] Fix the unref of images, when image isn't transparent --- vips.go | 3 --- vips.h | 7 ++++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/vips.go b/vips.go index 7e67c99..e0b0e43 100644 --- a/vips.go +++ b/vips.go @@ -604,9 +604,6 @@ func vipsDrawWatermark(image *C.VipsImage, o WatermarkImage) (*C.VipsImage, erro return nil, e } - defer C.g_object_unref(C.gpointer(image)) - defer C.g_object_unref(C.gpointer(watermark)) - opts := vipsWatermarkImageOptions{C.int(o.Left), C.int(o.Top), C.float(o.Opacity)} err := C.vips_watermark_image(image, watermark, &out, (*C.WatermarkImageOptions)(unsafe.Pointer(&opts))) diff --git a/vips.h b/vips.h index d475f46..1ac370b 100644 --- a/vips.h +++ b/vips.h @@ -464,17 +464,22 @@ vips_add_band(VipsImage *in, VipsImage **out, double c) { int vips_watermark_image(VipsImage *in, VipsImage *sub, VipsImage **out, WatermarkImageOptions *o) { VipsImage *base = vips_image_new(); - VipsImage **t = (VipsImage **) vips_object_local_array(VIPS_OBJECT(base), 8); + VipsImage **t = (VipsImage **) vips_object_local_array(VIPS_OBJECT(base), 10); + // add in and sub for unreffing and later use t[0] = in; t[1] = sub; if (has_alpha_channel(in) == 0) { vips_bandjoin_const1(in, &t[0], 255.0, NULL); + // in is no longer in the array and won't be unreffed, so add it at the end + t[8] = in; } if (has_alpha_channel(sub) == 0) { vips_bandjoin_const1(sub, &t[1], 255.0, NULL); + // sub is no longer in the array and won't be unreffed, so add it at the end + t[9] = sub; } // Place watermark image in the right place and size it to the size of the