resize_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package resize
  2. import (
  3. "image"
  4. "image/color"
  5. "runtime"
  6. "testing"
  7. )
  8. var img = image.NewGray16(image.Rect(0, 0, 3, 3))
  9. func init() {
  10. runtime.GOMAXPROCS(runtime.NumCPU())
  11. img.Set(1, 1, color.White)
  12. }
  13. func Test_Nearest(t *testing.T) {
  14. m := Resize(6, 0, img, NearestNeighbor)
  15. if m.At(1, 1) == m.At(2, 2) {
  16. t.Fail()
  17. }
  18. }
  19. func Test_Param1(t *testing.T) {
  20. m := Resize(0, 0, img, NearestNeighbor)
  21. if m.Bounds() != img.Bounds() {
  22. t.Fail()
  23. }
  24. }
  25. func Test_Param2(t *testing.T) {
  26. m := Resize(100, 0, img, NearestNeighbor)
  27. if m.Bounds() != image.Rect(0, 0, 100, 100) {
  28. t.Fail()
  29. }
  30. }
  31. func Test_ZeroImg(t *testing.T) {
  32. zeroImg := image.NewGray16(image.Rect(0, 0, 0, 0))
  33. m := Resize(0, 0, zeroImg, NearestNeighbor)
  34. if m.Bounds() != zeroImg.Bounds() {
  35. t.Fail()
  36. }
  37. }
  38. func Test_CorrectResize(t *testing.T) {
  39. zeroImg := image.NewGray16(image.Rect(0, 0, 256, 256))
  40. m := Resize(60, 0, zeroImg, NearestNeighbor)
  41. if m.Bounds() != image.Rect(0, 0, 60, 60) {
  42. t.Fail()
  43. }
  44. }
  45. func Benchmark_BigResizeLanczos3(b *testing.B) {
  46. var m image.Image
  47. for i := 0; i < b.N; i++ {
  48. m = Resize(1000, 1000, img, Lanczos3)
  49. }
  50. m.At(0, 0)
  51. }
  52. func Benchmark_BigResizeLanczos3Lut(b *testing.B) {
  53. var m image.Image
  54. for i := 0; i < b.N; i++ {
  55. m = Resize(1000, 1000, img, Lanczos3Lut)
  56. }
  57. m.At(0, 0)
  58. }
  59. func Benchmark_Reduction(b *testing.B) {
  60. largeImg := image.NewRGBA(image.Rect(0, 0, 1000, 1000))
  61. var m image.Image
  62. for i := 0; i < b.N; i++ {
  63. m = Resize(300, 300, largeImg, Bicubic)
  64. }
  65. m.At(0, 0)
  66. }