Return input image if output dimensions equal input dimensions.
This commit is contained in:
parent
7e2ce0a2ea
commit
9485f5475a
|
@ -86,6 +86,12 @@ func Resize(width, height uint, img image.Image, interp InterpolationFunction) i
|
||||||
if height == 0 {
|
if height == 0 {
|
||||||
height = uint(0.7 + float64(img.Bounds().Dy())/scaleY)
|
height = uint(0.7 + float64(img.Bounds().Dy())/scaleY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trivial case: return input image
|
||||||
|
if int(width) == img.Bounds().Dx() && int(height) == img.Bounds().Dy() {
|
||||||
|
return img
|
||||||
|
}
|
||||||
|
|
||||||
if interp == NearestNeighbor {
|
if interp == NearestNeighbor {
|
||||||
return resizeNearest(width, height, scaleX, scaleY, img, interp)
|
return resizeNearest(width, height, scaleX, scaleY, img, interp)
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,21 @@ func Test_Bounds(t *testing.T) {
|
||||||
out.At(0, 0)
|
out.At(0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_SameSizeReturnsOriginal(t *testing.T) {
|
||||||
|
img := image.NewRGBA(image.Rect(0, 0, 10, 10))
|
||||||
|
out := Resize(0, 0, img, Lanczos2)
|
||||||
|
|
||||||
|
if img != out {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
|
out = Resize(10, 10, img, Lanczos2)
|
||||||
|
|
||||||
|
if img != out {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Benchmark_BigResizeLanczos3(b *testing.B) {
|
func Benchmark_BigResizeLanczos3(b *testing.B) {
|
||||||
var m image.Image
|
var m image.Image
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user