mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-15 10:25:55 -07:00
Fix the unref of images, when image isn't transparent
This commit is contained in:
parent
ff7970929b
commit
6524efa800
2 changed files with 6 additions and 4 deletions
3
vips.go
3
vips.go
|
|
@ -604,9 +604,6 @@ func vipsDrawWatermark(image *C.VipsImage, o WatermarkImage) (*C.VipsImage, erro
|
||||||
return nil, e
|
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)}
|
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)))
|
err := C.vips_watermark_image(image, watermark, &out, (*C.WatermarkImageOptions)(unsafe.Pointer(&opts)))
|
||||||
|
|
|
||||||
7
vips.h
7
vips.h
|
|
@ -464,17 +464,22 @@ vips_add_band(VipsImage *in, VipsImage **out, double c) {
|
||||||
int
|
int
|
||||||
vips_watermark_image(VipsImage *in, VipsImage *sub, VipsImage **out, WatermarkImageOptions *o) {
|
vips_watermark_image(VipsImage *in, VipsImage *sub, VipsImage **out, WatermarkImageOptions *o) {
|
||||||
VipsImage *base = vips_image_new();
|
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[0] = in;
|
||||||
t[1] = sub;
|
t[1] = sub;
|
||||||
|
|
||||||
if (has_alpha_channel(in) == 0) {
|
if (has_alpha_channel(in) == 0) {
|
||||||
vips_bandjoin_const1(in, &t[0], 255.0, NULL);
|
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) {
|
if (has_alpha_channel(sub) == 0) {
|
||||||
vips_bandjoin_const1(sub, &t[1], 255.0, NULL);
|
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
|
// Place watermark image in the right place and size it to the size of the
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue