github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/gift/transform_test.go (about)

     1  package gift
     2  
     3  import (
     4  	"image"
     5  	"image/color"
     6  	"testing"
     7  )
     8  
     9  func comparePix(p1, p2 []uint8) bool {
    10  	if len(p1) != len(p2) {
    11  		return false
    12  	}
    13  	for i := 0; i < len(p1); i++ {
    14  		if p1[i] != p2[i] {
    15  			return false
    16  		}
    17  	}
    18  	return true
    19  }
    20  
    21  func TestRotate90(t *testing.T) {
    22  	img0 := image.NewGray(image.Rect(-1, -1, 3, 1))
    23  	img0.Pix = []uint8{
    24  		1, 2, 3, 4,
    25  		5, 6, 7, 8,
    26  	}
    27  	img1Exp := image.NewGray(image.Rect(0, 0, 2, 4))
    28  	img1Exp.Pix = []uint8{
    29  		4, 8,
    30  		3, 7,
    31  		2, 6,
    32  		1, 5,
    33  	}
    34  
    35  	f := Rotate90()
    36  	img1 := image.NewGray(f.Bounds(img0.Bounds()))
    37  	f.Draw(img1, img0, nil)
    38  
    39  	if img1.Bounds().Size() != img1Exp.Bounds().Size() {
    40  		t.Errorf("expected %v got %v", img1Exp.Bounds().Size(), img1.Bounds().Size())
    41  	}
    42  	if !comparePix(img1Exp.Pix, img1.Pix) {
    43  		t.Errorf("expected %v got %v", img1Exp.Pix, img1.Pix)
    44  	}
    45  }
    46  
    47  func TestRotate180(t *testing.T) {
    48  	img0 := image.NewGray(image.Rect(-1, -1, 3, 1))
    49  	img0.Pix = []uint8{
    50  		1, 2, 3, 4,
    51  		5, 6, 7, 8,
    52  	}
    53  	img1Exp := image.NewGray(image.Rect(0, 0, 4, 2))
    54  	img1Exp.Pix = []uint8{
    55  		8, 7, 6, 5,
    56  		4, 3, 2, 1,
    57  	}
    58  
    59  	f := Rotate180()
    60  	img1 := image.NewGray(f.Bounds(img0.Bounds()))
    61  	f.Draw(img1, img0, nil)
    62  
    63  	if img1.Bounds().Size() != img1Exp.Bounds().Size() {
    64  		t.Errorf("expected %v got %v", img1Exp.Bounds().Size(), img1.Bounds().Size())
    65  	}
    66  	if !comparePix(img1Exp.Pix, img1.Pix) {
    67  		t.Errorf("expected %v got %v", img1Exp.Pix, img1.Pix)
    68  	}
    69  }
    70  
    71  func TestRotate270(t *testing.T) {
    72  	img0 := image.NewGray(image.Rect(-1, -1, 3, 1))
    73  	img0.Pix = []uint8{
    74  		1, 2, 3, 4,
    75  		5, 6, 7, 8,
    76  	}
    77  	img1Exp := image.NewGray(image.Rect(0, 0, 2, 4))
    78  	img1Exp.Pix = []uint8{
    79  		5, 1,
    80  		6, 2,
    81  		7, 3,
    82  		8, 4,
    83  	}
    84  
    85  	f := Rotate270()
    86  	img1 := image.NewGray(f.Bounds(img0.Bounds()))
    87  	f.Draw(img1, img0, nil)
    88  
    89  	if img1.Bounds().Size() != img1Exp.Bounds().Size() {
    90  		t.Errorf("expected %v got %v", img1Exp.Bounds().Size(), img1.Bounds().Size())
    91  	}
    92  	if !comparePix(img1Exp.Pix, img1.Pix) {
    93  		t.Errorf("expected %v got %v", img1Exp.Pix, img1.Pix)
    94  	}
    95  }
    96  
    97  func TestFlipHorizontal(t *testing.T) {
    98  	img0 := image.NewGray(image.Rect(-1, -1, 3, 1))
    99  	img0.Pix = []uint8{
   100  		1, 2, 3, 4,
   101  		5, 6, 7, 8,
   102  	}
   103  	img1Exp := image.NewGray(image.Rect(0, 0, 4, 2))
   104  	img1Exp.Pix = []uint8{
   105  		4, 3, 2, 1,
   106  		8, 7, 6, 5,
   107  	}
   108  
   109  	f := FlipHorizontal()
   110  	img1 := image.NewGray(f.Bounds(img0.Bounds()))
   111  	f.Draw(img1, img0, nil)
   112  
   113  	if img1.Bounds().Size() != img1Exp.Bounds().Size() {
   114  		t.Errorf("expected %v got %v", img1Exp.Bounds().Size(), img1.Bounds().Size())
   115  	}
   116  	if !comparePix(img1Exp.Pix, img1.Pix) {
   117  		t.Errorf("expected %v got %v", img1Exp.Pix, img1.Pix)
   118  	}
   119  }
   120  
   121  func TestFlipVertical(t *testing.T) {
   122  	img0 := image.NewGray(image.Rect(-1, -1, 3, 1))
   123  	img0.Pix = []uint8{
   124  		1, 2, 3, 4,
   125  		5, 6, 7, 8,
   126  	}
   127  	img1Exp := image.NewGray(image.Rect(0, 0, 4, 2))
   128  	img1Exp.Pix = []uint8{
   129  		5, 6, 7, 8,
   130  		1, 2, 3, 4,
   131  	}
   132  
   133  	f := FlipVertical()
   134  	img1 := image.NewGray(f.Bounds(img0.Bounds()))
   135  	f.Draw(img1, img0, nil)
   136  
   137  	if img1.Bounds().Size() != img1Exp.Bounds().Size() {
   138  		t.Errorf("expected %v got %v", img1Exp.Bounds().Size(), img1.Bounds().Size())
   139  	}
   140  	if !comparePix(img1Exp.Pix, img1.Pix) {
   141  		t.Errorf("expected %v got %v", img1Exp.Pix, img1.Pix)
   142  	}
   143  }
   144  
   145  func TestTranspose(t *testing.T) {
   146  	img0 := image.NewGray(image.Rect(-1, -1, 3, 1))
   147  	img0.Pix = []uint8{
   148  		1, 2, 3, 4,
   149  		5, 6, 7, 8,
   150  	}
   151  	img1Exp := image.NewGray(image.Rect(0, 0, 2, 4))
   152  	img1Exp.Pix = []uint8{
   153  		1, 5,
   154  		2, 6,
   155  		3, 7,
   156  		4, 8,
   157  	}
   158  
   159  	f := Transpose()
   160  	img1 := image.NewGray(f.Bounds(img0.Bounds()))
   161  	f.Draw(img1, img0, nil)
   162  
   163  	if img1.Bounds().Size() != img1Exp.Bounds().Size() {
   164  		t.Errorf("expected %v got %v", img1Exp.Bounds().Size(), img1.Bounds().Size())
   165  	}
   166  	if !comparePix(img1Exp.Pix, img1.Pix) {
   167  		t.Errorf("expected %v got %v", img1Exp.Pix, img1.Pix)
   168  	}
   169  }
   170  
   171  func TestTransverse(t *testing.T) {
   172  	img0 := image.NewGray(image.Rect(-1, -1, 3, 1))
   173  	img0.Pix = []uint8{
   174  		1, 2, 3, 4,
   175  		5, 6, 7, 8,
   176  	}
   177  	img1Exp := image.NewGray(image.Rect(0, 0, 2, 4))
   178  	img1Exp.Pix = []uint8{
   179  		8, 4,
   180  		7, 3,
   181  		6, 2,
   182  		5, 1,
   183  	}
   184  
   185  	f := Transverse()
   186  	img1 := image.NewGray(f.Bounds(img0.Bounds()))
   187  	f.Draw(img1, img0, nil)
   188  
   189  	if img1.Bounds().Size() != img1Exp.Bounds().Size() {
   190  		t.Errorf("expected %v got %v", img1Exp.Bounds().Size(), img1.Bounds().Size())
   191  	}
   192  	if !comparePix(img1Exp.Pix, img1.Pix) {
   193  		t.Errorf("expected %v got %v", img1Exp.Pix, img1.Pix)
   194  	}
   195  }
   196  
   197  func TestCrop(t *testing.T) {
   198  	testData := []struct {
   199  		desc           string
   200  		r              image.Rectangle
   201  		srcb, dstb     image.Rectangle
   202  		srcPix, dstPix []uint8
   203  	}{
   204  		{
   205  			"crop (0, 0, 0, 0)",
   206  			image.Rect(0, 0, 0, 0),
   207  			image.Rect(-1, -1, 4, 2),
   208  			image.Rect(0, 0, 0, 0),
   209  			[]uint8{
   210  				0x00, 0x40, 0x00, 0x40, 0x00,
   211  				0x60, 0xB0, 0xA0, 0xB0, 0x60,
   212  				0x00, 0x80, 0x00, 0x80, 0x00,
   213  			},
   214  			[]uint8{},
   215  		},
   216  		{
   217  			"crop (1, 1, -1, -1)",
   218  			image.Rectangle{image.Pt(1, 1), image.Pt(-1, -1)},
   219  			image.Rect(-1, -1, 4, 2),
   220  			image.Rect(0, 0, 0, 0),
   221  			[]uint8{
   222  				0x00, 0x40, 0x00, 0x40, 0x00,
   223  				0x60, 0xB0, 0xA0, 0xB0, 0x60,
   224  				0x00, 0x80, 0x00, 0x80, 0x00,
   225  			},
   226  			[]uint8{},
   227  		},
   228  		{
   229  			"crop (-1, 0, 3, 2)",
   230  			image.Rect(-1, 0, 3, 2),
   231  			image.Rect(-1, -1, 4, 2),
   232  			image.Rect(0, 0, 4, 2),
   233  			[]uint8{
   234  				0x00, 0x40, 0x00, 0x40, 0x00,
   235  				0x60, 0xB0, 0xA0, 0xB0, 0x60,
   236  				0x00, 0x80, 0x00, 0x80, 0x00,
   237  			},
   238  			[]uint8{
   239  				0x60, 0xB0, 0xA0, 0xB0,
   240  				0x00, 0x80, 0x00, 0x80,
   241  			},
   242  		},
   243  		{
   244  			"crop (-100, -100, 2, 2)",
   245  			image.Rect(-100, -100, 2, 2),
   246  			image.Rect(-1, -1, 4, 2),
   247  			image.Rect(0, 0, 3, 3),
   248  			[]uint8{
   249  				0x00, 0x40, 0x00, 0x40, 0x00,
   250  				0x60, 0xB0, 0xA0, 0xB0, 0x60,
   251  				0x00, 0x80, 0x00, 0x80, 0x00,
   252  			},
   253  			[]uint8{
   254  				0x00, 0x40, 0x00,
   255  				0x60, 0xB0, 0xA0,
   256  				0x00, 0x80, 0x00,
   257  			},
   258  		},
   259  		{
   260  			"crop (-100, -100, 100, 100)",
   261  			image.Rect(-100, -100, 100, 100),
   262  			image.Rect(-1, -1, 4, 2),
   263  			image.Rect(0, 0, 5, 3),
   264  			[]uint8{
   265  				0x00, 0x40, 0x00, 0x40, 0x00,
   266  				0x60, 0xB0, 0xA0, 0xB0, 0x60,
   267  				0x00, 0x80, 0x00, 0x80, 0x00,
   268  			},
   269  			[]uint8{
   270  				0x00, 0x40, 0x00, 0x40, 0x00,
   271  				0x60, 0xB0, 0xA0, 0xB0, 0x60,
   272  				0x00, 0x80, 0x00, 0x80, 0x00,
   273  			},
   274  		},
   275  	}
   276  
   277  	for _, d := range testData {
   278  		src := image.NewGray(d.srcb)
   279  		src.Pix = d.srcPix
   280  
   281  		f := Crop(d.r)
   282  		dst := image.NewGray(f.Bounds(src.Bounds()))
   283  		f.Draw(dst, src, nil)
   284  
   285  		if !checkBoundsAndPix(dst.Bounds(), d.dstb, dst.Pix, d.dstPix) {
   286  			t.Errorf("test [%s] failed: %#v, %#v", d.desc, dst.Bounds(), dst.Pix)
   287  		}
   288  	}
   289  }
   290  
   291  func TestCropToSize(t *testing.T) {
   292  	testData := []struct {
   293  		desc           string
   294  		w, h           int
   295  		anchor         Anchor
   296  		srcb, dstb     image.Rectangle
   297  		srcPix, dstPix []uint8
   298  	}{
   299  		{
   300  			"crop to size (0, 0, center)",
   301  			0, 0, CenterAnchor,
   302  			image.Rect(-1, -1, 4, 4),
   303  			image.Rect(0, 0, 0, 0),
   304  			[]uint8{
   305  				0x00, 0x01, 0x02, 0x03, 0x04,
   306  				0x05, 0x06, 0x07, 0x08, 0x09,
   307  				0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
   308  				0x0f, 0x10, 0x11, 0x12, 0x13,
   309  				0x14, 0x15, 0x16, 0x17, 0x18,
   310  			},
   311  			[]uint8{},
   312  		},
   313  		{
   314  			"crop to size (3, 3, center)",
   315  			3, 3, CenterAnchor,
   316  			image.Rect(-1, -1, 4, 4),
   317  			image.Rect(0, 0, 3, 3),
   318  			[]uint8{
   319  				0x00, 0x01, 0x02, 0x03, 0x04,
   320  				0x05, 0x06, 0x07, 0x08, 0x09,
   321  				0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
   322  				0x0f, 0x10, 0x11, 0x12, 0x13,
   323  				0x14, 0x15, 0x16, 0x17, 0x18,
   324  			},
   325  			[]uint8{
   326  				0x06, 0x07, 0x08,
   327  				0x0b, 0x0c, 0x0d,
   328  				0x10, 0x11, 0x12,
   329  			},
   330  		},
   331  		{
   332  			"crop to size (3, 3, top-left)",
   333  			3, 3, TopLeftAnchor,
   334  			image.Rect(-1, -1, 4, 4),
   335  			image.Rect(0, 0, 3, 3),
   336  			[]uint8{
   337  				0x00, 0x01, 0x02, 0x03, 0x04,
   338  				0x05, 0x06, 0x07, 0x08, 0x09,
   339  				0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
   340  				0x0f, 0x10, 0x11, 0x12, 0x13,
   341  				0x14, 0x15, 0x16, 0x17, 0x18,
   342  			},
   343  			[]uint8{
   344  				0x00, 0x01, 0x02,
   345  				0x05, 0x06, 0x07,
   346  				0x0a, 0x0b, 0x0c,
   347  			},
   348  		},
   349  		{
   350  			"crop to size (3, 3, top)",
   351  			3, 3, TopAnchor,
   352  			image.Rect(-1, -1, 4, 4),
   353  			image.Rect(0, 0, 3, 3),
   354  			[]uint8{
   355  				0x00, 0x01, 0x02, 0x03, 0x04,
   356  				0x05, 0x06, 0x07, 0x08, 0x09,
   357  				0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
   358  				0x0f, 0x10, 0x11, 0x12, 0x13,
   359  				0x14, 0x15, 0x16, 0x17, 0x18,
   360  			},
   361  			[]uint8{
   362  				0x01, 0x02, 0x03,
   363  				0x06, 0x07, 0x08,
   364  				0x0b, 0x0c, 0x0d,
   365  			},
   366  		},
   367  		{
   368  			"crop to size (3, 3,, top-right)",
   369  			3, 3, TopRightAnchor,
   370  			image.Rect(-1, -1, 4, 4),
   371  			image.Rect(0, 0, 3, 3),
   372  			[]uint8{
   373  				0x00, 0x01, 0x02, 0x03, 0x04,
   374  				0x05, 0x06, 0x07, 0x08, 0x09,
   375  				0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
   376  				0x0f, 0x10, 0x11, 0x12, 0x13,
   377  				0x14, 0x15, 0x16, 0x17, 0x18,
   378  			},
   379  			[]uint8{
   380  				0x02, 0x03, 0x04,
   381  				0x07, 0x08, 0x09,
   382  				0x0c, 0x0d, 0x0e,
   383  			},
   384  		},
   385  		{
   386  			"crop to size (3, 3, left)",
   387  			3, 3, LeftAnchor,
   388  			image.Rect(-1, -1, 4, 4),
   389  			image.Rect(0, 0, 3, 3),
   390  			[]uint8{
   391  				0x00, 0x01, 0x02, 0x03, 0x04,
   392  				0x05, 0x06, 0x07, 0x08, 0x09,
   393  				0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
   394  				0x0f, 0x10, 0x11, 0x12, 0x13,
   395  				0x14, 0x15, 0x16, 0x17, 0x18,
   396  			},
   397  			[]uint8{
   398  				0x05, 0x06, 0x07,
   399  				0x0a, 0x0b, 0x0c,
   400  				0x0f, 0x10, 0x11,
   401  			},
   402  		},
   403  		{
   404  			"crop to size (3, 3, right)",
   405  			3, 3, RightAnchor,
   406  			image.Rect(-1, -1, 4, 4),
   407  			image.Rect(0, 0, 3, 3),
   408  			[]uint8{
   409  				0x00, 0x01, 0x02, 0x03, 0x04,
   410  				0x05, 0x06, 0x07, 0x08, 0x09,
   411  				0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
   412  				0x0f, 0x10, 0x11, 0x12, 0x13,
   413  				0x14, 0x15, 0x16, 0x17, 0x18,
   414  			},
   415  			[]uint8{
   416  				0x07, 0x08, 0x09,
   417  				0x0c, 0x0d, 0x0e,
   418  				0x11, 0x12, 0x13,
   419  			},
   420  		},
   421  		{
   422  			"crop to size (3, 3, bottom-left)",
   423  			3, 3, BottomLeftAnchor,
   424  			image.Rect(-1, -1, 4, 4),
   425  			image.Rect(0, 0, 3, 3),
   426  			[]uint8{
   427  				0x00, 0x01, 0x02, 0x03, 0x04,
   428  				0x05, 0x06, 0x07, 0x08, 0x09,
   429  				0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
   430  				0x0f, 0x10, 0x11, 0x12, 0x13,
   431  				0x14, 0x15, 0x16, 0x17, 0x18,
   432  			},
   433  			[]uint8{
   434  				0x0a, 0x0b, 0x0c,
   435  				0x0f, 0x10, 0x11,
   436  				0x14, 0x15, 0x16,
   437  			},
   438  		},
   439  		{
   440  			"crop to size (3, 3, bottom)",
   441  			3, 3, BottomAnchor,
   442  			image.Rect(-1, -1, 4, 4),
   443  			image.Rect(0, 0, 3, 3),
   444  			[]uint8{
   445  				0x00, 0x01, 0x02, 0x03, 0x04,
   446  				0x05, 0x06, 0x07, 0x08, 0x09,
   447  				0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
   448  				0x0f, 0x10, 0x11, 0x12, 0x13,
   449  				0x14, 0x15, 0x16, 0x17, 0x18,
   450  			},
   451  			[]uint8{
   452  				0x0b, 0x0c, 0x0d,
   453  				0x10, 0x11, 0x12,
   454  				0x15, 0x16, 0x17,
   455  			},
   456  		},
   457  		{
   458  			"crop to size (3, 3, bottom-right)",
   459  			3, 3, BottomRightAnchor,
   460  			image.Rect(-1, -1, 4, 4),
   461  			image.Rect(0, 0, 3, 3),
   462  			[]uint8{
   463  				0x00, 0x01, 0x02, 0x03, 0x04,
   464  				0x05, 0x06, 0x07, 0x08, 0x09,
   465  				0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
   466  				0x0f, 0x10, 0x11, 0x12, 0x13,
   467  				0x14, 0x15, 0x16, 0x17, 0x18,
   468  			},
   469  			[]uint8{
   470  				0x0c, 0x0d, 0x0e,
   471  				0x11, 0x12, 0x13,
   472  				0x16, 0x17, 0x18,
   473  			},
   474  		},
   475  		{
   476  			"crop to size (100, 100, center)",
   477  			100, 100, CenterAnchor,
   478  			image.Rect(-1, -1, 4, 4),
   479  			image.Rect(0, 0, 5, 5),
   480  			[]uint8{
   481  				0x00, 0x01, 0x02, 0x03, 0x04,
   482  				0x05, 0x06, 0x07, 0x08, 0x09,
   483  				0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
   484  				0x0f, 0x10, 0x11, 0x12, 0x13,
   485  				0x14, 0x15, 0x16, 0x17, 0x18,
   486  			},
   487  			[]uint8{
   488  				0x00, 0x01, 0x02, 0x03, 0x04,
   489  				0x05, 0x06, 0x07, 0x08, 0x09,
   490  				0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
   491  				0x0f, 0x10, 0x11, 0x12, 0x13,
   492  				0x14, 0x15, 0x16, 0x17, 0x18,
   493  			},
   494  		},
   495  	}
   496  
   497  	for _, d := range testData {
   498  		src := image.NewGray(d.srcb)
   499  		src.Pix = d.srcPix
   500  
   501  		f := CropToSize(d.w, d.h, d.anchor)
   502  		dst := image.NewGray(f.Bounds(src.Bounds()))
   503  		f.Draw(dst, src, nil)
   504  
   505  		if !checkBoundsAndPix(dst.Bounds(), d.dstb, dst.Pix, d.dstPix) {
   506  			t.Errorf("test [%s] failed: %#v, %#v", d.desc, dst.Bounds(), dst.Pix)
   507  		}
   508  	}
   509  }
   510  
   511  func TestRotate(t *testing.T) {
   512  	testData := []struct {
   513  		desc           string
   514  		a              float32
   515  		bg             color.Color
   516  		interp         Interpolation
   517  		srcb, dstb     image.Rectangle
   518  		srcPix, dstPix []uint8
   519  	}{
   520  		{
   521  			"rotate 0x0 90 white nearest",
   522  			90, color.White, NearestNeighborInterpolation,
   523  			image.Rect(0, 0, 0, 0),
   524  			image.Rect(0, 0, 0, 0),
   525  			[]uint8{},
   526  			[]uint8{},
   527  		},
   528  		{
   529  			"rotate 1x1 90 white nearest",
   530  			90, color.White, NearestNeighborInterpolation,
   531  			image.Rect(-1, -1, 0, 0),
   532  			image.Rect(0, 0, 1, 1),
   533  			[]uint8{0x80},
   534  			[]uint8{0x80},
   535  		},
   536  		{
   537  			"rotate 3x3 -90 white nearest",
   538  			-90, color.White, NearestNeighborInterpolation,
   539  			image.Rect(-1, -1, 2, 2),
   540  			image.Rect(0, 0, 3, 3),
   541  			[]uint8{
   542  				0x10, 0x20, 0x30,
   543  				0x40, 0x50, 0x60,
   544  				0x70, 0x80, 0x90,
   545  			},
   546  			[]uint8{
   547  				0x70, 0x40, 0x10,
   548  				0x80, 0x50, 0x20,
   549  				0x90, 0x60, 0x30,
   550  			},
   551  		},
   552  		{
   553  			"rotate 3x3 -90 white linear",
   554  			-90, color.White, LinearInterpolation,
   555  			image.Rect(-1, -1, 2, 2),
   556  			image.Rect(0, 0, 3, 3),
   557  			[]uint8{
   558  				0x10, 0x20, 0x30,
   559  				0x40, 0x50, 0x60,
   560  				0x70, 0x80, 0x90,
   561  			},
   562  			[]uint8{
   563  				0x70, 0x40, 0x10,
   564  				0x80, 0x50, 0x20,
   565  				0x90, 0x60, 0x30,
   566  			},
   567  		},
   568  		{
   569  			"rotate 3x3 45 black nearest",
   570  			45, color.Black, NearestNeighborInterpolation,
   571  			image.Rect(-1, -1, 2, 2),
   572  			image.Rect(0, 0, 5, 5),
   573  			[]uint8{
   574  				0x10, 0x20, 0x30,
   575  				0x40, 0x50, 0x60,
   576  				0x70, 0x80, 0x90,
   577  			},
   578  			[]uint8{
   579  				0x00, 0x00, 0x30, 0x00, 0x00,
   580  				0x00, 0x20, 0x30, 0x60, 0x00,
   581  				0x10, 0x10, 0x50, 0x90, 0x90,
   582  				0x00, 0x40, 0x70, 0x80, 0x00,
   583  				0x00, 0x00, 0x70, 0x00, 0x00,
   584  			},
   585  		},
   586  		{
   587  			"rotate 5x5 45 black linear",
   588  			45, color.Black, LinearInterpolation,
   589  			image.Rect(-1, -1, 4, 4),
   590  			image.Rect(0, 0, 8, 8),
   591  			[]uint8{
   592  				0xff, 0xff, 0xff, 0xff, 0xff,
   593  				0xff, 0xff, 0xff, 0xff, 0xff,
   594  				0xff, 0xff, 0xff, 0xff, 0xff,
   595  				0xff, 0xff, 0xff, 0xff, 0xff,
   596  				0xff, 0xff, 0xff, 0xff, 0xff,
   597  			},
   598  			[]uint8{
   599  				0x00, 0x00, 0x00, 0x26, 0x26, 0x00, 0x00, 0x00,
   600  				0x00, 0x00, 0x2c, 0xe0, 0xe0, 0x2c, 0x00, 0x00,
   601  				0x00, 0x2c, 0xe0, 0xff, 0xff, 0xe0, 0x2c, 0x00,
   602  				0x26, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x26,
   603  				0x26, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x26,
   604  				0x00, 0x2c, 0xe0, 0xff, 0xff, 0xe0, 0x2c, 0x00,
   605  				0x00, 0x00, 0x2c, 0xe0, 0xe0, 0x2c, 0x00, 0x00,
   606  				0x00, 0x00, 0x00, 0x26, 0x26, 0x00, 0x00, 0x00,
   607  			},
   608  		},
   609  		{
   610  			"rotate 5x5 45 black cubic",
   611  			45, color.Black, CubicInterpolation,
   612  			image.Rect(-1, -1, 4, 4),
   613  			image.Rect(0, 0, 8, 8),
   614  			[]uint8{
   615  				0xff, 0xff, 0xff, 0xff, 0xff,
   616  				0xff, 0xff, 0xff, 0xff, 0xff,
   617  				0xff, 0xff, 0xff, 0xff, 0xff,
   618  				0xff, 0xff, 0xff, 0xff, 0xff,
   619  				0xff, 0xff, 0xff, 0xff, 0xff,
   620  			},
   621  			[]uint8{
   622  				0x00, 0x00, 0x00, 0x23, 0x23, 0x00, 0x00, 0x00,
   623  				0x00, 0x00, 0x28, 0xf1, 0xf1, 0x28, 0x00, 0x00,
   624  				0x00, 0x28, 0xe3, 0xff, 0xff, 0xe3, 0x28, 0x00,
   625  				0x23, 0xf1, 0xff, 0xff, 0xff, 0xff, 0xf1, 0x23,
   626  				0x23, 0xf1, 0xff, 0xff, 0xff, 0xff, 0xf1, 0x23,
   627  				0x00, 0x28, 0xe3, 0xff, 0xff, 0xe3, 0x28, 0x00,
   628  				0x00, 0x00, 0x28, 0xf1, 0xf1, 0x28, 0x00, 0x00,
   629  				0x00, 0x00, 0x00, 0x23, 0x23, 0x00, 0x00, 0x00,
   630  			},
   631  		},
   632  	}
   633  
   634  	for _, d := range testData {
   635  		src := image.NewGray(d.srcb)
   636  		src.Pix = d.srcPix
   637  
   638  		f := Rotate(d.a, d.bg, d.interp)
   639  		dst := image.NewGray(f.Bounds(src.Bounds()))
   640  		f.Draw(dst, src, nil)
   641  
   642  		if !checkBoundsAndPix(dst.Bounds(), d.dstb, dst.Pix, d.dstPix) {
   643  			t.Errorf("test [%s] failed: %#v, %#v", d.desc, dst.Bounds(), dst.Pix)
   644  		}
   645  	}
   646  
   647  }