From 75637c239751c35bb71b5c0e2068b2a04fd48a66 Mon Sep 17 00:00:00 2001 From: songjiayang Date: Mon, 23 Oct 2023 02:30:29 +0800 Subject: [PATCH] Fixed the bug of incorrect calculation of page height when resize gif with vscale (#386) Signed-off-by: songjiayang --- vips/arithmetic.go | 4 ++-- vips/color.go | 2 +- vips/image.go | 2 +- vips/image_gif_test.go | 13 +++++++++++++ vips/logging.go | 1 + 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/vips/arithmetic.go b/vips/arithmetic.go index f2bda66d..2a2d25c0 100644 --- a/vips/arithmetic.go +++ b/vips/arithmetic.go @@ -40,7 +40,7 @@ func vipsDivide(left *C.VipsImage, right *C.VipsImage) (*C.VipsImage, error) { return out, nil } -// https://libvips.github.io/libvips/API/current/libvips-arithmetic.html#vips-linear +// https://libvips.github.io/libvips/API/current/libvips-arithmetic.html#vips-linear func vipsLinear(in *C.VipsImage, a, b []float64, n int) (*C.VipsImage, error) { incOpCounter("linear") var out *C.VipsImage @@ -52,7 +52,7 @@ func vipsLinear(in *C.VipsImage, a, b []float64, n int) (*C.VipsImage, error) { return out, nil } -// https://libvips.github.io/libvips/API/current/libvips-arithmetic.html#vips-linear1 +// https://libvips.github.io/libvips/API/current/libvips-arithmetic.html#vips-linear1 func vipsLinear1(in *C.VipsImage, a, b float64) (*C.VipsImage, error) { incOpCounter("linear1") var out *C.VipsImage diff --git a/vips/color.go b/vips/color.go index def51aca..df5aed52 100644 --- a/vips/color.go +++ b/vips/color.go @@ -43,7 +43,7 @@ const ( // Intent represents VIPS_INTENT type type Intent int -//Intent enum +// Intent enum const ( IntentPerceptual Intent = C.VIPS_INTENT_PERCEPTUAL IntentRelative Intent = C.VIPS_INTENT_RELATIVE diff --git a/vips/image.go b/vips/image.go index fa6cd0c4..429ddd30 100644 --- a/vips/image.go +++ b/vips/image.go @@ -1662,7 +1662,7 @@ func (r *ImageRef) ResizeWithVScale(hScale, vScale float64, kernel Kernel) error if vScale != -1 { scale = vScale } - newPageHeight := int(float64(pageHeight) * scale) + newPageHeight := int(float64(pageHeight)*scale + 0.5) if err := r.SetPageHeight(newPageHeight); err != nil { return err } diff --git a/vips/image_gif_test.go b/vips/image_gif_test.go index 7b1e8eee..169103d2 100644 --- a/vips/image_gif_test.go +++ b/vips/image_gif_test.go @@ -50,6 +50,19 @@ func TestImage_GIF_Animated_Resize(t *testing.T) { nil) } +func TestImage_GIF_Animated_ResizeWithVScale(t *testing.T) { + goldenAnimatedTest(t, resources+"gif-animated.gif", + 3, + func(img *ImageRef) error { + return img.ResizeWithVScale(0.5, 0.78, KernelCubic) + }, + func(img *ImageRef) { + assert.Equal(t, 3, img.Pages()) + assert.Equal(t, 100, img.GetPageHeight()) + }, + nil) +} + func TestImage_GIF_Animated_Rotate90(t *testing.T) { goldenAnimatedTest(t, resources+"gif-animated.gif", -1, diff --git a/vips/logging.go b/vips/logging.go index 7822acaf..5053d016 100644 --- a/vips/logging.go +++ b/vips/logging.go @@ -33,6 +33,7 @@ var ( // and called by glib and libvips for each logging message. It will call govipsLog // which in turn will filter based on verbosity and direct the messages to the // currently chosen LoggingHandlerFunction. +// //export govipsLoggingHandler func govipsLoggingHandler(messageDomain *C.char, messageLevel C.int, message *C.char) { govipsLog(C.GoString(messageDomain), LogLevel(messageLevel), C.GoString(message))