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

Delta Between Two Patch Sets: tiff/reader_test.go

Issue 13453043: code review 13453043: go.image/tiff: decoder support tiled tiff format (Closed)
Left Patch Set: diff -r bbc7adb6f09d https://code.google.com/p/go.image Created 11 years, 6 months ago
Right Patch Set: diff -r bbc7adb6f09d 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« tiff/reader.go ('K') | « tiff/reader.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
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 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 "image" 8 "image"
9 "io/ioutil" 9 "io/ioutil"
10 "os" 10 "os"
11 "strings" 11 "strings"
12 "testing" 12 "testing"
13 13
14 _ "image/png" 14 _ "image/png"
15 ) 15 )
16 16
17 const testdataDir = "../testdata/" 17 const testdataDir = "../testdata/"
18 18
19 // Read makes *buffer implements io.Reader, so that we can pass one to Decode. 19 // Read makes *buffer implements io.Reader, so that we can pass one to Decode.
20 func (*buffer) Read([]byte) (int, error) { 20 func (*buffer) Read([]byte) (int, error) {
21 panic("unimplemented") 21 panic("unimplemented")
22 } 22 }
23 23
24 // TestNoRPS tries to decode an image that has no RowsPerStrip tag. 24 // TestNoRPS tries to decode an image that has no RowsPerStrip tag.
25 // The tag is mandatory according to the spec but some software omits 25 // The tag is mandatory according to the spec but some software omits
26 // it in the case of a single strip. 26 // it in the case of a single strip.
27 func TestNoRPS(t *testing.T) { 27 func TestNoRPS(t *testing.T) {
28 » f, err := os.Open(testdataDir + "no_rps.tiff") 28 » _, err := load("no_rps.tiff")
29 » if err != nil {
30 » » t.Fatal(err)
31 » }
32 » defer f.Close()
33 » _, err = Decode(f)
34 if err != nil { 29 if err != nil {
35 t.Fatal(err) 30 t.Fatal(err)
36 } 31 }
37 } 32 }
38 33
39 // TestUnpackBits tests the decoding of PackBits-encoded data. 34 // TestUnpackBits tests the decoding of PackBits-encoded data.
40 func TestUnpackBits(t *testing.T) { 35 func TestUnpackBits(t *testing.T) {
41 var unpackBitsTests = []struct { 36 var unpackBitsTests = []struct {
42 compressed string 37 compressed string
43 uncompressed string 38 uncompressed string
(...skipping 27 matching lines...) Expand all
71 c1 := img1.At(x+x1, y+y1) 66 c1 := img1.At(x+x1, y+y1)
72 r0, g0, b0, a0 := c0.RGBA() 67 r0, g0, b0, a0 := c0.RGBA()
73 r1, g1, b1, a1 := c1.RGBA() 68 r1, g1, b1, a1 := c1.RGBA()
74 if r0 != r1 || g0 != g1 || b0 != b1 || a0 != a1 { 69 if r0 != r1 || g0 != g1 || b0 != b1 || a0 != a1 {
75 t.Fatalf("pixel at (%d, %d) has wrong color: wan t %v, got %v", x, y, c0, c1) 70 t.Fatalf("pixel at (%d, %d) has wrong color: wan t %v, got %v", x, y, c0, c1)
76 } 71 }
77 } 72 }
78 } 73 }
79 } 74 }
80 75
81 func load(name string) (image.Image, error) { 76 func load(name string) (image.Image, error) {
nigeltao 2013/09/06 10:04:38 I'd now move this function to before its first use
82 f, err := os.Open(testdataDir + name) 77 f, err := os.Open(testdataDir + name)
83 if err != nil { 78 if err != nil {
84 return nil, err 79 return nil, err
85 } 80 }
86 defer f.Close() 81 defer f.Close()
87 img, _, err := image.Decode(f) 82 img, _, err := image.Decode(f)
88 if err != nil { 83 if err != nil {
89 return nil, err 84 return nil, err
90 } 85 }
91 return img, nil 86 return img, nil
(...skipping 27 matching lines...) Expand all
119 // TestDecompress tests that decoding some TIFF images that use different 114 // TestDecompress tests that decoding some TIFF images that use different
120 // compression formats result in the same pixel data. 115 // compression formats result in the same pixel data.
121 func TestDecompress(t *testing.T) { 116 func TestDecompress(t *testing.T) {
122 var decompressTests = []string{ 117 var decompressTests = []string{
123 "bw-uncompressed.tiff", 118 "bw-uncompressed.tiff",
124 "bw-deflate.tiff", 119 "bw-deflate.tiff",
125 "bw-packbits.tiff", 120 "bw-packbits.tiff",
126 } 121 }
127 var img0 image.Image 122 var img0 image.Image
128 for _, name := range decompressTests { 123 for _, name := range decompressTests {
129 » » f, err := os.Open(testdataDir + name) 124 » » img1, err := load(name)
130 » » if err != nil {
131 » » » t.Fatal(err)
132 » » }
133 » » defer f.Close()
134 » » if img0 == nil {
135 » » » img0, err = Decode(f)
136 » » » if err != nil {
137 » » » » t.Fatalf("decoding %s: %v", name, err)
138 » » » }
139 » » » continue
140 » » }
141
142 » » img1, err := Decode(f)
143 if err != nil { 125 if err != nil {
144 t.Fatalf("decoding %s: %v", name, err) 126 t.Fatalf("decoding %s: %v", name, err)
127 }
128 if img0 == nil {
129 img0 = img1
130 continue
145 } 131 }
146 compare(t, img0, img1) 132 compare(t, img0, img1)
147 } 133 }
148 } 134 }
149 135
150 // benchmarkDecode benchmarks the decoding of an image. 136 // benchmarkDecode benchmarks the decoding of an image.
151 func benchmarkDecode(b *testing.B, filename string) { 137 func benchmarkDecode(b *testing.B, filename string) {
152 b.StopTimer() 138 b.StopTimer()
153 contents, err := ioutil.ReadFile(testdataDir + filename) 139 contents, err := ioutil.ReadFile(testdataDir + filename)
154 if err != nil { 140 if err != nil {
155 panic(err) 141 panic(err)
156 } 142 }
157 r := &buffer{buf: contents} 143 r := &buffer{buf: contents}
158 b.StartTimer() 144 b.StartTimer()
159 for i := 0; i < b.N; i++ { 145 for i := 0; i < b.N; i++ {
160 _, err := Decode(r) 146 _, err := Decode(r)
161 if err != nil { 147 if err != nil {
162 b.Fatal("Decode:", err) 148 b.Fatal("Decode:", err)
163 } 149 }
164 } 150 }
165 } 151 }
166 152
167 func BenchmarkDecodeCompressed(b *testing.B) { benchmarkDecode(b, "video-001.t iff") } 153 func BenchmarkDecodeCompressed(b *testing.B) { benchmarkDecode(b, "video-001.t iff") }
168 func BenchmarkDecodeUncompressed(b *testing.B) { benchmarkDecode(b, "video-001-u ncompressed.tiff") } 154 func BenchmarkDecodeUncompressed(b *testing.B) { benchmarkDecode(b, "video-001-u ncompressed.tiff") }
LEFTRIGHT

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