diff --git a/filters.go b/filters.go index 4818a90..112cc76 100644 --- a/filters.go +++ b/filters.go @@ -27,8 +27,8 @@ type RGBA [4]uint16 // build RGBA from an arbitrary color func toRGBA(c color.Color) RGBA { - n := color.RGBA64Model.Convert(c).(color.RGBA64) - return RGBA{n.R, n.G, n.B, n.A} + r, g, b, a := c.RGBA() + return RGBA{uint16(r), uint16(g), uint16(b), uint16(a)} } func clampToUint16(x float32) (y uint16) { diff --git a/resize.go b/resize.go index a3ac3d0..aee19c3 100644 --- a/resize.go +++ b/resize.go @@ -85,11 +85,11 @@ func Resize(width, height uint, img image.Image, interp InterpolationFunction) i resizedImg := image.NewRGBA64(image.Rect(0, 0, int(oldWidth/scaleX), int(oldHeight/scaleY))) b := resizedImg.Bounds() - + // prevent resize from doing too much work // if #CPUs > width n := 1 - if (NCPU < b.Dy()) { + if NCPU < b.Dy() { n = NCPU } else { n = b.Dy() diff --git a/resize_test.go b/resize_test.go index d74a9db..0b1735a 100644 --- a/resize_test.go +++ b/resize_test.go @@ -8,11 +8,12 @@ import ( var img = image.NewGray16(image.Rect(0, 0, 3, 3)) -func Test_Nearest(t *testing.T) { +func init() { img.Set(1, 1, color.White) +} +func Test_Nearest(t *testing.T) { m := Resize(6, 0, img, NearestNeighbor) - if m.At(2, 2) != m.At(3, 3) { t.Fail() } @@ -40,3 +41,8 @@ func Test_ZeroImg(t *testing.T) { t.Fail() } } + +func Benchmark_BigResize(b *testing.B) { + m := Resize(1000, 1000, img, Lanczos3) + m.At(0, 0) +}