mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-07 21:48:13 -08:00
Use vips reduce when downscaling
This commit is contained in:
parent
878125c410
commit
dc3286965b
3 changed files with 22 additions and 1 deletions
|
|
@ -198,7 +198,11 @@ func transformImage(image *C.VipsImage, o Options, shrink int, residual float64)
|
|||
}
|
||||
|
||||
if o.Force || residual != 0 {
|
||||
image, err = vipsAffine(image, residualx, residualy, o.Interpolator)
|
||||
if residualx < 1 && residualy < 1 {
|
||||
image, err = vipsReduce(image, 1/residualx, 1/residualy)
|
||||
} else {
|
||||
image, err = vipsAffine(image, residualx, residualy, o.Interpolator)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
12
vips.go
12
vips.go
|
|
@ -513,6 +513,18 @@ func vipsShrink(input *C.VipsImage, shrink int) (*C.VipsImage, error) {
|
|||
return image, nil
|
||||
}
|
||||
|
||||
func vipsReduce(input *C.VipsImage, xshrink float64, yshrink float64) (*C.VipsImage, error) {
|
||||
var image *C.VipsImage
|
||||
defer C.g_object_unref(C.gpointer(input))
|
||||
|
||||
err := C.vips_reduce_bridge(input, &image, C.double(xshrink), C.double(yshrink))
|
||||
if err != 0 {
|
||||
return nil, catchVipsError()
|
||||
}
|
||||
|
||||
return image, nil
|
||||
}
|
||||
|
||||
func vipsEmbed(input *C.VipsImage, left, top, width, height int, extend Extend, background Color) (*C.VipsImage, error) {
|
||||
var image *C.VipsImage
|
||||
|
||||
|
|
|
|||
5
vips.h
5
vips.h
|
|
@ -122,6 +122,11 @@ vips_shrink_bridge(VipsImage *in, VipsImage **out, double xshrink, double yshrin
|
|||
return vips_shrink(in, out, xshrink, yshrink, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
vips_reduce_bridge(VipsImage *in, VipsImage **out, double xshrink, double yshrink) {
|
||||
return vips_reduce(in, out, xshrink, yshrink, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
vips_type_find_bridge(int t) {
|
||||
if (t == GIF) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue