1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-11-27 22:48:53 +02:00

Use VIPS_UNREF instead of g_clear_object

This commit is contained in:
DarthSim
2025-09-08 21:07:11 +03:00
parent 7da78ef191
commit 2eb80c7f58
4 changed files with 86 additions and 88 deletions

View File

@@ -331,6 +331,13 @@ func ptrToBytes(ptr unsafe.Pointer, size int) []byte {
return (*[math.MaxInt32]byte)(ptr)[:int(size):int(size)]
}
func (img *Image) swapAndUnref(newImg *C.VipsImage) {
if img.VipsImage != nil {
C.unref_image(img.VipsImage)
}
img.VipsImage = newImg
}
func (img *Image) Width() int {
return int(img.VipsImage.Xsize)
}
@@ -390,11 +397,11 @@ func (img *Image) Load(imgdata *imagedata.ImageData, shrink int, scale float64,
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
if imgdata.Type == imagetype.TIFF {
if C.vips_fix_float_tiff(img.VipsImage, &tmp) == 0 {
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
} else {
log.Warnf("Can't fix TIFF: %s", Error())
}
@@ -417,7 +424,7 @@ func (img *Image) LoadThumbnail(imgdata *imagedata.ImageData) error {
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
return nil
}
@@ -476,7 +483,8 @@ func (img *Image) Save(imgtype imagetype.Type, quality int) (*imagedata.ImageDat
func (img *Image) Clear() {
if img.VipsImage != nil {
C.clear_image(&img.VipsImage)
C.unref_image(img.VipsImage)
img.VipsImage = nil
}
}
@@ -487,7 +495,7 @@ func (img *Image) LineCache(lines int) error {
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
return nil
}
@@ -503,7 +511,7 @@ func (img *Image) Arrayjoin(in []*Image) error {
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
return nil
}
@@ -623,7 +631,7 @@ func (img *Image) CastUchar() error {
if C.vips_cast_go(img.VipsImage, &tmp, C.VIPS_FORMAT_UCHAR) != 0 {
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
}
return nil
@@ -636,7 +644,7 @@ func (img *Image) Rad2Float() error {
if C.vips_rad2float_go(img.VipsImage, &tmp) != 0 {
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
}
return nil
@@ -653,7 +661,7 @@ func (img *Image) Resize(wscale, hscale float64) error {
C.vips_image_set_int(tmp, cachedCString("imgproxy-scaled-down"), 1)
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
return nil
}
@@ -673,7 +681,7 @@ func (img *Image) Rotate(angle int) error {
C.vips_autorot_remove_angle(tmp)
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
return nil
}
@@ -684,7 +692,7 @@ func (img *Image) Flip() error {
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
return nil
}
@@ -695,7 +703,7 @@ func (img *Image) Crop(left, top, width, height int) error {
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
return nil
}
@@ -713,7 +721,7 @@ func (img *Image) SmartCrop(width, height int) error {
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
return nil
}
@@ -729,7 +737,7 @@ func (img *Image) Trim(threshold float64, smart bool, color Color, equalHor bool
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
return nil
}
@@ -739,7 +747,7 @@ func (img *Image) Flatten(bg Color) error {
if C.vips_flatten_go(img.VipsImage, &tmp, cRGB(bg)) != 0 {
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
return nil
}
@@ -751,7 +759,7 @@ func (img *Image) ApplyFilters(blurSigma, sharpSigma float32, pixelatePixels int
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
return nil
}
@@ -771,7 +779,7 @@ func (img *Image) BackupColourProfile() {
var tmp *C.VipsImage
if C.vips_icc_backup(img.VipsImage, &tmp) == 0 {
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
} else {
log.Warningf("Can't backup ICC profile: %s", Error())
}
@@ -781,7 +789,7 @@ func (img *Image) RestoreColourProfile() {
var tmp *C.VipsImage
if C.vips_icc_restore(img.VipsImage, &tmp) == 0 {
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
} else {
log.Warningf("Can't restore ICC profile: %s", Error())
}
@@ -806,7 +814,7 @@ func (img *Image) ImportColourProfile() error {
}
if C.vips_icc_import_go(img.VipsImage, &tmp) == 0 {
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
} else {
log.Warningf("Can't import ICC profile: %s", Error())
}
@@ -828,7 +836,7 @@ func (img *Image) ExportColourProfile() error {
}
if C.vips_icc_export_go(img.VipsImage, &tmp) == 0 {
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
} else {
log.Warningf("Can't export ICC profile: %s", Error())
}
@@ -845,7 +853,7 @@ func (img *Image) ExportColourProfileToSRGB() error {
}
if C.vips_icc_export_srgb(img.VipsImage, &tmp) == 0 {
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
} else {
log.Warningf("Can't export ICC profile: %s", Error())
}
@@ -864,7 +872,7 @@ func (img *Image) TransformColourProfileToSRGB() error {
}
if C.vips_icc_transform_srgb(img.VipsImage, &tmp) == 0 {
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
} else {
log.Warningf("Can't transform ICC profile to sRGB: %s", Error())
}
@@ -876,7 +884,7 @@ func (img *Image) RemoveColourProfile() error {
var tmp *C.VipsImage
if C.vips_icc_remove(img.VipsImage, &tmp) == 0 {
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
} else {
log.Warningf("Can't remove ICC profile: %s", Error())
}
@@ -899,7 +907,7 @@ func (img *Image) Colorspace(colorspace C.VipsInterpretation) error {
if C.vips_colourspace_go(img.VipsImage, &tmp, colorspace) != 0 {
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
}
return nil
@@ -910,7 +918,7 @@ func (img *Image) CopyMemory() error {
if tmp = C.vips_image_copy_memory(img.VipsImage); tmp == nil {
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
return nil
}
@@ -920,7 +928,7 @@ func (img *Image) Replicate(width, height int, centered bool) error {
if C.vips_replicate_go(img.VipsImage, &tmp, C.int(width), C.int(height), gbool(centered)) != 0 {
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
return nil
}
@@ -931,7 +939,7 @@ func (img *Image) Embed(width, height int, offX, offY int) error {
if C.vips_embed_go(img.VipsImage, &tmp, C.int(offX), C.int(offY), C.int(width), C.int(height)) != 0 {
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
return nil
}
@@ -942,7 +950,7 @@ func (img *Image) ApplyWatermark(wm *Image, left, top int, opacity float64) erro
if C.vips_apply_watermark(img.VipsImage, wm.VipsImage, &tmp, C.int(left), C.int(top), C.double(opacity)) != 0 {
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
return nil
}
@@ -953,7 +961,7 @@ func (img *Image) Strip(keepExifCopyright bool) error {
if C.vips_strip(img.VipsImage, &tmp, gbool(keepExifCopyright)) != 0 {
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
return nil
}
@@ -964,7 +972,7 @@ func (img *Image) StripAll() error {
if C.vips_strip_all(img.VipsImage, &tmp) != 0 {
return Error()
}
C.swap_and_clear(&img.VipsImage, tmp)
img.swapAndUnref(tmp)
return nil
}