From f430a41192ab83e08e5acb181bdce85694a4982e Mon Sep 17 00:00:00 2001 From: minodisk Date: Mon, 25 May 2015 18:18:32 +0900 Subject: [PATCH] Fix wrong color with RGBA input --- converter.go | 6 +++--- resize_test.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/converter.go b/converter.go index 84bd284..b3dd06b 100644 --- a/converter.go +++ b/converter.go @@ -131,11 +131,11 @@ func resizeRGBA(in *image.RGBA, out *image.NRGBA, scale float64, coeffs []int16, // reverse alpha-premultiplication. if a != 0 { - r *= 0xffff + r *= 0xff r /= a - g *= 0xffff + g *= 0xff g /= a - b *= 0xffff + b *= 0xff b /= a } diff --git a/resize_test.go b/resize_test.go index ee31ac4..0c6093b 100644 --- a/resize_test.go +++ b/resize_test.go @@ -46,7 +46,7 @@ func Test_CorrectResize(t *testing.T) { } } -func Test_SameColor(t *testing.T) { +func Test_SameColorWithRGBA(t *testing.T) { img := image.NewRGBA(image.Rect(0, 0, 20, 20)) for y := img.Bounds().Min.Y; y < img.Bounds().Max.Y; y++ { for x := img.Bounds().Min.X; x < img.Bounds().Max.X; x++ { @@ -56,7 +56,7 @@ func Test_SameColor(t *testing.T) { out := Resize(10, 10, img, Lanczos3) for y := out.Bounds().Min.Y; y < out.Bounds().Max.Y; y++ { for x := out.Bounds().Min.X; x < out.Bounds().Max.X; x++ { - color := img.At(x, y).(color.RGBA) + color := out.At(x, y).(color.NRGBA) if color.R != 0x80 || color.G != 0x80 || color.B != 0x80 || color.A != 0xFF { t.Fail() }