-
Notifications
You must be signed in to change notification settings - Fork 0
/
step2_grayscaleVideo.go
43 lines (36 loc) · 1.07 KB
/
step2_grayscaleVideo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"image"
"image/draw"
)
// ---------------- Step Function ----------------
func grayscaleVideo() {
for {
select {
case img, ok := <-procFrameQueue1:
if !ok {
// Channel is closed
return
}
// Process the received image
maskFrame := convertToMonochrome(img)
if drawUI && !playOnlyMode {
grayFrameRW.Lock()
grayFrame = convertGrayToRGBA(maskFrame)
grayFrameRW.Unlock()
}
procFrameQueue2 <- &ImageGrayMask{Mask:maskFrame,Image:img}
}
}
}
// ---------------- Helper Functions ----------------
func convertToMonochrome(img *image.RGBA) *image.Gray {
monoFrame := image.NewGray(img.Bounds())
draw.Draw(monoFrame, monoFrame.Bounds(), img, img.Bounds().Min, draw.Src)
return monoFrame
}
func convertGrayToRGBA(img *image.Gray) *image.RGBA {
rgbaFrame := image.NewRGBA(img.Bounds())
draw.Draw(rgbaFrame, rgbaFrame.Bounds(), img, img.Bounds().Min, draw.Src)
return rgbaFrame
}