Add the following code as new test e.g. subimage_test.go
(https://github.com/kjk/rez/blob/master/subimage_test.go)
package rez
import (
"image"
"testing"
)
func TestResizeSubimage(t *testing.T) {
src := readImage(t, "testdata/lenna.jpg")
src2 := toRgb(src).(*image.RGBA)
subR := image.Rect(10, 10, 340, 340)
src3 := src2.SubImage(subR)
dstRect := image.Rect(0, 0, 100, 100)
dst := image.NewRGBA(dstRect)
convert(t, dst, src3, false, NewBicubicFilter())
}
Run go test
.
The following crash will happen:
--- FAIL: TestResizeSubimage (0.01 seconds)
panic: runtime error: slice bounds out of range [recovered]
panic: runtime error: slice bounds out of range
goroutine 9262 [running]:
runtime.panic(0x186200, 0x2999af)
/usr/local/Cellar/go/1.3/libexec/src/pkg/runtime/panic.c:279 +0xf5
testing.func·006()
/usr/local/Cellar/go/1.3/libexec/src/pkg/testing/testing.go:416 +0x176
runtime.panic(0x186200, 0x2999af)
/usr/local/Cellar/go/1.3/libexec/src/pkg/runtime/panic.c:248 +0x18d
github.com/kjk/rez.getRgbPlane(0x208324040, 0x208310510, 0x0, 0x0, 0x0)
/Users/kkowalczyk/src/go/src/github.com/kjk/rez/image.go:373 +0x1d6
github.com/kjk/rez.inspectRgb(0x208324040, 0x2208301800, 0x208324040, 0x0, 0x0, 0x0)
/Users/kkowalczyk/src/go/src/github.com/kjk/rez/image.go:384 +0xb2
github.com/kjk/rez.inspect(0x2208301838, 0x208324040, 0x208324000, 0x22082f2900, 0x0, 0x0, 0x0, 0x0, 0x0)
/Users/kkowalczyk/src/go/src/github.com/kjk/rez/image.go:314 +0xd5
github.com/kjk/rez.PrepareConversion(0x2208301838, 0x208324640, 0x2208301838, 0x208324040, 0x24a4b, 0x0, 0x0)
/Users/kkowalczyk/src/go/src/github.com/kjk/rez/image.go:432 +0x59
github.com/kjk/rez.prepare(0x22082fe6d0, 0x208336090, 0x2208301838, 0x208324640, 0x2208301838, 0x208324040, 0x208324600, 0x22082fe618, 0x208324680, 0x0, ...)
/Users/kkowalczyk/src/go/src/github.com/kjk/rez/resize_test.go:53 +0x68
github.com/kjk/rez.convert(0x22082fe6d0, 0x208336090, 0x2208301838, 0x208324640, 0x2208301838, 0x208324040, 0x0, 0x22082fe618, 0x208324680)
/Users/kkowalczyk/src/go/src/github.com/kjk/rez/resize_test.go:62 +0x97
github.com/kjk/rez.TestResizeSubimage(0x208336090)
/Users/kkowalczyk/src/go/src/github.com/kjk/rez/subimage_test.go:20 +0x3d0
testing.tRunner(0x208336090, 0x2980b0)
/usr/local/Cellar/go/1.3/libexec/src/pkg/testing/testing.go:422 +0x8b
created by testing.RunTests
/usr/local/Cellar/go/1.3/libexec/src/pkg/testing/testing.go:504 +0x8db
In my code I did work-around this by copying the part I want to resize to a new image, but the additional allocation and copying slows things down.
I guess the issue is with not handling image bounds that have origin point other than (0,0)