mirror of
https://github.com/esimov/caire.git
synced 2025-09-27 04:45:53 +08:00
Major update -> v1.5.0
This commit is contained in:
@@ -8,8 +8,6 @@ import (
|
||||
)
|
||||
|
||||
func TestResize_ShrinkImageWidth(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight))
|
||||
var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy())
|
||||
newWidth := imgWidth / 2
|
||||
@@ -20,18 +18,19 @@ func TestResize_ShrinkImageWidth(t *testing.T) {
|
||||
for x := 0; x < newWidth; x++ {
|
||||
width, height := img.Bounds().Max.X, img.Bounds().Max.Y
|
||||
c = NewCarver(width, height)
|
||||
c.ComputeSeams(p, img)
|
||||
|
||||
_, err := c.ComputeSeams(p, img)
|
||||
assert.NoError(t, err)
|
||||
|
||||
seams := c.FindLowestEnergySeams(p)
|
||||
img = c.RemoveSeam(img, seams, p.Debug)
|
||||
}
|
||||
imgWidth := img.Bounds().Max.X
|
||||
|
||||
assert.Equal(imgWidth, newWidth)
|
||||
assert.Equal(t, imgWidth, newWidth)
|
||||
}
|
||||
|
||||
func TestResize_ShrinkImageHeight(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight))
|
||||
var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy())
|
||||
newHeight := imgHeight / 2
|
||||
@@ -39,23 +38,24 @@ func TestResize_ShrinkImageHeight(t *testing.T) {
|
||||
p.NewWidth = imgWidth
|
||||
p.NewHeight = newHeight
|
||||
|
||||
img = c.RotateImage90(img)
|
||||
img = rotateImage90(img)
|
||||
for x := 0; x < newHeight; x++ {
|
||||
width, height := img.Bounds().Max.X, img.Bounds().Max.Y
|
||||
c = NewCarver(width, height)
|
||||
c.ComputeSeams(p, img)
|
||||
|
||||
_, err := c.ComputeSeams(p, img)
|
||||
assert.NoError(t, err)
|
||||
|
||||
seams := c.FindLowestEnergySeams(p)
|
||||
img = c.RemoveSeam(img, seams, p.Debug)
|
||||
}
|
||||
img = c.RotateImage270(img)
|
||||
img = rotateImage270(img)
|
||||
imgHeight := img.Bounds().Max.Y
|
||||
|
||||
assert.Equal(imgHeight, newHeight)
|
||||
assert.Equal(t, imgHeight, newHeight)
|
||||
}
|
||||
|
||||
func TestResize_EnlargeImageWidth(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight))
|
||||
var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy())
|
||||
newWidth := imgWidth * 2
|
||||
@@ -66,18 +66,19 @@ func TestResize_EnlargeImageWidth(t *testing.T) {
|
||||
for x := 0; x < newWidth; x++ {
|
||||
width, height := img.Bounds().Max.X, img.Bounds().Max.Y
|
||||
c = NewCarver(width, height)
|
||||
c.ComputeSeams(p, img)
|
||||
|
||||
_, err := c.ComputeSeams(p, img)
|
||||
assert.NoError(t, err)
|
||||
|
||||
seams := c.FindLowestEnergySeams(p)
|
||||
img = c.AddSeam(img, seams, p.Debug)
|
||||
}
|
||||
imgWidth := img.Bounds().Max.X - img.Bounds().Dx()
|
||||
|
||||
assert.NotEqual(imgWidth, newWidth)
|
||||
assert.NotEqual(t, imgWidth, newWidth)
|
||||
}
|
||||
|
||||
func TestResize_EnlargeImageHeight(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight))
|
||||
var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy())
|
||||
newHeight := imgHeight * 2
|
||||
@@ -85,16 +86,19 @@ func TestResize_EnlargeImageHeight(t *testing.T) {
|
||||
p.NewWidth = imgWidth
|
||||
p.NewHeight = newHeight
|
||||
|
||||
img = c.RotateImage90(img)
|
||||
img = rotateImage90(img)
|
||||
for x := 0; x < newHeight; x++ {
|
||||
width, height := img.Bounds().Max.X, img.Bounds().Max.Y
|
||||
c = NewCarver(width, height)
|
||||
c.ComputeSeams(p, img)
|
||||
|
||||
_, err := c.ComputeSeams(p, img)
|
||||
assert.NoError(t, err)
|
||||
|
||||
seams := c.FindLowestEnergySeams(p)
|
||||
img = c.AddSeam(img, seams, p.Debug)
|
||||
}
|
||||
img = c.RotateImage270(img)
|
||||
img = rotateImage270(img)
|
||||
imgHeight := img.Bounds().Max.Y - img.Bounds().Dy()
|
||||
|
||||
assert.NotEqual(imgHeight, newHeight)
|
||||
assert.NotEqual(t, imgHeight, newHeight)
|
||||
}
|
||||
|
Reference in New Issue
Block a user