浏览代码

Fix animated JPEG XL support

DarthSim 8 月之前
父节点
当前提交
d9abf2d3d7
共有 5 个文件被更改,包括 13 次插入9 次删除
  1. 5 1
      imagetype/imagetype.go
  2. 4 4
      processing/processing.go
  3. 2 2
      vips/vips.c
  4. 1 1
      vips/vips.go
  5. 1 1
      vips/vips.h

+ 5 - 1
imagetype/imagetype.go

@@ -147,7 +147,11 @@ func (it Type) SupportsAlpha() bool {
 	return it != JPEG && it != BMP
 }
 
-func (it Type) SupportsAnimation() bool {
+func (it Type) SupportsAnimationLoad() bool {
+	return it == GIF || it == WEBP || it == JXL
+}
+
+func (it Type) SupportsAnimationSave() bool {
 	return it == GIF || it == WEBP
 }
 

+ 4 - 4
processing/processing.go

@@ -54,7 +54,7 @@ func isImageTypePreferred(imgtype imagetype.Type) bool {
 
 func findBestFormat(srcType imagetype.Type, animated, expectAlpha bool) imagetype.Type {
 	for _, t := range config.PreferredFormats {
-		if animated && !t.SupportsAnimation() {
+		if animated && !t.SupportsAnimationSave() {
 			continue
 		}
 
@@ -248,8 +248,8 @@ func ProcessImage(ctx context.Context, imgdata *imagedata.ImageData, po *options
 
 	animationSupport :=
 		po.SecurityOptions.MaxAnimationFrames > 1 &&
-			imgdata.Type.SupportsAnimation() &&
-			(po.Format == imagetype.Unknown || po.Format.SupportsAnimation())
+			imgdata.Type.SupportsAnimationLoad() &&
+			(po.Format == imagetype.Unknown || po.Format.SupportsAnimationSave())
 
 	pages := 1
 	if animationSupport {
@@ -304,7 +304,7 @@ func ProcessImage(ctx context.Context, imgdata *imagedata.ImageData, po *options
 		return nil, fmt.Errorf("Can't save %s, probably not supported by your libvips", po.Format)
 	}
 
-	if po.Format.SupportsAnimation() && animated {
+	if po.Format.SupportsAnimationSave() && animated {
 		if err := transformAnimated(ctx, img, po, imgdata); err != nil {
 			return nil, err
 		}

+ 2 - 2
vips/vips.c

@@ -64,9 +64,9 @@ vips_jpegload_go(void *buf, size_t len, int shrink, VipsImage **out)
 }
 
 int
-vips_jxlload_go(void *buf, size_t len, VipsImage **out)
+vips_jxlload_go(void *buf, size_t len, int pages, VipsImage **out)
 {
-  return vips_jxlload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, NULL);
+  return vips_jxlload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, "n", pages, NULL);
 }
 
 int

+ 1 - 1
vips/vips.go

@@ -337,7 +337,7 @@ func (img *Image) Load(imgdata *imagedata.ImageData, shrink int, scale float64,
 	case imagetype.JPEG:
 		err = C.vips_jpegload_go(data, dataSize, C.int(shrink), &tmp)
 	case imagetype.JXL:
-		err = C.vips_jxlload_go(data, dataSize, &tmp)
+		err = C.vips_jxlload_go(data, dataSize, C.int(pages), &tmp)
 	case imagetype.PNG:
 		err = C.vips_pngload_go(data, dataSize, &tmp, vipsConf.PngUnlimited)
 	case imagetype.WEBP:

+ 1 - 1
vips/vips.h

@@ -16,7 +16,7 @@ int gif_resolution_limit();
 int vips_health();
 
 int vips_jpegload_go(void *buf, size_t len, int shrink, VipsImage **out);
-int vips_jxlload_go(void *buf, size_t len, VipsImage **out);
+int vips_jxlload_go(void *buf, size_t len, int pages, VipsImage **out);
 int vips_pngload_go(void *buf, size_t len, VipsImage **out, int unlimited);
 int vips_webpload_go(void *buf, size_t len, double scale, int pages, VipsImage **out);
 int vips_gifload_go(void *buf, size_t len, int pages, VipsImage **out);