Explorar el Código

Add test case for input data with pre-multiplied-alpha.

nfnt hace 10 años
padre
commit
5a6676c19e
Se han modificado 1 ficheros con 17 adiciones y 0 borrados
  1. 17 0
      resize_test.go

+ 17 - 0
resize_test.go

@@ -2,6 +2,7 @@ package resize
 
 import (
 	"image"
+	"fmt"
 	"image/color"
 	"runtime"
 	"testing"
@@ -85,6 +86,22 @@ func Test_SameSizeReturnsOriginal(t *testing.T) {
 	}
 }
 
+func Test_ResizeWithPremultipliedAlpha(t *testing.T) {
+	img := image.NewRGBA(image.Rect(0, 0, 1, 4))
+	for y := img.Bounds().Min.Y; y < img.Bounds().Max.Y; y++ {
+		// 0x80 = 0.5 * 0xFF.
+		img.SetRGBA(0, y, color.RGBA{0x80, 0x80, 0x80, 0x80})
+	}
+
+	out := Resize(1, 2, img, MitchellNetravali)
+
+	fmt.Println(out)
+	outputColor := out.At(0,0).(color.NRGBA)
+	if outputColor.R != 0xFF {
+		t.Fail()
+	}
+}
+
 const (
 	// Use a small image size for benchmarks. We don't want memory performance
 	// to affect the benchmark results.