-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.go
More file actions
139 lines (114 loc) · 3.67 KB
/
test.go
File metadata and controls
139 lines (114 loc) · 3.67 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package main
import (
"fmt"
"golang.org/x/term"
"os"
"time"
)
const TEST_BUFFER_SIZE int = 15
const TEST_BUFFER_OFFSET int = 30
var TEST_VIDEO Video
func runTests(filepath string) {
TEST_VIDEO = loadVideo(filepath, TEST_BUFFER_OFFSET*2)
setTerminalDimensions()
// testBufferSpeed(&TEST_VIDEO)
// testGaussianBlur(&TEST_VIDEO)
// testAspectRatio(&TEST_VIDEO)
testInput()
// testDrawSpeed(&TEST_VIDEO, 2)
}
func testBufferSpeed(video *Video) {
bufferOffsets := []int{0, video.totalFrames / 4, video.totalFrames / 2, video.totalFrames / 4 * 3, video.totalFrames - TEST_BUFFER_OFFSET}
for _, startFrame := range bufferOffsets {
testBuffer(video, startFrame, TEST_BUFFER_OFFSET)
}
}
func testBuffer(video *Video, startFrame int, bufferOffset int) {
startTime := time.Now()
bufferVideo(video, startFrame, bufferOffset)
deltaTime := time.Now().Sub(startTime)
minBufferTime := time.Second * time.Duration(video.fps) / time.Duration(bufferOffset)
minBufferTimeMillis := minBufferTime.Milliseconds()
bufferTimeMillis := deltaTime.Milliseconds()
if bufferTimeMillis > minBufferTimeMillis {
fmt.Printf(RED_COLOR)
}
fmt.Printf("Frame: %d-%d\n", startFrame, startFrame+bufferOffset)
fmt.Printf("Buffertime: %d/%d ms\n", bufferTimeMillis, minBufferTimeMillis)
fmt.Printf(RESET_COLOR)
clearBuffer(video)
}
func testDrawSpeed(video *Video, durationSec int) {
clearBuffer(video)
bufferVideo(video, 1000, int(video.fps)*durationSec)
startTime := time.Now()
frame, _ := getFrame(video)
oldFrame := processFrame(frame, video.width, video.height, CHANNELS)
printFrame(oldFrame)
shiftBuffer(video)
for i := 0; i < len(video.frameBuffer); i++ {
frame, _ := getFrame(video)
setTerminalDimensions()
newFrame := processFrame(frame, video.width, video.height, CHANNELS)
frameDiff := getFrameDiff(oldFrame, newFrame)
printFrame(&frameDiff)
oldFrame = newFrame
shiftBuffer(video)
video.currentFrame++
}
deltaTime := time.Now().Sub(startTime)
if deltaTime.Milliseconds() > int64(durationSec*1000) {
fmt.Printf(RED_COLOR)
}
fmt.Printf("Frame: %d-%d\n", 0, int(video.fps)*durationSec)
fmt.Printf("Drawtime: %d/%dms\n", deltaTime.Milliseconds(), time.Second*time.Duration(durationSec))
fmt.Printf(RESET_COLOR)
clearBuffer(video)
}
func testGaussianBlur(video *Video) {
bufferVideo(video, video.totalFrames/9, TEST_BUFFER_OFFSET)
frame, _ := getFrame(video)
blurredFrame := gaussianBlur(video.width, video.height, frame, 1, 2)
blurredFrame1 := gaussianBlur(video.width, video.height, frame, 2, 4)
frame = subtractFrame(&blurredFrame, &blurredFrame1)
asciiString := processFrame(frame, video.width, video.height, 1)
printFrame(asciiString)
}
func testAspectRatio(video *Video) {
bufferVideo(video, video.totalFrames/9, TEST_BUFFER_OFFSET)
frame, _ := getFrame(video)
setTerminalDimensions()
asciiString := processFrame(frame, video.width, video.height, 1)
printFrame(asciiString)
}
func testInput() {
fd := int(os.Stdin.Fd())
// Save the original terminal state and set raw mode
oldState, err := term.MakeRaw(fd)
if err != nil {
fmt.Println("Error setting raw mode:", err)
return
}
defer term.Restore(fd, oldState)
// Enable mouse reporting (basic mode)
os.Stdout.WriteString("\x1b[?1000h")
defer os.Stdout.WriteString("\x1b[?1000l") // Disable mouse reporting on exit
// Create a buffer to hold input data
buf := make([]byte, 1024)
for {
// Read from stdin
n, err := os.Stdin.Read(buf)
if err != nil {
fmt.Println("Error reading from stdin:", err)
return
}
if n > 0 {
data := buf[:n]
if len(data) > 1 && data[0] == 27 && data[1] == 91 && data[2] == 77 {
fmt.Println(data)
} else {
fmt.Printf("Read %d bytes: %v\n", n, data)
}
}
}
}