-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_of_frame.go
70 lines (53 loc) · 1.64 KB
/
start_of_frame.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
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
package main
import (
"fmt"
"os"
)
func ExtractStartOfFrame(file *os.File) {
segmentLengthBuffer := make([]byte, 2)
_, err = ReadFunc(file, segmentLengthBuffer)
if err != nil {
fmt.Println(err)
panic(err)
}
segmentLength := BigEUint16(segmentLengthBuffer[0], segmentLengthBuffer[1])
fmt.Printf("Length %d\n", segmentLength)
segmentDataBuffer := make([]byte, segmentLength-2)
n, err = ReadFunc(file, segmentDataBuffer)
if err != nil {
fmt.Println(err)
panic(err)
}
fmt.Printf("Precision %d\n", int(segmentDataBuffer[0]))
Height = int(BigEUint16(segmentDataBuffer[1], segmentDataBuffer[2]))
fmt.Printf("Line No %d\n", Height)
Width = int(BigEUint16(segmentDataBuffer[3], segmentDataBuffer[4]))
fmt.Printf("Samples Per Line %d\n", Width)
numberOfComponents := int(segmentDataBuffer[5])
// fmt.Printf("Components %d\n", numberOfComponents)
for i := 0; i < int(numberOfComponents); i++ {
index := 6 + i*3
switch i + 1 {
case 1:
C1QT = int(segmentDataBuffer[index+2])
C1XS = int((segmentDataBuffer[index+1] & 0xF0) >> 4)
C1YS = int(segmentDataBuffer[index+1] & 0x0F)
case 2:
C2QT = int(segmentDataBuffer[index+2])
C2XS = int((segmentDataBuffer[index+1] & 0xF0) >> 4)
C2YS = int(segmentDataBuffer[index+1] & 0x0F)
case 3:
C3QT = int(segmentDataBuffer[index+2])
C3XS = int((segmentDataBuffer[index+1] & 0xF0) >> 4)
C3YS = int(segmentDataBuffer[index+1] & 0x0F)
}
fmt.Printf("Component %d %dx%d %d\n",
int(segmentDataBuffer[index]),
// Mask And Shift
int((segmentDataBuffer[index+1]&0xF0)>>4),
int(segmentDataBuffer[index+1]&0x0F),
int(segmentDataBuffer[index+2]),
)
}
fmt.Println("")
}