From 2abaaefa729502740002fc9a87c012ea7d1a3e64 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9my=20Oudompheng?= Date: Thu, 18 Oct 2012 21:28:04 +0200 Subject: [PATCH] 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 --- src/pkg/image/jpeg/dct_test.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/pkg/image/jpeg/dct_test.go b/src/pkg/image/jpeg/dct_test.go index 770e274bac..52d0c10dee 100644 --- a/src/pkg/image/jpeg/dct_test.go +++ b/src/pkg/image/jpeg/dct_test.go @@ -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 -- 2.48.1