Utoljára aktív 1 month ago

Revízió a530a298c64173248c53140325c626578cdf2046

rotate.go Eredeti
1var rotation90 = complex(tools.Cos(float32(math.Pi/2)), tools.Sin(float32(math.Pi/2)))
2func rotateByte(v byte, n int) byte {
3 byteData := make([]byte, 8)
4 outByteData := make([]byte, 8)
5
6 // region convert to bits in bytes
7 for i := 0; i < 8; i++ {
8 byteData[i] = -127
9 if v & (1 << uint(i)) > 0 {
10 byteData[i] = 127
11 }
12 }
13 // endregion
14 // region Rotate
15 for i := 0; i < 4; i++ {
16 // Sync Word
17 b0 := int(byteData[i*2])
18 b1 := int(byteData[i*2+1])
19
20 // 0 degrees
21 c := complex(float32(b0), float32(b1))
22 for z := 0; z < n; z++ {
23 c *= rotation90
24 }
25 outByteData[i*2] = f2b(real(c))
26 outByteData[i*2+1] = f2b(imag(c))
27 }
28 // endregion
29 // region Unmap to Byte
30 v = 0
31 for i := 0; i < 8; i++ {
32 t := 0
33 if outByteData[i] > 0 {
34 t = 1
35 }
36
37 v |= byte(t << uint(i))
38 }
39 // endregion
40
41 return v
42}