123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645 |
- package imaging
- import (
- "image"
- "image/color"
- "testing"
- )
- func TestFlipH(t *testing.T) {
- testCases := []struct {
- name string
- src image.Image
- want *image.NRGBA
- }{
- {
- "FlipH 2x3",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 1, 2),
- Stride: 2 * 4,
- Pix: []uint8{
- 0x00, 0x11, 0x22, 0x33, 0xcc, 0xdd, 0xee, 0xff,
- 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00,
- 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff,
- },
- },
- &image.NRGBA{
- Rect: image.Rect(0, 0, 2, 3),
- Stride: 2 * 4,
- Pix: []uint8{
- 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33,
- 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00,
- },
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- got := FlipH(tc.src)
- if !compareNRGBA(got, tc.want, 0) {
- t.Fatalf("got result %#v want %#v", got, tc.want)
- }
- })
- }
- }
- func BenchmarkFlipH(b *testing.B) {
- b.ReportAllocs()
- for i := 0; i < b.N; i++ {
- FlipH(testdataBranchesJPG)
- }
- }
- func TestFlipV(t *testing.T) {
- testCases := []struct {
- name string
- src image.Image
- want *image.NRGBA
- }{
- {
- "FlipV 2x3",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 1, 2),
- Stride: 2 * 4,
- Pix: []uint8{
- 0x00, 0x11, 0x22, 0x33, 0xcc, 0xdd, 0xee, 0xff,
- 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00,
- 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff,
- },
- },
- &image.NRGBA{
- Rect: image.Rect(0, 0, 2, 3),
- Stride: 2 * 4,
- Pix: []uint8{
- 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff,
- 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00,
- 0x00, 0x11, 0x22, 0x33, 0xcc, 0xdd, 0xee, 0xff,
- },
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- got := FlipV(tc.src)
- if !compareNRGBA(got, tc.want, 0) {
- t.Fatalf("got result %#v want %#v", got, tc.want)
- }
- })
- }
- }
- func BenchmarkFlipV(b *testing.B) {
- b.ReportAllocs()
- for i := 0; i < b.N; i++ {
- FlipV(testdataBranchesJPG)
- }
- }
- func TestTranspose(t *testing.T) {
- testCases := []struct {
- name string
- src image.Image
- want *image.NRGBA
- }{
- {
- "Transpose 2x3",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 1, 2),
- Stride: 2 * 4,
- Pix: []uint8{
- 0x00, 0x11, 0x22, 0x33, 0xcc, 0xdd, 0xee, 0xff,
- 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00,
- 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff,
- },
- },
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0x00, 0x11, 0x22, 0x33, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00,
- 0xcc, 0xdd, 0xee, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
- },
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- got := Transpose(tc.src)
- if !compareNRGBA(got, tc.want, 0) {
- t.Fatalf("got result %#v want %#v", got, tc.want)
- }
- })
- }
- }
- func BenchmarkTranspose(b *testing.B) {
- b.ReportAllocs()
- for i := 0; i < b.N; i++ {
- Transpose(testdataBranchesJPG)
- }
- }
- func TestTransverse(t *testing.T) {
- testCases := []struct {
- name string
- src image.Image
- want *image.NRGBA
- }{
- {
- "Transverse 2x3",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 1, 2),
- Stride: 2 * 4,
- Pix: []uint8{
- 0x00, 0x11, 0x22, 0x33, 0xcc, 0xdd, 0xee, 0xff,
- 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00,
- 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff,
- },
- },
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xcc, 0xdd, 0xee, 0xff,
- 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x11, 0x22, 0x33,
- },
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- got := Transverse(tc.src)
- if !compareNRGBA(got, tc.want, 0) {
- t.Fatalf("got result %#v want %#v", got, tc.want)
- }
- })
- }
- }
- func BenchmarkTransverse(b *testing.B) {
- b.ReportAllocs()
- for i := 0; i < b.N; i++ {
- Transverse(testdataBranchesJPG)
- }
- }
- func TestRotate90(t *testing.T) {
- testCases := []struct {
- name string
- src image.Image
- want *image.NRGBA
- }{
- {
- "Rotate90 2x3",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 1, 2),
- Stride: 2 * 4,
- Pix: []uint8{
- 0x00, 0x11, 0x22, 0x33, 0xcc, 0xdd, 0xee, 0xff,
- 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00,
- 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff,
- },
- },
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0xdd, 0xee, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
- 0x00, 0x11, 0x22, 0x33, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00,
- },
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- got := Rotate90(tc.src)
- if !compareNRGBA(got, tc.want, 0) {
- t.Fatalf("got result %#v want %#v", got, tc.want)
- }
- })
- }
- }
- func BenchmarkRotate90(b *testing.B) {
- b.ReportAllocs()
- for i := 0; i < b.N; i++ {
- Rotate90(testdataBranchesJPG)
- }
- }
- func TestRotate180(t *testing.T) {
- testCases := []struct {
- name string
- src image.Image
- want *image.NRGBA
- }{
- {
- "Rotate180 2x3",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 1, 2),
- Stride: 2 * 4,
- Pix: []uint8{
- 0x00, 0x11, 0x22, 0x33, 0xcc, 0xdd, 0xee, 0xff,
- 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00,
- 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff,
- },
- },
- &image.NRGBA{
- Rect: image.Rect(0, 0, 2, 3),
- Stride: 2 * 4,
- Pix: []uint8{
- 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00,
- 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
- 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33,
- },
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- got := Rotate180(tc.src)
- if !compareNRGBA(got, tc.want, 0) {
- t.Fatalf("got result %#v want %#v", got, tc.want)
- }
- })
- }
- }
- func BenchmarkRotate180(b *testing.B) {
- b.ReportAllocs()
- for i := 0; i < b.N; i++ {
- Rotate180(testdataBranchesJPG)
- }
- }
- func TestRotate270(t *testing.T) {
- testCases := []struct {
- name string
- src image.Image
- want *image.NRGBA
- }{
- {
- "Rotate270 2x3",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 1, 2),
- Stride: 2 * 4,
- Pix: []uint8{
- 0x00, 0x11, 0x22, 0x33, 0xcc, 0xdd, 0xee, 0xff,
- 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00,
- 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff,
- },
- },
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x11, 0x22, 0x33,
- 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xcc, 0xdd, 0xee, 0xff,
- },
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- got := Rotate270(tc.src)
- if !compareNRGBA(got, tc.want, 0) {
- t.Fatalf("got result %#v want %#v", got, tc.want)
- }
- })
- }
- }
- func BenchmarkRotate270(b *testing.B) {
- b.ReportAllocs()
- for i := 0; i < b.N; i++ {
- Rotate270(testdataBranchesJPG)
- }
- }
- func TestRotate(t *testing.T) {
- testCases := []struct {
- name string
- src image.Image
- angle float64
- bg color.Color
- want *image.NRGBA
- }{
- {
- "Rotate 0",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 3, 3),
- Stride: 4 * 4,
- Pix: []uint8{
- 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
- 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 0,
- color.Black,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 4, 4),
- Stride: 4 * 4,
- Pix: []uint8{
- 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
- 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- {
- "Rotate 90",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 3, 3),
- Stride: 4 * 4,
- Pix: []uint8{
- 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
- 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 90,
- color.Black,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 4, 4),
- Stride: 4 * 4,
- Pix: []uint8{
- 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- {
- "Rotate 180",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 3, 3),
- Stride: 4 * 4,
- Pix: []uint8{
- 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
- 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 180,
- color.Black,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 4, 4),
- Stride: 4 * 4,
- Pix: []uint8{
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff,
- 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
- },
- },
- },
- {
- "Rotate 45",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 3, 3),
- Stride: 4 * 4,
- Pix: []uint8{
- 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
- 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 45,
- color.Black,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 6, 6),
- Stride: 6 * 4,
- Pix: []uint8{
- 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x61, 0x00, 0x00, 0xff, 0x58, 0x08, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x61, 0x00, 0x00, 0xff, 0xe9, 0x16, 0x00, 0xff, 0x35, 0xca, 0x00, 0xff, 0x00, 0x30, 0x30, 0xff, 0x00, 0x00, 0x00, 0xff,
- 0x61, 0x00, 0x00, 0xff, 0xe9, 0x16, 0x00, 0xff, 0x35, 0xca, 0x00, 0xff, 0x00, 0x80, 0x80, 0xff, 0x35, 0x35, 0xff, 0xff, 0x58, 0x58, 0x61, 0xff,
- 0x58, 0x08, 0x00, 0xff, 0x35, 0xca, 0x00, 0xff, 0x00, 0x80, 0x80, 0xff, 0x35, 0x35, 0xff, 0xff, 0xe9, 0xe9, 0xff, 0xff, 0x61, 0x61, 0x61, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x00, 0x30, 0x30, 0xff, 0x35, 0x35, 0xff, 0xff, 0xe9, 0xe9, 0xff, 0xff, 0x61, 0x61, 0x61, 0xff, 0x00, 0x00, 0x00, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x58, 0x58, 0x61, 0xff, 0x61, 0x61, 0x61, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff,
- },
- },
- },
- {
- "Rotate 0x0",
- &image.NRGBA{
- Rect: image.Rect(0, 0, 0, 0),
- Stride: 0,
- Pix: []uint8{},
- },
- 123,
- color.Black,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 0, 0),
- Stride: 0,
- Pix: []uint8{},
- },
- },
- {
- "Rotate -90",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 0, 1),
- Stride: 1 * 4,
- Pix: []uint8{
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0x00, 0xff,
- },
- },
- -90,
- color.Black,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 2, 1),
- Stride: 2 * 4,
- Pix: []uint8{
- 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
- },
- },
- },
- {
- "Rotate -360*10",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 0, 1),
- Stride: 1 * 4,
- Pix: []uint8{
- 0x00, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0x00, 0xff,
- },
- },
- -360 * 10,
- color.Black,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 1, 2),
- Stride: 1 * 4,
- Pix: []uint8{
- 0x00, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0x00, 0xff,
- },
- },
- },
- {
- "Rotate -360*10 + 90",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 0, 1),
- Stride: 1 * 4,
- Pix: []uint8{
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0x00, 0xff,
- },
- },
- -360*10 + 90,
- color.Black,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 2, 1),
- Stride: 2 * 4,
- Pix: []uint8{
- 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
- },
- },
- },
- {
- "Rotate -360*10 + 180",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 0, 1),
- Stride: 1 * 4,
- Pix: []uint8{
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0x00, 0xff,
- },
- },
- -360*10 + 180,
- color.Black,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 1, 2),
- Stride: 1 * 4,
- Pix: []uint8{
- 0x00, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0x00, 0xff,
- },
- },
- },
- {
- "Rotate -360*10 + 270",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 0, 1),
- Stride: 1 * 4,
- Pix: []uint8{
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0x00, 0xff,
- },
- },
- -360*10 + 270,
- color.Black,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 2, 1),
- Stride: 2 * 4,
- Pix: []uint8{
- 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
- },
- },
- },
- {
- "Rotate 360*10",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 0, 1),
- Stride: 1 * 4,
- Pix: []uint8{
- 0x00, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0x00, 0xff,
- },
- },
- 360 * 10,
- color.Black,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 1, 2),
- Stride: 1 * 4,
- Pix: []uint8{
- 0x00, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0x00, 0xff,
- },
- },
- },
- {
- "Rotate 360*10 + 90",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 0, 1),
- Stride: 1 * 4,
- Pix: []uint8{
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0x00, 0xff,
- },
- },
- 360*10 + 90,
- color.Black,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 2, 1),
- Stride: 2 * 4,
- Pix: []uint8{
- 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
- },
- },
- },
- {
- "Rotate 360*10 + 180",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 0, 1),
- Stride: 1 * 4,
- Pix: []uint8{
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0x00, 0xff,
- },
- },
- 360*10 + 180,
- color.Black,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 1, 2),
- Stride: 1 * 4,
- Pix: []uint8{
- 0x00, 0xff, 0x00, 0xff,
- 0xff, 0x00, 0x00, 0xff,
- },
- },
- },
- {
- "Rotate 360*10 + 270",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 0, 1),
- Stride: 1 * 4,
- Pix: []uint8{
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0x00, 0xff,
- },
- },
- 360*10 + 270,
- color.Black,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 2, 1),
- Stride: 2 * 4,
- Pix: []uint8{
- 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
- },
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- got := Rotate(tc.src, tc.angle, tc.bg)
- if !compareNRGBA(got, tc.want, 0) {
- t.Fatalf("got result %#v want %#v", got, tc.want)
- }
- })
- }
- }
- func BenchmarkRotate(b *testing.B) {
- b.ReportAllocs()
- for i := 0; i < b.N; i++ {
- Rotate(testdataBranchesJPG, 30, color.Transparent)
- }
- }
|