Skip to content

Commit

Permalink
Fixed the bug of incorrect calculation of page height when resize gif…
Browse files Browse the repository at this point in the history
… with vscale (#386)

Signed-off-by: songjiayang <[email protected]>
  • Loading branch information
songjiayang authored Oct 22, 2023
1 parent c6838fc commit 75637c2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions vips/arithmetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vips/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vips/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 13 additions & 0 deletions vips/image_gif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions vips/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 75637c2

Please sign in to comment.