From 220cad3343ca3ce36ffc80f8ab21c25890a5b50d Mon Sep 17 00:00:00 2001 From: jst Date: Wed, 13 Aug 2014 20:12:18 +0200 Subject: [PATCH] Add simple test case for input image with non-trivial bounds. --- resize_test.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/resize_test.go b/resize_test.go index 283b89c..41f8f46 100644 --- a/resize_test.go +++ b/resize_test.go @@ -3,14 +3,16 @@ package resize import ( "image" "image/color" - "runtime" + "image/png" + "os" + //"runtime" "testing" ) var img = image.NewGray16(image.Rect(0, 0, 3, 3)) func init() { - runtime.GOMAXPROCS(runtime.NumCPU()) + //runtime.GOMAXPROCS(runtime.NumCPU()) img.Set(1, 1, color.White) } @@ -64,6 +66,12 @@ func Test_SameColor(t *testing.T) { } } +func Test_Bounds(t *testing.T) { + img := image.NewRGBA(image.Rect(20, 10, 200, 99)) + out := Resize(80, 80, img, Lanczos2) + out.At(0, 0) +} + func Benchmark_BigResizeLanczos3(b *testing.B) { var m image.Image for i := 0; i < b.N; i++ { @@ -117,3 +125,21 @@ func Benchmark_LargeJpegThumbLanczos2(b *testing.B) { func Benchmark_LargeJpegThumbLanczos3(b *testing.B) { jpegThumb(b, Lanczos3) } + +func Benchmark_LargeN(b *testing.B) { + file, _ := os.Open("M94A0467.png") + defer file.Close() + img, _ := png.Decode(file) + var output image.Image + + b.ResetTimer() + for i := 0; i < b.N; i++ { + output = Resize(900, 0, img, Bicubic) + } + b.StopTimer() + + output.At(0, 0) + outPng, _ := os.Create("out.png") + defer outPng.Close() + png.Encode(outPng, output) +}