From 49c84dc6bb393f742e1077434f7ba8c312e0452e Mon Sep 17 00:00:00 2001 From: Michael Hanselmann Date: Tue, 14 Dec 2021 21:43:12 +0100 Subject: [PATCH] waveshare213v2: Avoid allocating for every row when drawing Reuse the slice instead. --- waveshare2in13v2/waveshare213v2.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/waveshare2in13v2/waveshare213v2.go b/waveshare2in13v2/waveshare213v2.go index 0afff2e..c95af24 100644 --- a/waveshare2in13v2/waveshare213v2.go +++ b/waveshare2in13v2/waveshare213v2.go @@ -340,11 +340,12 @@ func (d *Dev) sendImage(cmd byte, dstRect image.Rectangle, src *image1bit.Vertic eh.sendCommand(cmd) rows, cols := dataDimensions(d.opts) + data := make([]byte, cols) for y := 0; y < rows; y++ { - data := make([]byte, cols) - for x := 0; x < cols; x++ { + data[x] = 0 + for bit := 0; bit < 8; bit++ { if src.BitAt((x*8)+bit, y) { data[x] |= 0x80 >> bit