From 63663ee56733f40319d25dc43589e7e3db5a07f1 Mon Sep 17 00:00:00 2001 From: Ace Date: Fri, 17 Jan 2020 17:17:41 +0100 Subject: [PATCH] Update configuration.py --- settings/configuration.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/settings/configuration.py b/settings/configuration.py index 895cc7d..006cfee 100644 --- a/settings/configuration.py +++ b/settings/configuration.py @@ -9,18 +9,27 @@ Copyright by aceisace """ from PIL import Image, ImageDraw, ImageFont, ImageColor import numpy +import arrow from urllib.request import urlopen -from settings import language +from settings import * from pytz import timezone import os from glob import glob +import importlib """Set the image background colour and text colour""" background_colour = 'white' text_colour = 'black' -"""Set the display height and width (in pixels)""" -display_height, display_width = 640, 384 +"""Set some display parameters""" +e_paper = importlib.import_module('drivers.'+model) +display_height, display_width = e_paper.EPD_WIDTH, e_paper.EPD_HEIGHT + +"""Check if the display supports 3 colours""" +if 'colour' in model: + three_colour_support = True +else: + three_colour_support = False """Create 3 sections of the display, based on percentage""" top_section_width = middle_section_width = bottom_section_width = display_width @@ -189,3 +198,21 @@ def image_cleanup(): for temp_files in glob(image_path+'*'): os.remove(temp_files) print('Done') + +def split_colours(image): + if three_colour_support == True: + """Split image into two, one for red pixels, the other for black pixels""" + buffer = numpy.array(image.convert('RGB')) + red, green = buffer[:, :, 0], buffer[:, :, 1] + buffer_red, buffer_black = numpy.array(image), numpy.array(image) + + buffer_red[numpy.logical_and(red >= 200, green <= 90)] = [0,0,0] #red->black + red1 = buffer_red[:,:,0] + buffer_red[red1 != 0] = [255,255,255] #white + red_im = Image.fromarray(buffer_red).convert('1',dither=True).rotate(270,expand=True) + + buffer_black[numpy.logical_and(red <= 180, red == green)] = [0,0,0] #black + red2 = buffer_black[:,:,0] + buffer_black[red2 != 0] = [255,255,255] # white + black_im = Image.fromarray(buffer_black).convert('1', dither=True).rotate(270,expand=True) + return black_im, red_im