Implement 16 grayscale support for image module
This commit is contained in:
parent
1138f2d862
commit
a7e2a852e9
@ -13,23 +13,6 @@ Display
|
|||||||
:members:
|
:members:
|
||||||
|
|
||||||
|
|
||||||
Modules
|
|
||||||
===========================
|
|
||||||
- Agenda
|
|
||||||
|
|
||||||
.. automodule:: inkycal.modules.inkycal_agenda.Agenda
|
|
||||||
:members:
|
|
||||||
|
|
||||||
- Calendar
|
|
||||||
|
|
||||||
.. automodule:: inkycal.modules.inkycal_calendar.Calendar
|
|
||||||
:members:
|
|
||||||
|
|
||||||
- Feeds Module (RSS & Atom)
|
|
||||||
.. automodule:: inkycal.modules.inkycal_feeds.Feeds
|
|
||||||
:members:
|
|
||||||
|
|
||||||
|
|
||||||
Custom functions
|
Custom functions
|
||||||
===========================
|
===========================
|
||||||
.. automodule:: inkycal.custom.functions
|
.. automodule:: inkycal.custom.functions
|
||||||
|
@ -8,6 +8,7 @@ import os
|
|||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
import PIL
|
||||||
import requests
|
import requests
|
||||||
from PIL import ImageFont, ImageDraw, Image
|
from PIL import ImageFont, ImageDraw, Image
|
||||||
|
|
||||||
@ -335,7 +336,7 @@ def draw_border(image, xy, size, radius=5, thickness=1, shrinkage=(0.1, 0.1)):
|
|||||||
draw.arc((c7, c8), 90, 180, fill=colour, width=thickness)
|
draw.arc((c7, c8), 90, 180, fill=colour, width=thickness)
|
||||||
|
|
||||||
|
|
||||||
def draw_border_2(im: Image, xy: tuple, size: tuple, radius: int):
|
def draw_border_2(im: PIL.Image, xy: tuple, size: tuple, radius: int):
|
||||||
draw = ImageDraw.Draw(im)
|
draw = ImageDraw.Draw(im)
|
||||||
|
|
||||||
x, y = xy
|
x, y = xy
|
||||||
|
@ -2,18 +2,21 @@
|
|||||||
Inkycal ePaper driving functions
|
Inkycal ePaper driving functions
|
||||||
Copyright by aceisace
|
Copyright by aceisace
|
||||||
"""
|
"""
|
||||||
import os
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
|
|
||||||
|
import PIL
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from inkycal.custom import top_level
|
from inkycal.custom import top_level
|
||||||
import glob
|
|
||||||
|
|
||||||
def import_driver(model):
|
def import_driver(model):
|
||||||
return import_module(f'inkycal.display.drivers.{model}')
|
return import_module(f'inkycal.display.drivers.{model}')
|
||||||
|
|
||||||
|
|
||||||
class Display:
|
class Display:
|
||||||
"""Display class for inkycal
|
"""Display class for inkycal
|
||||||
|
|
||||||
@ -44,7 +47,14 @@ class Display:
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
raise Exception('SPI could not be found. Please check if SPI is enabled')
|
raise Exception('SPI could not be found. Please check if SPI is enabled')
|
||||||
|
|
||||||
def render(self, im_black: Image, im_colour:Image or None=None) -> None:
|
|
||||||
|
def test(self) -> None:
|
||||||
|
"""Test the display by showing a test image"""
|
||||||
|
# TODO implement test image
|
||||||
|
raise NotImplementedError("Devs were too lazy again, sorry, please try again later")
|
||||||
|
|
||||||
|
|
||||||
|
def render(self, im_black: PIL.Image, im_colour: PIL.Image or None) -> None:
|
||||||
"""Renders an image on the selected E-Paper display.
|
"""Renders an image on the selected E-Paper display.
|
||||||
|
|
||||||
Initlializes the E-Paper display, sends image data and executes command
|
Initlializes the E-Paper display, sends image data and executes command
|
||||||
|
@ -10,6 +10,8 @@ Copyright by aceinnolab
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import PIL
|
||||||
import numpy
|
import numpy
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
@ -215,7 +217,7 @@ class Inkyimage:
|
|||||||
|
|
||||||
return image1
|
return image1
|
||||||
|
|
||||||
def to_palette(self, palette, dither=True) -> (Image, Image):
|
def to_palette(self, palette, dither=True) -> (PIL.Image, PIL.Image):
|
||||||
"""Maps an image to a given colour palette.
|
"""Maps an image to a given colour palette.
|
||||||
|
|
||||||
Maps each pixel from the image to a colour from the palette.
|
Maps each pixel from the image to a colour from the palette.
|
||||||
@ -235,6 +237,7 @@ class Inkyimage:
|
|||||||
>>> 'bwr' # black-white-red
|
>>> 'bwr' # black-white-red
|
||||||
>>> 'bwy' # black-white-yellow
|
>>> 'bwy' # black-white-yellow
|
||||||
>>> 'bw' # black-white
|
>>> 'bw' # black-white
|
||||||
|
>>> '16gray' # 16 shades of gray
|
||||||
"""
|
"""
|
||||||
# Check if an image is loaded
|
# Check if an image is loaded
|
||||||
if self._image_loaded():
|
if self._image_loaded():
|
||||||
@ -252,6 +255,9 @@ class Inkyimage:
|
|||||||
|
|
||||||
elif palette == 'bw':
|
elif palette == 'bw':
|
||||||
pal = None
|
pal = None
|
||||||
|
elif palette == '16gray':
|
||||||
|
pal = [x for x in range(0, 256, 16)] * 3
|
||||||
|
pal.sort()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.error('The given palette is unsupported.')
|
logger.error('The given palette is unsupported.')
|
||||||
|
@ -14,7 +14,7 @@ from tests import Config
|
|||||||
preview = Inkyimage.preview
|
preview = Inkyimage.preview
|
||||||
merge = Inkyimage.merge
|
merge = Inkyimage.merge
|
||||||
|
|
||||||
url = "https://github.com/aceinnolab/Inkycal/raw/assets/Repo/coffee.png"
|
url ="https://raw.githubusercontent.com/aceinnolab/Inkycal/assets/tests/mark-harpur-unsplash.jpg"
|
||||||
|
|
||||||
im = Image.open(requests.get(url, stream=True).raw)
|
im = Image.open(requests.get(url, stream=True).raw)
|
||||||
im.save("test.png", "PNG")
|
im.save("test.png", "PNG")
|
||||||
@ -27,9 +27,9 @@ tests = [
|
|||||||
{
|
{
|
||||||
"name": "Inkyimage",
|
"name": "Inkyimage",
|
||||||
"config": {
|
"config": {
|
||||||
"size": [400, 200],
|
"size": [800, 600],
|
||||||
"path": test_path,
|
"path": test_path,
|
||||||
"palette": "bwr",
|
"palette": "16gray",
|
||||||
"autoflip": True,
|
"autoflip": True,
|
||||||
"orientation": "vertical",
|
"orientation": "vertical",
|
||||||
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
||||||
|
Loading…
Reference in New Issue
Block a user