Develop fast render #2
4 changed files with 18 additions and 33 deletions
|
@ -2,6 +2,7 @@ from EpdAdapter import EpdAdapter, DISPLAY_REFRESH, DATA_START_TRANSMISSION_1
|
||||||
from settings import display_colours
|
from settings import display_colours
|
||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw
|
||||||
from math import sqrt, pow
|
from math import sqrt, pow
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
class Epd7in5bAdapter (EpdAdapter):
|
class Epd7in5bAdapter (EpdAdapter):
|
||||||
def __init__ (self):
|
def __init__ (self):
|
||||||
|
@ -40,46 +41,32 @@ class Epd7in5bAdapter (EpdAdapter):
|
||||||
|
|
||||||
def get_frame_buffer (self, image):
|
def get_frame_buffer (self, image):
|
||||||
buf = [ 0x00 ] * int(self.height * self.width / 4)
|
buf = [ 0x00 ] * int(self.height * self.width / 4)
|
||||||
image_rgb = image
|
imwidth, imheight = image.size
|
||||||
imwidth, imheight = image_rgb.size
|
|
||||||
if imwidth != self.height or imheight != self.width:
|
if imwidth != self.height or imheight != self.width:
|
||||||
raise ValueError('Image must be same dimensions as display \
|
raise ValueError('Image must be same dimensions as display \
|
||||||
({0}x{1}).' .format(self.height, self.width))
|
({0}x{1}).' .format(self.height, self.width))
|
||||||
|
|
||||||
|
image_buf = self.__prepare_image__(image)
|
||||||
for x in range(self.width):
|
for x in range(self.width):
|
||||||
for y in range(self.height):
|
for y in range(self.height):
|
||||||
# Set the bits for the column of pixels at the current
|
# Set the bits for the column of pixels at the current
|
||||||
# position.
|
# position.
|
||||||
pixel = image_rgb.getpixel((y, x))
|
if image_buf[x, y, 1] == 255: #White
|
||||||
color = self.__get_color__(pixel)
|
|
||||||
if color is 'white':
|
|
||||||
buf[int((y + x * self.height) / 4)] |= 0xC0 >> (y % 4 * 2)
|
buf[int((y + x * self.height) / 4)] |= 0xC0 >> (y % 4 * 2)
|
||||||
elif color is 'black':
|
elif image_buf[x, y, 0] == 0: #Black
|
||||||
buf[int((y + x * self.height) / 4)] &= ~(0xC0 >> (y % 4 * 2))
|
buf[int((y + x * self.height) / 4)] &= ~(0xC0 >> (y % 4 * 2))
|
||||||
if color is 'red':
|
else: #Red
|
||||||
buf[int((y + x * self.height) / 4)] &= ~(0xC0 >> (y % 4 * 2))
|
buf[int((y + x * self.height) / 4)] &= ~(0xC0 >> (y % 4 * 2))
|
||||||
buf[int((y + x * self.height) / 4)] |= 0x40 >> (y % 4 * 2)
|
buf[int((y + x * self.height) / 4)] |= 0x40 >> (y % 4 * 2)
|
||||||
return buf #due to python2 -> python3, int had to be added in 'get_frame
|
return buf
|
||||||
#_buffer
|
|
||||||
|
|
||||||
def __get_color__ (self, pixel):
|
def __prepare_image__(self, image):
|
||||||
color_percent = self.__get_color_percentage__(pixel)
|
buffer = np.array(image)
|
||||||
brightness = self.__brightness__(pixel)
|
r,g = buffer[:,:,0], buffer[:,:,1]
|
||||||
if brightness > 240:
|
buffer[np.logical_and(r > 240, g > 240)] = [255,255,255]
|
||||||
return 'white'
|
buffer[r > g] = [255,0,0]
|
||||||
elif color_percent[0] > 35:
|
buffer[r != 255] = [0,0,0]
|
||||||
return 'red'
|
return buffer
|
||||||
else:
|
|
||||||
return 'black'
|
|
||||||
|
|
||||||
def __get_color_percentage__ (self, pixel):
|
|
||||||
sum = pixel[0] + pixel[1] + pixel[2]
|
|
||||||
if sum is 0:
|
|
||||||
return (0,0,0)
|
|
||||||
return (pixel[0] / sum * 100, pixel[1] / sum * 100, pixel[2] / sum * 100)
|
|
||||||
|
|
||||||
def __brightness__ (self, pixel):
|
|
||||||
return (pixel[0] + pixel[1] + pixel[2]) / 3
|
|
||||||
|
|
||||||
def calibrate (self):
|
def calibrate (self):
|
||||||
for _ in range(2):
|
for _ in range(2):
|
||||||
|
|
|
@ -4,10 +4,7 @@ from ics import Calendar
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
import re
|
import re
|
||||||
from settings import week_starts_on
|
from settings import week_starts_on
|
||||||
try:
|
from urllib.request import urlopen
|
||||||
from urllib.request import urlopen
|
|
||||||
except Exception as e:
|
|
||||||
print("Something didn't work right, maybe you're offline?" + e.reason)
|
|
||||||
|
|
||||||
class IcalEvents(CalendarInterface):
|
class IcalEvents(CalendarInterface):
|
||||||
"""Fetches events from ical addresses."""
|
"""Fetches events from ical addresses."""
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from RssInterface import RssInterface
|
from RssInterface import RssInterface
|
||||||
from datetime import datetime, timedelta, date
|
from datetime import datetime, timedelta, date
|
||||||
import feedparser
|
import feedparser
|
||||||
import arrow
|
|
||||||
import RssPost
|
import RssPost
|
||||||
|
|
||||||
max_range_days = 14
|
max_range_days = 14
|
||||||
|
|
|
@ -21,7 +21,7 @@ if [ -z "$option" ]; then
|
||||||
fi
|
fi
|
||||||
if [ "$option" = 3 ]; then
|
if [ "$option" = 3 ]; then
|
||||||
echo -e "Removing the E-Paper software now..."
|
echo -e "Removing the E-Paper software now..."
|
||||||
pip3 uninstall feedparser -y && sudo pip3 uninstall feedparser -y && pip3 uninstall Pillow -y && sudo pip3 uninstall Pillow -y && sudo pip3 uninstall pyowm -y&& sudo pip3 uninstall ics -y && pip3 uninstall pyowm -y && pip3 uninstall ics -y && sudo apt-get remove supervisor -y && sudo apt-get clean && sudo apt-get autoremove -y
|
pip3 uninstall feedparser -y && sudo pip3 uninstall feedparser -y && pip3 uninstall numpy -y && sudo pip3 uninstall numpy -y && pip3 uninstall Pillow -y && sudo pip3 uninstall Pillow -y && sudo pip3 uninstall pyowm -y&& sudo pip3 uninstall ics -y && pip3 uninstall pyowm -y && pip3 uninstall ics -y && sudo apt-get remove supervisor -y && sudo apt-get clean && sudo apt-get autoremove -y
|
||||||
if [ -e /etc/supervisor/conf.d/E-Paper.conf ]; then
|
if [ -e /etc/supervisor/conf.d/E-Paper.conf ]; then
|
||||||
sudo rm /etc/supervisor/conf.d/E-Paper.conf
|
sudo rm /etc/supervisor/conf.d/E-Paper.conf
|
||||||
fi
|
fi
|
||||||
|
@ -82,9 +82,11 @@ if [ "$option" = 2 ]; then
|
||||||
sudo pip3 install pyowm
|
sudo pip3 install pyowm
|
||||||
sudo pip3 install ics
|
sudo pip3 install ics
|
||||||
sudo pip3 install feedparser
|
sudo pip3 install feedparser
|
||||||
|
sudo pip3 install numpy
|
||||||
pip3 install pyowm
|
pip3 install pyowm
|
||||||
pip3 install ics
|
pip3 install ics
|
||||||
pip3 install feedparser
|
pip3 install feedparser
|
||||||
|
pip3 install numpy
|
||||||
echo -e "\e[1;36m"Finished installing libraries"\e[0m"
|
echo -e "\e[1;36m"Finished installing libraries"\e[0m"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue