2012-08-02 21:59:40 +02:00
|
|
|
package resize
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
|
|
|
"image/color"
|
2012-09-19 19:32:00 +02:00
|
|
|
"runtime"
|
2012-08-02 21:59:40 +02:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2012-08-03 18:12:26 +02:00
|
|
|
var img = image.NewGray16(image.Rect(0, 0, 3, 3))
|
|
|
|
|
2012-09-01 00:21:10 +02:00
|
|
|
func init() {
|
2012-09-19 19:32:00 +02:00
|
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
2012-08-03 18:12:26 +02:00
|
|
|
img.Set(1, 1, color.White)
|
2012-09-01 00:21:10 +02:00
|
|
|
}
|
2012-08-03 18:12:26 +02:00
|
|
|
|
2012-09-01 00:21:10 +02:00
|
|
|
func Test_Nearest(t *testing.T) {
|
2012-08-09 18:56:42 +02:00
|
|
|
m := Resize(6, 0, img, NearestNeighbor)
|
2012-11-28 02:38:19 +01:00
|
|
|
if m.At(1, 1) == m.At(2, 2) {
|
2012-08-03 18:12:26 +02:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_Param1(t *testing.T) {
|
2012-08-09 18:56:42 +02:00
|
|
|
m := Resize(0, 0, img, NearestNeighbor)
|
|
|
|
if m.Bounds() != img.Bounds() {
|
2012-08-03 18:12:26 +02:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_Param2(t *testing.T) {
|
2012-08-09 18:56:42 +02:00
|
|
|
m := Resize(100, 0, img, NearestNeighbor)
|
|
|
|
if m.Bounds() != image.Rect(0, 0, 100, 100) {
|
2012-08-03 18:12:26 +02:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_ZeroImg(t *testing.T) {
|
|
|
|
zeroImg := image.NewGray16(image.Rect(0, 0, 0, 0))
|
|
|
|
|
2012-08-09 18:56:42 +02:00
|
|
|
m := Resize(0, 0, zeroImg, NearestNeighbor)
|
|
|
|
if m.Bounds() != zeroImg.Bounds() {
|
2012-08-02 21:59:40 +02:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
2012-09-01 00:21:10 +02:00
|
|
|
|
2013-03-10 10:58:08 +01:00
|
|
|
func Test_CorrectResize(t *testing.T) {
|
2013-03-10 11:55:50 +01:00
|
|
|
zeroImg := image.NewGray16(image.Rect(0, 0, 256, 256))
|
2013-03-10 10:58:08 +01:00
|
|
|
|
|
|
|
m := Resize(60, 0, zeroImg, NearestNeighbor)
|
2013-03-10 11:55:50 +01:00
|
|
|
if m.Bounds() != image.Rect(0, 0, 60, 60) {
|
2013-03-10 10:58:08 +01:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-08 20:55:46 +02:00
|
|
|
func Benchmark_BigResizeLanczos3(b *testing.B) {
|
2012-09-19 19:32:00 +02:00
|
|
|
var m image.Image
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
m = Resize(1000, 1000, img, Lanczos3)
|
|
|
|
}
|
2012-09-01 00:21:10 +02:00
|
|
|
m.At(0, 0)
|
|
|
|
}
|
2012-09-19 21:03:56 +02:00
|
|
|
|
|
|
|
func Benchmark_Reduction(b *testing.B) {
|
|
|
|
largeImg := image.NewRGBA(image.Rect(0, 0, 1000, 1000))
|
|
|
|
|
|
|
|
var m image.Image
|
|
|
|
for i := 0; i < b.N; i++ {
|
2012-09-21 20:02:25 +02:00
|
|
|
m = Resize(300, 300, largeImg, Bicubic)
|
2012-09-19 21:03:56 +02:00
|
|
|
}
|
|
|
|
m.At(0, 0)
|
|
|
|
}
|
2014-01-18 11:55:34 +01:00
|
|
|
|
|
|
|
// Benchmark resize of 16 MPix jpeg image to 800px width.
|
|
|
|
func jpegThumb(b *testing.B, interp InterpolationFunction) {
|
|
|
|
input := image.NewYCbCr(image.Rect(0, 0, 4896, 3264), image.YCbCrSubsampleRatio422)
|
|
|
|
|
|
|
|
var output image.Image
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
output = Resize(800, 0, input, interp)
|
|
|
|
}
|
|
|
|
|
|
|
|
output.At(0, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Benchmark_LargeJpegThumbNearestNeighbor(b *testing.B) {
|
|
|
|
jpegThumb(b, NearestNeighbor)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Benchmark_LargeJpegThumbBilinear(b *testing.B) {
|
|
|
|
jpegThumb(b, Bilinear)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Benchmark_LargeJpegThumbBicubic(b *testing.B) {
|
|
|
|
jpegThumb(b, Bicubic)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Benchmark_LargeJpegThumbMitchellNetravali(b *testing.B) {
|
|
|
|
jpegThumb(b, MitchellNetravali)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Benchmark_LargeJpegThumbLanczos2(b *testing.B) {
|
|
|
|
jpegThumb(b, Lanczos2)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Benchmark_LargeJpegThumbLanczos3(b *testing.B) {
|
|
|
|
jpegThumb(b, Lanczos3)
|
|
|
|
}
|