123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- // Copyright 2011 The Graphics-Go Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style
- // license that can be found in the LICENSE file.
- package graphics
- import (
- "code.google.com/p/graphics-go/graphics/graphicstest"
- "image"
- "math"
- "testing"
- _ "image/png"
- )
- var rotateOneColorTests = []transformOneColorTest{
- {
- "onepixel-onequarter", 1, 1, 1, 1,
- &RotateOptions{math.Pi / 2},
- []uint8{0xff},
- []uint8{0xff},
- },
- {
- "onepixel-partial", 1, 1, 1, 1,
- &RotateOptions{math.Pi * 2.0 / 3.0},
- []uint8{0xff},
- []uint8{0xff},
- },
- {
- "onepixel-complete", 1, 1, 1, 1,
- &RotateOptions{2 * math.Pi},
- []uint8{0xff},
- []uint8{0xff},
- },
- {
- "even-onequarter", 2, 2, 2, 2,
- &RotateOptions{math.Pi / 2.0},
- []uint8{
- 0xff, 0x00,
- 0x00, 0xff,
- },
- []uint8{
- 0x00, 0xff,
- 0xff, 0x00,
- },
- },
- {
- "even-complete", 2, 2, 2, 2,
- &RotateOptions{2.0 * math.Pi},
- []uint8{
- 0xff, 0x00,
- 0x00, 0xff,
- },
- []uint8{
- 0xff, 0x00,
- 0x00, 0xff,
- },
- },
- {
- "line-partial", 3, 3, 3, 3,
- &RotateOptions{math.Pi * 1.0 / 3.0},
- []uint8{
- 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00,
- },
- []uint8{
- 0xa2, 0x80, 0x00,
- 0x22, 0xff, 0x22,
- 0x00, 0x80, 0xa2,
- },
- },
- {
- "line-offset-partial", 3, 3, 3, 3,
- &RotateOptions{math.Pi * 3 / 2},
- []uint8{
- 0x00, 0x00, 0x00,
- 0x00, 0xff, 0xff,
- 0x00, 0x00, 0x00,
- },
- []uint8{
- 0x00, 0xff, 0x00,
- 0x00, 0xff, 0x00,
- 0x00, 0x00, 0x00,
- },
- },
- {
- "dot-partial", 4, 4, 4, 4,
- &RotateOptions{math.Pi},
- []uint8{
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0xff, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- },
- []uint8{
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xff, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- },
- },
- }
- func TestRotateOneColor(t *testing.T) {
- for _, oc := range rotateOneColorTests {
- src := oc.newSrc()
- dst := oc.newDst()
- if err := Rotate(dst, src, oc.opt.(*RotateOptions)); err != nil {
- t.Errorf("rotate %s: %v", oc.desc, err)
- continue
- }
- if !checkTransformTest(t, &oc, dst) {
- continue
- }
- }
- }
- func TestRotateEmpty(t *testing.T) {
- empty := image.NewRGBA(image.Rect(0, 0, 0, 0))
- if err := Rotate(empty, empty, nil); err != nil {
- t.Fatal(err)
- }
- }
- func TestRotateGopherSide(t *testing.T) {
- src, err := graphicstest.LoadImage("../testdata/gopher.png")
- if err != nil {
- t.Fatal(err)
- }
- srcb := src.Bounds()
- dst := image.NewRGBA(image.Rect(0, 0, srcb.Dy(), srcb.Dx()))
- if err := Rotate(dst, src, &RotateOptions{math.Pi / 2.0}); err != nil {
- t.Fatal(err)
- }
- cmp, err := graphicstest.LoadImage("../testdata/gopher-rotate-side.png")
- if err != nil {
- t.Fatal(err)
- }
- err = graphicstest.ImageWithinTolerance(dst, cmp, 0x101)
- if err != nil {
- t.Fatal(err)
- }
- }
- func TestRotateGopherPartial(t *testing.T) {
- src, err := graphicstest.LoadImage("../testdata/gopher.png")
- if err != nil {
- t.Fatal(err)
- }
- srcb := src.Bounds()
- dst := image.NewRGBA(image.Rect(0, 0, srcb.Dx(), srcb.Dy()))
- if err := Rotate(dst, src, &RotateOptions{math.Pi / 3.0}); err != nil {
- t.Fatal(err)
- }
- cmp, err := graphicstest.LoadImage("../testdata/gopher-rotate-partial.png")
- if err != nil {
- t.Fatal(err)
- }
- err = graphicstest.ImageWithinTolerance(dst, cmp, 0x101)
- if err != nil {
- t.Fatal(err)
- }
- }
|