mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-15 02:15:54 -07:00
refactor(#55): minor changes, use proper declarations, unref image
This commit is contained in:
parent
e83c80c93c
commit
174de89a40
5 changed files with 41 additions and 20 deletions
24
vips.go
24
vips.go
|
|
@ -252,14 +252,24 @@ func vipsInterpretation(image *C.VipsImage) Interpretation {
|
|||
return Interpretation(C.vips_image_guess_interpretation_bridge(image))
|
||||
}
|
||||
|
||||
func vipsFlatten(image *C.VipsImage, background Color) (*C.VipsImage, error) {
|
||||
func vipsFlattenBackground(image *C.VipsImage, background Color) (*C.VipsImage, error) {
|
||||
var outImage *C.VipsImage
|
||||
backgroundC := [3]C.double{C.double(background.R), C.double(background.G), C.double(background.B)}
|
||||
err := int(C.vips_flatten_image(image, &outImage, (*C.double)(&backgroundC[0])))
|
||||
if err != 0 {
|
||||
|
||||
backgroundC := [3]C.double{
|
||||
C.double(background.R),
|
||||
C.double(background.G),
|
||||
C.double(background.B),
|
||||
}
|
||||
|
||||
err := C.vips_flatten_background_brigde(image, &outImage, (*C.double)(&backgroundC[0]))
|
||||
if int(err) != 0 {
|
||||
return nil, catchVipsError()
|
||||
}
|
||||
return outImage, nil
|
||||
|
||||
C.g_object_unref(C.gpointer(image))
|
||||
image = outImage
|
||||
|
||||
return image, nil
|
||||
}
|
||||
|
||||
func vipsPreSave(image *C.VipsImage, o *vipsSaveOptions) (*C.VipsImage, error) {
|
||||
|
|
@ -277,8 +287,8 @@ func vipsPreSave(image *C.VipsImage, o *vipsSaveOptions) (*C.VipsImage, error) {
|
|||
// Apply the proper colour space
|
||||
var outImage *C.VipsImage
|
||||
if vipsColourspaceIsSupported(image) {
|
||||
err := int(C.vips_colourspace_bridge(image, &outImage, interpretation))
|
||||
if err != 0 {
|
||||
err := C.vips_colourspace_bridge(image, &outImage, interpretation)
|
||||
if int(err) != 0 {
|
||||
return nil, catchVipsError()
|
||||
}
|
||||
C.g_object_unref(C.gpointer(image))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue