commit
2e2b625655
@ -1,3 +1,7 @@
|
||||
0.8.3
|
||||
- draw_image with filename or PIL object
|
||||
0.8.2
|
||||
- fix background colour in Page drawing
|
||||
0.8.1
|
||||
- clean up
|
||||
0.8.0
|
||||
|
@ -41,9 +41,12 @@ class Chip(metaclass=abc.ABCMeta):
|
||||
@color.setter
|
||||
def color(self, rgb):
|
||||
"""set (R, G, B) colour """
|
||||
self.options['color'] = {
|
||||
'R': rgb[0], 'G': rgb[1], 'B': rgb[2]
|
||||
}
|
||||
if isinstance(rgb, int):
|
||||
self.options['color'] = rgb
|
||||
else:
|
||||
self.options['color'] = {
|
||||
'R': rgb[0], 'G': rgb[1], 'B': rgb[2]
|
||||
}
|
||||
|
||||
@property
|
||||
def background_color(self):
|
||||
@ -53,9 +56,12 @@ class Chip(metaclass=abc.ABCMeta):
|
||||
@background_color.setter
|
||||
def background_color(self, rgb):
|
||||
"""set (R, G, B) background colour """
|
||||
self.options['background_color'] = {
|
||||
'R': rgb[0], 'G': rgb[1], 'B': rgb[2]
|
||||
}
|
||||
if isinstance(rgb, int):
|
||||
self.options['background_color'] = rgb
|
||||
else:
|
||||
self.options['background_color'] = {
|
||||
'R': rgb[0], 'G': rgb[1], 'B': rgb[2]
|
||||
}
|
||||
|
||||
@property
|
||||
def auto_flush(self):
|
||||
|
@ -14,9 +14,10 @@ lcd_tft = ILI9325(240, 320, drv)
|
||||
lcd_tft.init()
|
||||
|
||||
|
||||
image_file = Image.open("assets/japan_temple_240x320.jpg")
|
||||
lcd_tft.draw_image(0, 0, image_file)
|
||||
# image_file = Image.open("assets/japan_temple_240x320.jpg")
|
||||
# lcd_tft.draw_image(0, 0, image_file)
|
||||
|
||||
numbers_image = Image.open("assets/dsp2017_101_64.png")
|
||||
# numbers_image = Image.open("assets/dsp2017_101_64.png")
|
||||
lcd_tft.transparency_color = (0, 0, 0)
|
||||
lcd_tft.draw_image(10, 10, numbers_image)
|
||||
# lcd_tft.draw_image(10, 10, numbers_image)
|
||||
lcd_tft.draw_image(10, 10, "assets/dsp2017_101_64.png")
|
||||
|
@ -16,7 +16,8 @@ def test1():
|
||||
print(drv.width, drv.height)
|
||||
lcd = CharLCD(drv.width, drv.height, drv, 0, 0)
|
||||
lcd.init()
|
||||
lcd.write('First')
|
||||
lcd.write('First Line')
|
||||
lcd.write(' it is not', 0, 0)
|
||||
|
||||
lcd.write('HD44780', 6, 3)
|
||||
lcd.flush()
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""Area drawing algorithm"""
|
||||
import itertools
|
||||
from gfxlcd.drawing.pixel import Pixel
|
||||
from PIL import Image
|
||||
|
||||
|
||||
class Area(Pixel):
|
||||
@ -103,6 +104,8 @@ class Area(Pixel):
|
||||
|
||||
def draw_image(self, pos_x, pos_y, image):
|
||||
"""draw a PIL image"""
|
||||
if isinstance(image, str):
|
||||
image = Image.open(image)
|
||||
image_file = image.convert('RGB')
|
||||
width, height = image_file.size
|
||||
self._set_area(
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""Page drawing algorithm"""
|
||||
import abc
|
||||
from gfxlcd.drawing.pixel import Pixel
|
||||
from PIL import Image
|
||||
|
||||
|
||||
class Page(Pixel, metaclass=abc.ABCMeta):
|
||||
@ -9,6 +10,8 @@ class Page(Pixel, metaclass=abc.ABCMeta):
|
||||
self.driver = driver
|
||||
Pixel.__init__(self, driver)
|
||||
self.buffer = []
|
||||
self.options['color'] = 1
|
||||
self.options['background_color'] = 0
|
||||
|
||||
def init(self):
|
||||
"""init page"""
|
||||
@ -17,11 +20,21 @@ class Page(Pixel, metaclass=abc.ABCMeta):
|
||||
else:
|
||||
self.buffer = [[0] * (self.width // 8) for x in range(self.height)]
|
||||
|
||||
def _convert_color(self, color):
|
||||
"""convert color to available one"""
|
||||
if color == 0:
|
||||
return 0
|
||||
|
||||
return 1
|
||||
|
||||
def draw_pixel(self, pos_x, pos_y, color=None):
|
||||
"""draw a pixel at x,y"""
|
||||
if color is None:
|
||||
color = self.options['color']
|
||||
self.buffer[pos_x][pos_y//8] |= self._convert_color(color) << (pos_y % 8)
|
||||
if self._convert_color(color) == 1:
|
||||
self.buffer[pos_x][pos_y//8] |= 1 << (pos_y % 8)
|
||||
else:
|
||||
self.buffer[pos_x][pos_y//8] &= ~(1 << (pos_y % 8))
|
||||
self.flush()
|
||||
|
||||
def draw_line(self, pos_x1, pos_y1, pos_x2, pos_y2):
|
||||
@ -114,6 +127,8 @@ class Page(Pixel, metaclass=abc.ABCMeta):
|
||||
|
||||
def draw_image(self, pos_x, pos_y, image):
|
||||
"""draw a PIL image"""
|
||||
if isinstance(image, str):
|
||||
image = Image.open(image)
|
||||
image_file = image.convert('L')
|
||||
width, height = image_file.size
|
||||
offset_x = 0
|
||||
|
@ -35,13 +35,6 @@ class NJU6450(Page, Chip):
|
||||
self.driver.cmd(0xB8 | pos_y, 1)
|
||||
self.driver.cmd(0x00 | (pos_x - width//2), 1)
|
||||
|
||||
def _convert_color(self, color):
|
||||
"""convert color to avaiable one"""
|
||||
if color['R'] == 0 and color['G'] == 0 and color['B'] == 0:
|
||||
return 0
|
||||
|
||||
return 1
|
||||
|
||||
def flush(self, force=None):
|
||||
"""flush buffer to device
|
||||
:force - boolean|None"""
|
||||
|
@ -22,13 +22,6 @@ class NullPage(Page, Chip):
|
||||
Page.init(self)
|
||||
Chip.init(self)
|
||||
|
||||
def _convert_color(self, color):
|
||||
"""convert color to avaiable one"""
|
||||
if color['R'] == 0 and color['G'] == 0 and color['B'] == 0:
|
||||
return 0
|
||||
|
||||
return 1
|
||||
|
||||
def flush(self, force=None):
|
||||
"""flush buffer to device
|
||||
:force - boolean|None"""
|
||||
|
@ -76,13 +76,6 @@ class SSD1306(Page, Chip):
|
||||
self.driver.cmd(0x14) # enable charge pump
|
||||
self.driver.cmd(0xaf) # turn on panel
|
||||
|
||||
def _convert_color(self, color):
|
||||
"""convert color to avaiable one"""
|
||||
if color['R'] == 0 and color['G'] == 0 and color['B'] == 0:
|
||||
return 0
|
||||
|
||||
return 1
|
||||
|
||||
def flush(self, force=None):
|
||||
"""flush buffer to device
|
||||
:force - boolean|None"""
|
||||
|
@ -216,6 +216,17 @@ class TestPageDrawing(object):
|
||||
buffer[5][1] = 8
|
||||
assert_equal(self.lcd.buffer, buffer)
|
||||
|
||||
def test_draw_pixels_clear_then(self):
|
||||
self.lcd.draw_pixel(1, 1)
|
||||
self.lcd.draw_pixel(2, 1)
|
||||
self.lcd.draw_pixel(2, 2)
|
||||
buffer = self.get_buffer()
|
||||
buffer[2][0] = 4
|
||||
self.lcd.draw_pixel(1, 1, self.lcd.background_color)
|
||||
self.lcd.draw_pixel(2, 1, self.lcd.background_color)
|
||||
self.draw_buffer(self.lcd.buffer)
|
||||
assert_equal(self.lcd.buffer, buffer)
|
||||
|
||||
def draw_buffer(self, buffer):
|
||||
for page in range(2):
|
||||
print(page)
|
||||
|
@ -1,4 +1,4 @@
|
||||
[bdist_wheel]
|
||||
universal = 1
|
||||
universal = 0
|
||||
[metadata]
|
||||
description-file = readme.md
|
2
setup.py
2
setup.py
@ -13,7 +13,7 @@ def read(*paths):
|
||||
|
||||
setup(
|
||||
name='gfxlcd',
|
||||
version='0.8.1',
|
||||
version='0.8.3',
|
||||
description='gfxlcd is a handler for graphical lcds: ILI9328, SSD1306, NJU6450, touch panel: AD7843 @ Raspberry Pi.',
|
||||
keywords=[
|
||||
'gfxlcd', 'raspberry pi' ,'ili9328' ,'ssd1306', 'nju6450', 'lcd', 'graphical lcd', 'touch panel', 'ad7843',
|
||||
|
Loading…
Reference in New Issue
Block a user