Commit 01139765 authored by Russ Hughes's avatar Russ Hughes

Document jpg conversion using ImageMagick and another example for the T-Display

parent a4547cfa
'''
jpg.py
Randomly draw a jpg using the fast method
The alien.jpg is from the Erik Flowers Weather Icons available from
https://github.com/erikflowers/weather-icons and is licensed under
SIL OFL 1.1
It was was converted from the wi-alien.svg icon using
ImageMagick's convert utility:
convert wi-alien.svg -type TrueColor alien.jpg
'''
import gc
import random
from machine import Pin, SPI
import st7789
gc.enable()
gc.collect()
def main():
'''
Decode and draw jpg on display
'''
try:
spi = SPI(2, baudrate=30000000, sck=Pin(18), mosi=Pin(19))
tft = st7789.ST7789(
spi,
135,
240,
reset=Pin(23, Pin.OUT),
cs=Pin(5, Pin.OUT),
dc=Pin(16, Pin.OUT),
backlight=Pin(4, Pin.OUT),
rotation=3,
buffer_size = 30*30*2)
# enable display and clear screen
tft.init()
# display jpg in random locations
while True:
tft.jpg(
"alien.jpg",
random.randint(0, tft.width() - 30),
random.randint(0, tft.height() - 30),
st7789.FAST)
finally:
# shutdown spi
spi.deinit()
main()
...@@ -534,6 +534,8 @@ mp_obj_t dict_lookup(mp_obj_t self_in, mp_obj_t index) { ...@@ -534,6 +534,8 @@ mp_obj_t dict_lookup(mp_obj_t self_in, mp_obj_t index) {
return elem->value; return elem->value;
} }
} }
STATIC mp_obj_t st7789_ST7789_bitmap(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t st7789_ST7789_bitmap(size_t n_args, const mp_obj_t *args) {
st7789_ST7789_obj_t *self = MP_OBJ_TO_PTR(args[0]); st7789_ST7789_obj_t *self = MP_OBJ_TO_PTR(args[0]);
...@@ -551,7 +553,7 @@ STATIC mp_obj_t st7789_ST7789_bitmap(size_t n_args, const mp_obj_t *args) { ...@@ -551,7 +553,7 @@ STATIC mp_obj_t st7789_ST7789_bitmap(size_t n_args, const mp_obj_t *args) {
mp_obj_dict_t * dict = MP_OBJ_TO_PTR(bitmap->globals); mp_obj_dict_t * dict = MP_OBJ_TO_PTR(bitmap->globals);
const uint16_t height = mp_obj_get_int(mp_obj_dict_get(dict, MP_OBJ_NEW_QSTR(MP_QSTR_HEIGHT))); const uint16_t height = mp_obj_get_int(mp_obj_dict_get(dict, MP_OBJ_NEW_QSTR(MP_QSTR_HEIGHT)));
const uint16_t width = mp_obj_get_int(mp_obj_dict_get(dict, MP_OBJ_NEW_QSTR(MP_QSTR_WIDTH))); const uint16_t width = mp_obj_get_int(mp_obj_dict_get(dict, MP_OBJ_NEW_QSTR(MP_QSTR_WIDTH)));
uint16_t bitmaps = 0; // was = mp_obj_get_int(mp_obj_dict_get(dict, MP_OBJ_NEW_QSTR(MP_QSTR_BITMAPS))); uint16_t bitmaps = 0;
const uint8_t bpp = mp_obj_get_int(mp_obj_dict_get(dict, MP_OBJ_NEW_QSTR(MP_QSTR_BPP))); const uint8_t bpp = mp_obj_get_int(mp_obj_dict_get(dict, MP_OBJ_NEW_QSTR(MP_QSTR_BPP)));
mp_obj_t * palette_arg = mp_obj_dict_get(dict, MP_OBJ_NEW_QSTR(MP_QSTR_PALETTE)); mp_obj_t * palette_arg = mp_obj_dict_get(dict, MP_OBJ_NEW_QSTR(MP_QSTR_PALETTE));
mp_obj_t * palette = NULL; mp_obj_t * palette = NULL;
......
#
# You can convert images to compatible jpg's by using ImageMagick's convert
# utility by specifying the output type as TrueColor. ImageMagick downloads
# are available from https://imagemagick.org/ for Linux, OSX, Windows and
# other operating systems.
#
# The wi-alien.svg icon is from https://github.com/erikflowers/weather-icons
# licensed under SIL OFL 1.1
#
convert wi-alien.svg -type TrueColor alien.jpg
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 22.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 30 30" style="enable-background:new 0 0 30 30;" xml:space="preserve">
<path d="M8.75,15.54c-1.12-2.4-0.95-4.66,0.52-6.79c1.03-1.48,2.6-2.39,4.73-2.72c0.16-0.04,0.34-0.07,0.54-0.08h0.63
c2.91,0.09,5.05,1.38,6.4,3.88c0.64,1.18,0.8,2.48,0.48,3.91c-0.26,1.13-0.68,2.19-1.28,3.17c-1.29,2.01-2.63,3.64-4,4.88
c-0.07,0.07-0.17,0.16-0.3,0.26c-0.46,0.35-0.89,0.53-1.28,0.54s-0.83-0.14-1.31-0.45c-0.29-0.17-0.53-0.37-0.74-0.59
C11.18,19.55,9.71,17.55,8.75,15.54z M8.86,13.33c0.02,0.11,0.05,0.25,0.09,0.44s0.07,0.32,0.09,0.4c0.28,1.26,0.86,2.23,1.73,2.93
c0.88,0.7,1.96,1.11,3.26,1.23c0.29,0.03,0.46,0.02,0.51-0.03s0.08-0.23,0.09-0.52c-0.01-0.08-0.03-0.21-0.05-0.39
c-0.02-0.18-0.04-0.31-0.06-0.39c-0.25-1.34-0.88-2.32-1.9-2.93c-0.18-0.11-0.39-0.22-0.62-0.34s-0.44-0.2-0.61-0.27
c-0.17-0.07-0.4-0.16-0.69-0.27c-0.29-0.11-0.5-0.19-0.63-0.25c-0.16-0.06-0.42-0.1-0.8-0.11C8.95,12.83,8.81,13,8.86,13.33z
M15.66,17.73c-0.02,0.31,0,0.49,0.06,0.56c0.07,0.07,0.25,0.08,0.55,0.04c0.38-0.04,0.78-0.12,1.2-0.22
c1.07-0.27,1.94-0.84,2.62-1.71c0.34-0.41,0.6-0.86,0.77-1.34s0.34-1.05,0.47-1.72c0.05-0.23,0.04-0.38-0.03-0.46
c-0.07-0.08-0.22-0.11-0.44-0.08c-0.59,0.1-1.12,0.23-1.59,0.4c-1.15,0.43-2.02,1.01-2.62,1.74C16.05,15.68,15.72,16.6,15.66,17.73z
"/>
</svg>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment