88 lines
2.1 KiB
Go
88 lines
2.1 KiB
Go
|
package remapping
|
||
|
|
||
|
type RGBcolor = [3]byte
|
||
|
|
||
|
func Even(number int) bool {
|
||
|
return number %2 == 0
|
||
|
}
|
||
|
|
||
|
func Slice512(s []byte) [512]byte {
|
||
|
var ret [512]byte
|
||
|
for i := range s {
|
||
|
if i < 512 {
|
||
|
ret[i] = s[i]
|
||
|
}
|
||
|
}
|
||
|
return ret
|
||
|
}
|
||
|
|
||
|
func SliceUnlenthed(s [512]byte) []byte {
|
||
|
ret := make([]byte, 512)
|
||
|
for i := range s {
|
||
|
ret[i] = s[i]
|
||
|
}
|
||
|
return ret
|
||
|
}
|
||
|
|
||
|
func SliceRearrange(rowwidth int, rows int, alternaterows bool, inslice []byte) [][]byte {
|
||
|
var flippedslice []byte
|
||
|
if alternaterows {
|
||
|
flippedslice = make([]byte, len(inslice)+3)
|
||
|
for r := 0; r < rows; r++ {
|
||
|
rowzero := (r * rowwidth * 3)
|
||
|
if Even(r) {
|
||
|
for c := 0; c < (rowwidth)*3; c += 3 {
|
||
|
flippedslice[rowzero+c] = inslice[rowzero+c]
|
||
|
flippedslice[rowzero+c+1] = inslice[rowzero+c+1]
|
||
|
flippedslice[rowzero+c+2] = inslice[rowzero+c+2]
|
||
|
}
|
||
|
} else {
|
||
|
x := rowwidth * 3
|
||
|
for c := 0; c < (rowwidth)*3; c += 3 {
|
||
|
x = x - 3
|
||
|
flippedslice[rowzero+x] = inslice[rowzero+c]
|
||
|
flippedslice[rowzero+x+1] = inslice[rowzero+c+1]
|
||
|
flippedslice[rowzero+x+2] = inslice[rowzero+c+2]
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
flippedslice = inslice
|
||
|
}
|
||
|
currentUniverse := 0
|
||
|
currentUniversePosition := 0
|
||
|
universes := make([][]byte, (len(flippedslice)/510)+1)
|
||
|
currentUniverseSlice := make([]byte, 511)
|
||
|
currentRowReverse := false
|
||
|
for i := range flippedslice {
|
||
|
if currentUniversePosition >= 510 {
|
||
|
universes[currentUniverse] = currentUniverseSlice
|
||
|
if !currentRowReverse {
|
||
|
currentRowReverse = true
|
||
|
} else {
|
||
|
currentRowReverse = false
|
||
|
}
|
||
|
currentUniverse += 1
|
||
|
currentUniversePosition = 0
|
||
|
currentUniverseSlice = make([]byte, 511)
|
||
|
}
|
||
|
currentUniverseSlice[currentUniversePosition] = flippedslice[i]
|
||
|
currentUniversePosition += 1
|
||
|
}
|
||
|
universes[currentUniverse] = currentUniverseSlice
|
||
|
return universes
|
||
|
}
|
||
|
|
||
|
func XYGridToLinear(w int, h int, grid [][]RGBcolor) []byte {
|
||
|
ret := make([]byte, w*h*3)
|
||
|
i := 0
|
||
|
for y := 0; y < h; y++ {
|
||
|
for x := 0; x < w; x++ {
|
||
|
ret[i] = grid[x][y][0]
|
||
|
ret[i+1] = grid[x][y][1]
|
||
|
ret[i+2] = grid[x][y][2]
|
||
|
i += 3
|
||
|
}
|
||
|
}
|
||
|
return ret
|
||
|
}
|