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 (
"math"
"sync"
)
// 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)
}
wg := new(sync.WaitGroup)
for i := 0; i < h; i++ {
cols := DCT1D(input[i])
copy(output[i], cols)
wg.Add(1)
go func(i int) {
cols := DCT1D(input[i])
output[i] = cols
wg.Done()
}(i)
}
wg.Wait()
for i := 0; i < w; i++ {
wg.Add(1)
in := make([]float64, h)
for j := 0; j < h; j++ {
in[j] = output[j][i]
}
rows := DCT1D(in)
for j := 0; j < len(rows); j++ {
output[j][i] = rows[j]
}
go func(i int) {
for j := 0; j < h; j++ {
in[j] = output[j][i]
}
rows := DCT1D(in)
for j := 0; j < len(rows); j++ {
output[j][i] = rows[j]
}
wg.Done()
}(i)
}
wg.Wait()
return output
}