resize_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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(2, 2) == m.At(3, 3) {
  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 Benchmark_BigResize(b *testing.B) {
  39. var m image.Image
  40. for i := 0; i < b.N; i++ {
  41. m = Resize(1000, 1000, img, Lanczos3)
  42. }
  43. m.At(0, 0)
  44. }
  45. func Benchmark_Reduction(b *testing.B) {
  46. largeImg := image.NewRGBA(image.Rect(0, 0, 1000, 1000))
  47. var m image.Image
  48. for i := 0; i < b.N; i++ {
  49. m = Resize(300, 300, largeImg, Bicubic)
  50. }
  51. m.At(0, 0)
  52. }