Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(590)

Delta Between Two Patch Sets: tiff/writer_test.go

Issue 13243047: code review 13243047: go.image/tiff: encoder support Gray/Gray16 format (Closed)
Left Patch Set: diff -r cd62a2ebd552 https://code.google.com/p/go.image Created 11 years, 6 months ago
Right Patch Set: diff -r cd62a2ebd552 https://code.google.com/p/go.image Created 11 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« tiff/writer.go ('K') | « tiff/writer.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2012 The Go Authors. All rights reserved. 1 // Copyright 2012 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 tiff 5 package tiff
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "image" 9 "image"
10 "io/ioutil" 10 "io/ioutil"
11 "os" 11 "os"
12 "testing" 12 "testing"
13 ) 13 )
14 14
15 var roundtripTests = []struct { 15 var roundtripTests = []struct {
16 filename string 16 filename string
17 opts *Options 17 opts *Options
18 }{ 18 }{
19 {"video-001.tiff", nil}, 19 {"video-001.tiff", nil},
20 {"video-001-gray.tiff", nil},
21 {"video-001-gray-16bit.tiff", nil},
22 {"video-001-paletted.tiff", nil},
20 {"bw-packbits.tiff", nil}, 23 {"bw-packbits.tiff", nil},
21 {"video-001.tiff", &Options{Predictor: true}}, 24 {"video-001.tiff", &Options{Predictor: true}},
22 {"video-001.tiff", &Options{Compression: Deflate}}, 25 {"video-001.tiff", &Options{Compression: Deflate}},
23 {"video-001.tiff", &Options{Predictor: true, Compression: Deflate}}, 26 {"video-001.tiff", &Options{Predictor: true, Compression: Deflate}},
24 } 27 }
25 28
26 func openImage(filename string) (image.Image, error) { 29 func openImage(filename string) (image.Image, error) {
27 f, err := os.Open(testdataDir + filename) 30 f, err := os.Open(testdataDir + filename)
28 if err != nil { 31 if err != nil {
29 return nil, err 32 return nil, err
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 if err := Encode(out, m0, nil); err != nil { 66 if err := Encode(out, m0, nil); err != nil {
64 t.Fatal(err) 67 t.Fatal(err)
65 } 68 }
66 m1, err := Decode(&buffer{buf: out.Bytes()}) 69 m1, err := Decode(&buffer{buf: out.Bytes()})
67 if err != nil { 70 if err != nil {
68 t.Fatal(err) 71 t.Fatal(err)
69 } 72 }
70 compare(t, m0, m1) 73 compare(t, m0, m1)
71 } 74 }
72 75
73 // BenchmarkEncode benchmarks the encoding of an image. 76 // BenchmarkEncode benchmarks the encoding of an image.
nigeltao 2013/09/13 07:36:59 I'd delete the obvious comment.
74 func BenchmarkEncode(b *testing.B) { 77 func BenchmarkEncode(b *testing.B) {
75 » img, err := openImage("video-001.tiff") 78 » benchmarkEncode(b, "video-001.tiff", 4)
79 }
80
81 func BenchmarkEncodePaletted(b *testing.B) {
82 » benchmarkEncode(b, "video-001-paletted.tiff", 1)
83 }
84
85 func BenchmarkEncodeGray(b *testing.B) {
86 » benchmarkEncode(b, "video-001-gray.tiff", 1)
87 }
88
89 func BenchmarkEncodeGray16(b *testing.B) {
90 » benchmarkEncode(b, "video-001-gray-16bit.tiff", 2)
91 }
92
93 func benchmarkEncode(b *testing.B, name string, pixelSize int) {
94 » img, err := openImage(name)
76 if err != nil { 95 if err != nil {
77 b.Fatal(err) 96 b.Fatal(err)
78 } 97 }
79 s := img.Bounds().Size() 98 s := img.Bounds().Size()
80 » b.SetBytes(int64(s.X * s.Y * 4)) 99 » b.SetBytes(int64(s.X * s.Y * pixelSize))
81 b.ResetTimer() 100 b.ResetTimer()
82 for i := 0; i < b.N; i++ { 101 for i := 0; i < b.N; i++ {
83 Encode(ioutil.Discard, img, nil) 102 Encode(ioutil.Discard, img, nil)
84 } 103 }
85 } 104 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b