Skip to content

Commit

Permalink
Add auto dither to what.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Nov 21, 2023
1 parent 88b8ea8 commit 4feb1e4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
28 changes: 19 additions & 9 deletions examples/7color/image.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
#!/usr/bin/env python3

import argparse
import pathlib
import sys

from PIL import Image

from inky.auto import auto

parser = argparse.ArgumentParser()

parser.add_argument("--saturation", "-s", type=float, default=0.5, help="Colour palette saturation")
parser.add_argument("--file", "-f", type=pathlib.Path, help="Image file")

inky = auto(ask_user=True, verbose=True)
saturation = 0.5

if len(sys.argv) == 1:
print("""
Usage: {file} image-file
""".format(file=sys.argv[0]))
args, _ = parser.parse_known_args()

saturation = args.saturation

if not args.file:
print(f"""Usage:
{sys.argv[0]} --file image.png (--saturation 0.5)""")
sys.exit(1)

image = Image.open(sys.argv[1])
image = Image.open(args.file)
resizedimage = image.resize(inky.resolution)

if len(sys.argv) > 2:
saturation = float(sys.argv[2])
try:
inky.set_image(resizedimage, saturation=saturation)
except TypeError:
inky.set_image(resizedimage)

inky.set_image(resizedimage, saturation=saturation)
inky.show()
18 changes: 15 additions & 3 deletions inky/inky_ssd1608.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,21 @@ def set_border(self, colour):

def set_image(self, image):
"""Copy an image to the display."""
canvas = Image.new("P", (self.rows, self.cols))
canvas.paste(image, (self.offset_x, self.offset_y))
self.buf = numpy.array(canvas, dtype=numpy.uint8).reshape((self.cols, self.rows))
if not image.mode == "P":
palette_image = Image.new("P", (1, 1))
r, g, b = 0, 0, 0
if self.colour == "red":
r = 255
if self.colour == "yellow":
g = 255
palette_image.putpalette([255, 255, 255, 0, 0, 0, r, g, b] + [0, 0, 0] * 252)
image.load()
image = image.im.convert("P", True, palette_image.im)

canvas = Image.new("P", (self.cols, self.rows))
width, height = image.size
canvas.paste(image, (self.offset_x, self.offset_y, width, height))
self.buf = numpy.array(canvas, dtype=numpy.uint8).reshape((self.rows, self.cols))

def _spi_write(self, dc, values):
"""Write values over SPI.
Expand Down
14 changes: 13 additions & 1 deletion inky/inky_ssd1683.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,20 @@ def set_border(self, colour):

def set_image(self, image):
"""Copy an image to the display."""
if not image.mode == "P":
palette_image = Image.new("P", (1, 1))
r, g, b = 0, 0, 0
if self.colour == "red":
r = 255
if self.colour == "yellow":
g = 255
palette_image.putpalette([255, 255, 255, 0, 0, 0, r, g, b] + [0, 0, 0] * 252)
image.load()
image = image.im.convert("P", True, palette_image.im)

canvas = Image.new("P", (self.cols, self.rows))
canvas.paste(image, (self.offset_x, self.offset_y))
width, height = image.size
canvas.paste(image, (self.offset_x, self.offset_y, width, height))
self.buf = numpy.array(canvas, dtype=numpy.uint8).reshape((self.rows, self.cols))

def _spi_write(self, dc, values):
Expand Down

0 comments on commit 4feb1e4

Please sign in to comment.