Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions transform/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type ResampleFilter struct {
// NearestNeighbor resampling filter assigns to each point the sample point nearest to it.
var NearestNeighbor ResampleFilter

// Box resampling filter, only let pass values in the x < 0.5 range from sample.
// Box resampling filter, only let pass values in the x <= 0.5 range from sample.
// It produces similar results to the Nearest Neighbor method.
var Box ResampleFilter

Expand Down Expand Up @@ -47,7 +47,7 @@ func init() {
Box = ResampleFilter{
Support: 0.5,
Fn: func(x float64) float64 {
if math.Abs(x) < 0.5 {
if math.Abs(x) <= 0.5 {
return 1
}
return 0
Expand Down
33 changes: 33 additions & 0 deletions transform/resize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,39 @@ func TestResizeBox(t *testing.T) {
}
}

func TestResizeBoxHalfwaySample(t *testing.T) {
cases := []struct {
name string
width int
height int
}{
{name: "x1.5", width: 3, height: 3},
{name: "x2.5", width: 5, height: 5},
{name: "x3.5", width: 7, height: 7},
}

img := &image.RGBA{
Stride: 2 * 4,
Rect: image.Rect(0, 0, 2, 2),
Pix: []uint8{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
},
}

for _, c := range cases {
expected := image.NewRGBA(image.Rect(0, 0, c.width, c.height))
for i := range expected.Pix {
expected.Pix[i] = 0xFF
}

actual := Resize(img, c.width, c.height, Box)
if !util.RGBAImageEqual(actual, expected) {
t.Errorf("%s: expected: %#v, actual: %#v", "ResizeBox "+c.name, util.RGBAToString(expected), util.RGBAToString(actual))
}
}
}

func TestResizeLinear(t *testing.T) {
cases := []struct {
name string
Expand Down