Skip to content

Commit

Permalink
feat(waveshare): use grayscale when loss is above threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
loiccoyle committed Jul 1, 2024
1 parent 693f0e1 commit 4b1a10f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 0 additions & 2 deletions tinyticker/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ def show_image(self, image: Image.Image) -> None:

self._log.debug("Image size: %s", image.size)
self._log.info("Wake up.")
# I think this wakes it from sleep
self.epd.init()
self.epd.show(image)
self._log.info("Display sleep.")
self.epd.sleep()
Expand Down
18 changes: 16 additions & 2 deletions tinyticker/waveshare_lib/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def clear(self) -> None:
self.display(self._blank)

def show(self, image: Image.Image) -> None:
self.init()
self.display(self.getbuffer(image))


Expand Down Expand Up @@ -161,6 +162,7 @@ def show(self, image: Image.Image) -> None:
logger.info("Highlight pixels: %i", highlight_mask.sum())
highlight_buffer = self.getbuffer(Image.fromarray(~highlight_mask))

self.init()
self.display(
self.getbuffer(image),
highlights=highlight_buffer,
Expand Down Expand Up @@ -212,8 +214,20 @@ def getbuffer_grayscale(self, image: Image.Image) -> bytearray:
return bytearray(packed_pixels.flatten())

def show(self, image: Image.Image) -> None:
self.init_grayscale()
self.display_grayscale(self.getbuffer_grayscale(image))
# loss when displaying in bit mode
loss = np.linalg.norm(
np.array(image.convert("L")) / 255
- np.array(image.convert("1", dither=None))
) / (image.size[0] * image.size[1])
threshold = 1e-4

if loss > threshold:
logger.info("Using grayscale.")
self.init_grayscale()
self.display_grayscale(self.getbuffer_grayscale(image))
else:
self.init()
self.display(self.getbuffer(image))


# Could be used later to utilize the partial refresh feature of some of the EPDs
Expand Down

0 comments on commit 4b1a10f

Please sign in to comment.