Merge branch 'disintegration-pixel_coordinate'

This commit is contained in:
jst 2015-03-27 19:50:42 +01:00
commit ce86eacf20
2 changed files with 23 additions and 3 deletions

View File

@ -87,7 +87,7 @@ func createWeights8(dy, filterLength int, blur, scale float64, kernel func(float
coeffs := make([]int16, dy*filterLength)
start := make([]int, dy)
for y := 0; y < dy; y++ {
interpX := scale * (float64(y) + 0.5)
interpX := scale*(float64(y)+0.5) - 0.5
start[y] = int(interpX) - filterLength/2 + 1
interpX -= float64(start[y])
for i := 0; i < filterLength; i++ {
@ -107,7 +107,7 @@ func createWeights16(dy, filterLength int, blur, scale float64, kernel func(floa
coeffs := make([]int32, dy*filterLength)
start := make([]int, dy)
for y := 0; y < dy; y++ {
interpX := scale * (float64(y) + 0.5)
interpX := scale*(float64(y)+0.5) - 0.5
start[y] = int(interpX) - filterLength/2 + 1
interpX -= float64(start[y])
for i := 0; i < filterLength; i++ {
@ -126,7 +126,7 @@ func createWeightsNearest(dy, filterLength int, blur, scale float64) ([]bool, []
coeffs := make([]bool, dy*filterLength)
start := make([]int, dy)
for y := 0; y < dy; y++ {
interpX := scale * (float64(y) + 0.5)
interpX := scale*(float64(y)+0.5) - 0.5
start[y] = int(interpX) - filterLength/2 + 1
interpX -= float64(start[y])
for i := 0; i < filterLength; i++ {

View File

@ -85,6 +85,26 @@ func Test_SameSizeReturnsOriginal(t *testing.T) {
}
}
func Test_PixelCoordinates(t *testing.T) {
checkers := image.NewGray(image.Rect(0, 0, 4, 4))
checkers.Pix = []uint8{
255, 0, 255, 0,
0, 255, 0, 255,
255, 0, 255, 0,
0, 255, 0, 255,
}
resized := Resize(12, 12, checkers, NearestNeighbor).(*image.Gray)
if resized.Pix[0] != 255 || resized.Pix[1] != 255 || resized.Pix[2] != 255 {
t.Fail()
}
if resized.Pix[3] != 0 || resized.Pix[4] != 0 || resized.Pix[5] != 0 {
t.Fail()
}
}
const (
// Use a small image size for benchmarks. We don't want memory performance
// to affect the benchmark results.