Skip to content

Commit 48f8a95

Browse files
authored
Merge pull request #2 from makermelissa/main
Optimized library to only draw changed pixels
2 parents a58a4df + 2ab1209 commit 48f8a95

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

adafruit_pixel_framebuf.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def __init__(
8585
)
8686

8787
self._buffer = bytearray(width * height * 3)
88+
self._double_buffer = bytearray(width * height * 3)
8889
super().__init__(
8990
self._buffer, width, height, buf_format=adafruit_framebuf.RGB888
9091
)
@@ -99,5 +100,12 @@ def display(self):
99100
for _y in range(self._height):
100101
for _x in range(self._width):
101102
index = (_y * self.stride + _x) * 3
102-
self._grid[(_x, _y)] = tuple(self._buffer[index : index + 3])
103+
if (
104+
self._buffer[index : index + 3]
105+
!= self._double_buffer[index : index + 3]
106+
):
107+
self._grid[(_x, _y)] = tuple(self._buffer[index : index + 3])
108+
self._double_buffer[index : index + 3] = self._buffer[
109+
index : index + 3
110+
]
103111
self._grid.show()

0 commit comments

Comments
 (0)