diff options
author | hmhealey <harrisonmhealey@gmail.com> | 2015-09-17 11:08:47 -0400 |
---|---|---|
committer | hmhealey <harrisonmhealey@gmail.com> | 2015-09-17 19:13:42 -0400 |
commit | d83be6df2d8b0e2fef4cb6866cfdb6434bbef5c4 (patch) | |
tree | a4677163f2aa762c75988fe402b9aea89d95e0be /Godeps/_workspace/src/code.google.com/p/graphics-go/graphics/scale_test.go | |
parent | 82127341cacd4299f9a59e76b5f68d6d7222c45b (diff) | |
download | chat-d83be6df2d8b0e2fef4cb6866cfdb6434bbef5c4.tar.gz chat-d83be6df2d8b0e2fef4cb6866cfdb6434bbef5c4.tar.bz2 chat-d83be6df2d8b0e2fef4cb6866cfdb6434bbef5c4.zip |
PLT-173 Added graphics-go and goexif libraries for image manipulation
Diffstat (limited to 'Godeps/_workspace/src/code.google.com/p/graphics-go/graphics/scale_test.go')
-rw-r--r-- | Godeps/_workspace/src/code.google.com/p/graphics-go/graphics/scale_test.go | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/Godeps/_workspace/src/code.google.com/p/graphics-go/graphics/scale_test.go b/Godeps/_workspace/src/code.google.com/p/graphics-go/graphics/scale_test.go new file mode 100644 index 000000000..9c2468f11 --- /dev/null +++ b/Godeps/_workspace/src/code.google.com/p/graphics-go/graphics/scale_test.go @@ -0,0 +1,153 @@ +// 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" + "testing" + + _ "image/png" +) + +var scaleOneColorTests = []transformOneColorTest{ + { + "down-half", + 1, 1, + 2, 2, + nil, + []uint8{ + 0x80, 0x00, + 0x00, 0x80, + }, + []uint8{ + 0x40, + }, + }, + { + "up-double", + 4, 4, + 2, 2, + nil, + []uint8{ + 0x80, 0x00, + 0x00, 0x80, + }, + []uint8{ + 0x80, 0x60, 0x20, 0x00, + 0x60, 0x50, 0x30, 0x20, + 0x20, 0x30, 0x50, 0x60, + 0x00, 0x20, 0x60, 0x80, + }, + }, + { + "up-doublewidth", + 4, 2, + 2, 2, + nil, + []uint8{ + 0x80, 0x00, + 0x00, 0x80, + }, + []uint8{ + 0x80, 0x60, 0x20, 0x00, + 0x00, 0x20, 0x60, 0x80, + }, + }, + { + "up-doubleheight", + 2, 4, + 2, 2, + nil, + []uint8{ + 0x80, 0x00, + 0x00, 0x80, + }, + []uint8{ + 0x80, 0x00, + 0x60, 0x20, + 0x20, 0x60, + 0x00, 0x80, + }, + }, + { + "up-partial", + 3, 3, + 2, 2, + nil, + []uint8{ + 0x80, 0x00, + 0x00, 0x80, + }, + []uint8{ + 0x80, 0x40, 0x00, + 0x40, 0x40, 0x40, + 0x00, 0x40, 0x80, + }, + }, +} + +func TestScaleOneColor(t *testing.T) { + for _, oc := range scaleOneColorTests { + dst := oc.newDst() + src := oc.newSrc() + if err := Scale(dst, src); err != nil { + t.Errorf("scale %s: %v", oc.desc, err) + continue + } + + if !checkTransformTest(t, &oc, dst) { + continue + } + } +} + +func TestScaleEmpty(t *testing.T) { + empty := image.NewRGBA(image.Rect(0, 0, 0, 0)) + if err := Scale(empty, empty); err != nil { + t.Fatal(err) + } +} + +func TestScaleGopher(t *testing.T) { + dst := image.NewRGBA(image.Rect(0, 0, 100, 150)) + + src, err := graphicstest.LoadImage("../testdata/gopher.png") + if err != nil { + t.Error(err) + return + } + + // Down-sample. + if err := Scale(dst, src); err != nil { + t.Fatal(err) + } + cmp, err := graphicstest.LoadImage("../testdata/gopher-100x150.png") + if err != nil { + t.Error(err) + return + } + err = graphicstest.ImageWithinTolerance(dst, cmp, 0) + if err != nil { + t.Error(err) + return + } + + // Up-sample. + dst = image.NewRGBA(image.Rect(0, 0, 500, 750)) + if err := Scale(dst, src); err != nil { + t.Fatal(err) + } + cmp, err = graphicstest.LoadImage("../testdata/gopher-500x750.png") + if err != nil { + t.Error(err) + return + } + err = graphicstest.ImageWithinTolerance(dst, cmp, 0) + if err != nil { + t.Error(err) + return + } +} |