dct: Process dct algorithm in multiple goroutine (#26)

This commit is contained in:
Dong-hee Na 2019-03-18 21:09:40 +09:00 committed by GitHub
parent 47321c08d3
commit 0876a2adc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ package transforms
import ( import (
"math" "math"
"sync"
) )
// DCT1D function returns result of DCT-II. // DCT1D function returns result of DCT-II.
@ -37,21 +38,32 @@ func DCT2D(input [][]float64, w int, h int) [][]float64 {
output[i] = make([]float64, w) output[i] = make([]float64, w)
} }
wg := new(sync.WaitGroup)
for i := 0; i < h; i++ { for i := 0; i < h; i++ {
cols := DCT1D(input[i]) wg.Add(1)
copy(output[i], cols) go func(i int) {
cols := DCT1D(input[i])
output[i] = cols
wg.Done()
}(i)
} }
wg.Wait()
for i := 0; i < w; i++ { for i := 0; i < w; i++ {
wg.Add(1)
in := make([]float64, h) in := make([]float64, h)
for j := 0; j < h; j++ { go func(i int) {
in[j] = output[j][i] for j := 0; j < h; j++ {
} in[j] = output[j][i]
rows := DCT1D(in) }
for j := 0; j < len(rows); j++ { rows := DCT1D(in)
output[j][i] = rows[j] for j := 0; j < len(rows); j++ {
} output[j][i] = rows[j]
}
wg.Done()
}(i)
} }
wg.Wait()
return output return output
} }