Skip to content

Commit ce0739e

Browse files
committed
fbscreenshot: pack rotated pixel writes to uint32
1 parent f94b7d3 commit ce0739e

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

src/common/fb.nim

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,21 @@ proc fbclear*() =
4545
zeroMem(fbMap, FbSize)
4646

4747
proc fbscreenshot*(fbMap: pointer, output: string) =
48-
let fbData = cast[ptr UncheckedArray[uint8]](fbMap)
49-
var rotatedPixels = newSeqUninit[uint8](FbPixels * 4)
48+
let fbData = cast[ptr UncheckedArray[uint16]](fbMap)
49+
var rotatedPixels = newSeqUninit[uint32](FbPixels)
5050

5151
for x in 0..<FbWidth:
5252
let colBase = x * FbHeight
5353
var srcBase = x * 2
5454

5555
for y in 0..<FbHeight:
56-
let pixel = uint16(fbData[srcBase]) or (uint16(fbData[srcBase + 1]) shl 8)
56+
let pixel = fbData[srcBase]
5757
srcBase += FbWidth * 2
5858

59-
let r = (pixel shr 11) and 0x1F
60-
let g = (pixel shr 5) and 0x3F
61-
let b = pixel and 0x1F
62-
63-
let dstIdx = (colBase + FbHeight - 1 - y) * 4
64-
rotatedPixels[dstIdx] = FiveToEight[r]
65-
rotatedPixels[dstIdx + 1] = SixToEight[g]
66-
rotatedPixels[dstIdx + 2] = FiveToEight[b]
67-
rotatedPixels[dstIdx + 3] = 255
59+
rotatedPixels[colBase + FbHeight - 1 - y] = uint32(FiveToEight[(pixel shr 11) and 0x1F]) or
60+
(uint32(SixToEight[(pixel shr 5) and 0x3F]) shl 8) or
61+
(uint32(FiveToEight[pixel and 0x1F]) shl 16) or
62+
0xFF000000'u32
6863

6964
discard stbi_write_png(
7065
cstring(output),

0 commit comments

Comments
 (0)