123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- package imaging
- import (
- "image"
- "testing"
- )
- func TestRotate90(t *testing.T) {
- td := []struct {
- desc 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 _, d := range td {
- got := Rotate90(d.src)
- want := d.want
- if !compareNRGBA(got, want, 0) {
- t.Errorf("test [%s] failed: %#v", d.desc, got)
- }
- }
- }
- func TestRotate180(t *testing.T) {
- td := []struct {
- desc 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 _, d := range td {
- got := Rotate180(d.src)
- want := d.want
- if !compareNRGBA(got, want, 0) {
- t.Errorf("test [%s] failed: %#v", d.desc, got)
- }
- }
- }
- func TestRotate270(t *testing.T) {
- td := []struct {
- desc 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 _, d := range td {
- got := Rotate270(d.src)
- want := d.want
- if !compareNRGBA(got, want, 0) {
- t.Errorf("test [%s] failed: %#v", d.desc, got)
- }
- }
- }
- func TestFlipV(t *testing.T) {
- td := []struct {
- desc 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 _, d := range td {
- got := FlipV(d.src)
- want := d.want
- if !compareNRGBA(got, want, 0) {
- t.Errorf("test [%s] failed: %#v", d.desc, got)
- }
- }
- }
- func TestFlipH(t *testing.T) {
- td := []struct {
- desc 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 _, d := range td {
- got := FlipH(d.src)
- want := d.want
- if !compareNRGBA(got, want, 0) {
- t.Errorf("test [%s] failed: %#v", d.desc, got)
- }
- }
- }
- func TestTranspose(t *testing.T) {
- td := []struct {
- desc 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 _, d := range td {
- got := Transpose(d.src)
- want := d.want
- if !compareNRGBA(got, want, 0) {
- t.Errorf("test [%s] failed: %#v", d.desc, got)
- }
- }
- }
- func TestTransverse(t *testing.T) {
- td := []struct {
- desc 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 _, d := range td {
- got := Transverse(d.src)
- want := d.want
- if !compareNRGBA(got, want, 0) {
- t.Errorf("test [%s] failed: %#v", d.desc, got)
- }
- }
- }
|