OLD | NEW |
1 // Copyright 2013 The Go Authors. All rights reserved. | 1 // Copyright 2013 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package gif | 5 package gif |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "image" | 9 "image" |
10 "image/color" | 10 "image/color" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 95 } |
96 // Compare the average delta to the tolerance level. | 96 // Compare the average delta to the tolerance level. |
97 avgDelta := averageDelta(m0, m1) | 97 avgDelta := averageDelta(m0, m1) |
98 if avgDelta > tc.tolerance { | 98 if avgDelta > tc.tolerance { |
99 t.Errorf("%s: average delta is too high. expected: %d, g
ot %d", tc.filename, tc.tolerance, avgDelta) | 99 t.Errorf("%s: average delta is too high. expected: %d, g
ot %d", tc.filename, tc.tolerance, avgDelta) |
100 continue | 100 continue |
101 } | 101 } |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
| 105 func TestSubImage(t *testing.T) { |
| 106 m0, err := readImg("../testdata/video-001.gif") |
| 107 if err != nil { |
| 108 t.Fatalf("readImg: %v", err) |
| 109 } |
| 110 m0 = m0.(*image.Paletted).SubImage(image.Rect(0, 0, 50, 30)) |
| 111 var buf bytes.Buffer |
| 112 err = Encode(&buf, m0, nil) |
| 113 if err != nil { |
| 114 t.Fatalf("Encode: %v", err) |
| 115 } |
| 116 m1, err := Decode(&buf) |
| 117 if err != nil { |
| 118 t.Fatalf("Decode: %v", err) |
| 119 } |
| 120 if m0.Bounds() != m1.Bounds() { |
| 121 t.Fatalf("bounds differ: %v and %v", m0.Bounds(), m1.Bounds()) |
| 122 } |
| 123 if averageDelta(m0, m1) != 0 { |
| 124 t.Fatalf("images differ") |
| 125 } |
| 126 } |
| 127 |
105 var frames = []string{ | 128 var frames = []string{ |
106 "../testdata/video-001.gif", | 129 "../testdata/video-001.gif", |
107 "../testdata/video-005.gray.gif", | 130 "../testdata/video-005.gray.gif", |
108 } | 131 } |
109 | 132 |
110 func TestEncodeAll(t *testing.T) { | 133 func TestEncodeAll(t *testing.T) { |
111 g0 := &GIF{ | 134 g0 := &GIF{ |
112 Image: make([]*image.Paletted, len(frames)), | 135 Image: make([]*image.Paletted, len(frames)), |
113 Delay: make([]int, len(frames)), | 136 Delay: make([]int, len(frames)), |
114 LoopCount: 5, | 137 LoopCount: 5, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 255, | 218 255, |
196 }) | 219 }) |
197 } | 220 } |
198 } | 221 } |
199 b.SetBytes(640 * 480 * 4) | 222 b.SetBytes(640 * 480 * 4) |
200 b.StartTimer() | 223 b.StartTimer() |
201 for i := 0; i < b.N; i++ { | 224 for i := 0; i < b.N; i++ { |
202 Encode(ioutil.Discard, img, nil) | 225 Encode(ioutil.Discard, img, nil) |
203 } | 226 } |
204 } | 227 } |
OLD | NEW |