Browse Source

Convert all images to uchar

DarthSim 4 years ago
parent
commit
bdbb496c18
1 changed files with 17 additions and 7 deletions
  1. 17 7
      process.go

+ 17 - 7
process.go

@@ -501,7 +501,15 @@ func transformImage(ctx context.Context, img *vipsImage, data []byte, po *proces
 		}
 	}
 
-	return img.RgbColourspace()
+	if err = img.RgbColourspace(); err != nil {
+		return err
+	}
+
+	if err := img.CastUchar(); err != nil {
+		return err
+	}
+
+	return copyMemoryAndCheckTimeout(ctx, img)
 }
 
 func transformAnimated(ctx context.Context, img *vipsImage, data []byte, po *processingOptions, imgtype imageType) error {
@@ -599,6 +607,14 @@ func transformAnimated(ctx context.Context, img *vipsImage, data []byte, po *pro
 		}
 	}
 
+	if err = img.CastUchar(); err != nil {
+		return err
+	}
+
+	if err = copyMemoryAndCheckTimeout(ctx, img); err != nil {
+		return err
+	}
+
 	img.SetInt("page-height", frames[0].Height())
 	img.SetInt("gif-delay", delay)
 	img.SetInt("gif-loop", loop)
@@ -769,12 +785,6 @@ func processImage(ctx context.Context) ([]byte, context.CancelFunc, error) {
 		return nil, func() {}, err
 	}
 
-	if po.Format == imageTypeGIF || po.Format == imageTypeBMP {
-		if err := img.CastUchar(); err != nil {
-			return nil, func() {}, err
-		}
-	}
-
 	if po.MaxBytes > 0 && canFitToBytes(po.Format) {
 		return saveImageToFitBytes(po, img)
 	}