dct: Process dct algorithm in multiple goroutine (#26)
This commit is contained in:
parent
47321c08d3
commit
0876a2adc2
@ -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,13 +38,21 @@ 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++ {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(i int) {
|
||||||
cols := DCT1D(input[i])
|
cols := DCT1D(input[i])
|
||||||
copy(output[i], cols)
|
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)
|
||||||
|
go func(i int) {
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
in[j] = output[j][i]
|
in[j] = output[j][i]
|
||||||
}
|
}
|
||||||
@ -51,7 +60,10 @@ func DCT2D(input [][]float64, w int, h int) [][]float64 {
|
|||||||
for j := 0; j < len(rows); j++ {
|
for j := 0; j < len(rows); j++ {
|
||||||
output[j][i] = rows[j]
|
output[j][i] = rows[j]
|
||||||
}
|
}
|
||||||
|
wg.Done()
|
||||||
|
}(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user