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

Side by Side Diff: src/pkg/image/png/paeth_test.go

Issue 6242056: code review 6242056: image/png: optimize the paeth filter implementation. (Closed)
Patch Set: diff -r 00a25723a7cd https://go.googlecode.com/hg/ Created 11 years, 10 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:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/pkg/image/png/reader.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2012 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
5 package png
6
7 import (
8 "testing"
9 )
10
11 func abs(x int) int {
12 if x < 0 {
13 return -x
14 }
15 return x
16 }
17
18 // slowPaeth is a slow but simple implementation of the Paeth function.
19 // It is a straight port of the sample code in the PNG spec, section 9.4.
20 func slowPaeth(a, b, c uint8) uint8 {
21 p := int(a) + int(b) - int(c)
22 pa := abs(p - int(a))
23 pb := abs(p - int(b))
24 pc := abs(p - int(c))
25 if pa <= pb && pa <= pc {
26 return a
27 } else if pb <= pc {
28 return b
29 }
30 return c
31 }
32
33 func TestPaeth(t *testing.T) {
34 for a := 0; a < 256; a += 15 {
35 for b := 0; b < 256; b += 15 {
36 for c := 0; c < 256; c += 15 {
37 got := paeth(uint8(a), uint8(b), uint8(c))
38 want := slowPaeth(uint8(a), uint8(b), uint8(c))
39 if got != want {
40 t.Errorf("a, b, c = %d, %d, %d: got %d, want %d", a, b, c, got, want)
41 }
42 }
43 }
44 }
45 }
46
47 func BenchmarkPaeth(b *testing.B) {
48 for i := 0; i < b.N; i++ {
49 paeth(uint8(i>>16), uint8(i>>8), uint8(i))
50 }
51 }
OLDNEW
« no previous file with comments | « no previous file | src/pkg/image/png/reader.go » ('j') | no next file with comments »

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