mirror of https://github.com/golang/go.git
image/jpeg: make TestDCT faster.
The value of cosines are cached in a global array instead of being recomputed each time. The test was terribly slow on arm. R=golang-dev, dave, nigeltao CC=golang-dev https://golang.org/cl/6733046
This commit is contained in:
parent
a5b0c67d5f
commit
2abaaefa72
|
|
@ -112,6 +112,14 @@ func alpha(i int) float64 {
|
|||
return math.Sqrt2
|
||||
}
|
||||
|
||||
var cosines [32]float64 // cosines[k] = cos(π/2 * k/8)
|
||||
|
||||
func init() {
|
||||
for k := range cosines {
|
||||
cosines[k] = math.Cos(math.Pi * float64(k) / 16)
|
||||
}
|
||||
}
|
||||
|
||||
// slowFDCT performs the 8*8 2-dimensional forward discrete cosine transform:
|
||||
//
|
||||
// dst[u,v] = (1/8) * Σ_x Σ_y alpha(u) * alpha(v) * src[x,y] *
|
||||
|
|
@ -129,8 +137,8 @@ func slowFDCT(b *block) {
|
|||
for y := 0; y < 8; y++ {
|
||||
for x := 0; x < 8; x++ {
|
||||
sum += alpha(u) * alpha(v) * float64(b[8*y+x]) *
|
||||
math.Cos(math.Pi*float64((2*x+1)*u)/16) *
|
||||
math.Cos(math.Pi*float64((2*y+1)*v)/16)
|
||||
cosines[((2*x+1)*u)%32] *
|
||||
cosines[((2*y+1)*v)%32]
|
||||
}
|
||||
}
|
||||
dst[8*v+u] = sum / 8
|
||||
|
|
@ -159,8 +167,8 @@ func slowIDCT(b *block) {
|
|||
for v := 0; v < 8; v++ {
|
||||
for u := 0; u < 8; u++ {
|
||||
sum += alpha(u) * alpha(v) * float64(b[8*v+u]) *
|
||||
math.Cos(math.Pi*float64((2*x+1)*u)/16) *
|
||||
math.Cos(math.Pi*float64((2*y+1)*v)/16)
|
||||
cosines[((2*x+1)*u)%32] *
|
||||
cosines[((2*y+1)*v)%32]
|
||||
}
|
||||
}
|
||||
dst[8*y+x] = sum / 8
|
||||
|
|
|
|||
Loading…
Reference in New Issue