Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2014 The Go Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style | |
3 // license that can be found in the LICENSE file. | |
4 | |
1 package draw | 5 package draw |
2 | 6 |
3 import ( | 7 import ( |
4 "flag" | 8 "flag" |
5 "fmt" | 9 "fmt" |
6 "image" | 10 "image" |
7 "image/png" | 11 "image/png" |
8 "os" | 12 "os" |
9 "reflect" | 13 "reflect" |
10 "testing" | 14 "testing" |
11 | 15 |
12 _ "image/jpeg" | 16 _ "image/jpeg" |
13 ) | 17 ) |
14 | 18 |
15 var genScaleFiles = flag.Bool("gen_scale_files", false, "Whether to generate the TestScaleXxx golden files.") | 19 var genScaleFiles = flag.Bool("gen_scale_files", false, "Whether to generate the TestScaleXxx golden files.") |
r
2014/07/08 19:44:54
s/W/w/
| |
16 | 20 |
17 // testScale tests that scaling the source image gives the exact destination | 21 // testScale tests that scaling the source image gives the exact destination |
18 // image. This is to ensure that any refactoring or optimization of the scaling | 22 // image. This is to ensure that any refactoring or optimization of the scaling |
19 // code doesn't change the scaling behavior. Changing the actual algorithm or | 23 // code doesn't change the scaling behavior. Changing the actual algorithm or |
20 // kernel used by any particular quality setting will obviously change the | 24 // kernel used by any particular quality setting will obviously change the |
21 // resultant pixels, and in such a case, use the gen_scale_files flag to | 25 // resultant pixels, and in such a case, use the gen_scale_files flag to |
r
2014/07/08 19:44:54
pixels. In such a case, use ...
| |
22 // regenerate the golden files. | 26 // regenerate the golden files. |
23 func testScale(t *testing.T, dstRect image.Rectangle, direction, srcFilename str ing) { | 27 func testScale(t *testing.T, dstRect image.Rectangle, direction, srcFilename str ing) { |
24 f, err := os.Open("../testdata/go-turns-two-" + srcFilename) | 28 f, err := os.Open("../testdata/go-turns-two-" + srcFilename) |
25 if err != nil { | 29 if err != nil { |
26 t.Fatalf("Open: %v", err) | 30 t.Fatalf("Open: %v", err) |
27 } | 31 } |
28 defer f.Close() | 32 defer f.Close() |
29 src, _, err := image.Decode(f) | 33 src, _, err := image.Decode(f) |
30 if err != nil { | 34 if err != nil { |
31 t.Fatalf("Decode: %v", err) | 35 t.Fatalf("Decode: %v", err) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 scaler.Scale(dst, dstMin, src, srcMin) | 98 scaler.Scale(dst, dstMin, src, srcMin) |
95 } | 99 } |
96 } | 100 } |
97 | 101 |
98 func BenchmarkScaleDownFastest(b *testing.B) { benchScale(b, image.Rect(0, 0, 12 0, 80), FastestQuality) } | 102 func BenchmarkScaleDownFastest(b *testing.B) { benchScale(b, image.Rect(0, 0, 12 0, 80), FastestQuality) } |
99 func BenchmarkScaleDownDefault(b *testing.B) { benchScale(b, image.Rect(0, 0, 12 0, 80), DefaultQuality) } | 103 func BenchmarkScaleDownDefault(b *testing.B) { benchScale(b, image.Rect(0, 0, 12 0, 80), DefaultQuality) } |
100 func BenchmarkScaleDownNicest(b *testing.B) { benchScale(b, image.Rect(0, 0, 12 0, 80), NicestQuality) } | 104 func BenchmarkScaleDownNicest(b *testing.B) { benchScale(b, image.Rect(0, 0, 12 0, 80), NicestQuality) } |
101 func BenchmarkScaleUpFastest(b *testing.B) { benchScale(b, image.Rect(0, 0, 80 0, 600), FastestQuality) } | 105 func BenchmarkScaleUpFastest(b *testing.B) { benchScale(b, image.Rect(0, 0, 80 0, 600), FastestQuality) } |
102 func BenchmarkScaleUpDefault(b *testing.B) { benchScale(b, image.Rect(0, 0, 80 0, 600), DefaultQuality) } | 106 func BenchmarkScaleUpDefault(b *testing.B) { benchScale(b, image.Rect(0, 0, 80 0, 600), DefaultQuality) } |
103 func BenchmarkScaleUpNicest(b *testing.B) { benchScale(b, image.Rect(0, 0, 80 0, 600), NicestQuality) } | 107 func BenchmarkScaleUpNicest(b *testing.B) { benchScale(b, image.Rect(0, 0, 80 0, 600), NicestQuality) } |
LEFT | RIGHT |