Skip to content

Commit 99aa41e

Browse files
committed
Add slideshow function to playimage
1 parent f0358bc commit 99aa41e

File tree

4 files changed

+151
-81
lines changed

4 files changed

+151
-81
lines changed

PyDOS.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def PyDOS():
7373
global envVars
7474
if "envVars" not in globals().keys():
7575
envVars = {}
76-
_VER = "1.43"
76+
_VER = "1.44"
7777
prmpVals = ['>','(',')','&','|','\x1b','\b','<','=',' ',_VER,'\n','$','']
7878

7979
print("Starting Py-DOS...")

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ down - the number of tiles connected down the matrix display
200200

201201
If the parameters are omitted or not properly formatted, the program will prompt for each of the values.
202202

203-
**Playimage.py [filename]** - (Circuitpython only, requires the adafruit_imageload library installed in the /lib folder) program to display .bmp, .jpg, .gif or .png image files. If the program is loaded from PyDOS it attempts to determine the appropriate display configuration from the PyDOS environment, otherwise several display options are supported and selected depending on the existence of BOARD.Display or locally installed display libraries.
203+
**Playimage.py [filename[,filename2,filename3,etc,[seconds_to_display]]]** - (Circuitpython only, requires the adafruit_imageload library installed in the /lib folder) program to display .bmp, .jpg, .gif (incl animaged) or .png image files. If multiple comma
204+
seperated files are entered a continous slide show is displayed with each image being
205+
displayed for `seconds_to_display` seconds. If the program is loaded from PyDOS it attempts to determine the appropriate display configuration from the PyDOS environment, otherwise several display options are supported and selected depending on the existence of BOARD.Display or locally installed display libraries.
204206

205207
**reboot.py** - performs a soft reboot (Micropython requires a Ctrl-D to complete)
206208

cpython/matrix.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
[base_width,base_height,bit_depth,chain_across,tile_down] = [int(p) for p in args]
1414
except:
1515
passedIn = ""
16+
args = ""
1617

1718
if len(args) != 5 or args[0] not in ['32','64'] or args[1] not in ['32','64'] or bit_depth < 1 or bit_depth > 8:
1819
try:

cpython/playimage.py

Lines changed: 146 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import gifio
44
except:
55
pass
6+
import adafruit_ticks
67
import adafruit_imageload
78
import bitmaptools
89
import displayio
9-
import time
1010
from os import getenv
1111
try:
1212
from pydos_ui import Pydos_ui
@@ -79,88 +79,78 @@
7979
def playimage(passedIn=""):
8080

8181
if passedIn != "":
82-
fname = passedIn
82+
flist = passedIn
8383
else:
84-
fname = ""
84+
flist = ""
8585

86-
if fname == "":
87-
fname = input("Enter filename: ")
86+
if flist == "":
87+
flist = input("Enter filename: ")
8888
try:
8989
while Pydos_ui.virt_touched():
9090
pass
9191
except:
9292
pass
9393

94-
if fname==passedIn:
94+
if flist==passedIn:
9595
print('Press "q" to quit')
9696
else:
9797
input('Press "Enter" to continue, press "q" to quit')
9898

99-
if fname[-4:].upper() in [".BMP",".PNG",".JPG",".RLE"]:
100-
101-
bitmap, palette = adafruit_imageload.load( \
102-
fname, bitmap=displayio.Bitmap, palette=displayio.Palette)
103-
104-
scalefactor = display.width / bitmap.width
105-
if display.height/bitmap.height < scalefactor:
106-
scalefactor = display.height/bitmap.height
99+
files = flist.split(',')
100+
try:
101+
dispseconds = int(files[-1])
102+
files = files[:-1]
103+
except:
104+
dispseconds = 15
107105

108-
if scalefactor < 1:
109-
print(f'scalefactor: {scalefactor}')
110-
bitframe = displayio.Bitmap(display.width,display.height,2**bitmap.bits_per_value)
111-
bitmaptools.rotozoom(bitframe,bitmap,scale=scalefactor)
112-
facecc = displayio.TileGrid(bitframe,pixel_shader=palette)
113-
# pixel_shader=displayio.ColorConverter(input_colorspace=colorspace))
114-
pwidth = bitframe.width
115-
pheight = bitframe.height
116-
else:
117-
facecc = displayio.TileGrid(bitmap,pixel_shader=palette)
118-
# pixel_shader=displayio.ColorConverter(input_colorspace=colorspace))
119-
pwidth = bitmap.width
120-
pheight = bitmap.height
121-
122-
print("bitmap (w,h): ",bitmap.width,bitmap.height)
123-
print("scaled bitmap (w,h): ",pwidth,pheight)
124-
print("facecc (w,h): ",facecc.width,facecc.height)
125-
126-
if pwidth < display.width:
127-
facecc.x = (display.width-pwidth)//2
128-
if pheight < display.height:
129-
facecc.y = (display.height-pheight)//2
130-
splash = displayio.Group()
131-
splash.append(facecc)
132-
display.root_group = splash
106+
singleimage = False
107+
if len(files) == 1 and files[0][0] != '*':
108+
singleimage = True
133109

134-
input('Press Enter to close')
110+
fileindx = 0
111+
wildindx = 0
112+
while True:
113+
fname = files[fileindx]
135114

136-
elif fname[-4:].upper() in [".GIF"]:
115+
if fname[0] == '*':
116+
wildlist = [f for f in os.listdir() if f[fname.find('.')-len(fname):] == fname[fname.find('.')-len(fname):]]
117+
fname = wildlist[wildindx]
118+
wildindx = (wildindx +1) % len(wildlist)
119+
if wildindx == 0:
120+
fileindx = (fileindx + 1) % len(files)
121+
else:
122+
fileindx = (fileindx + 1) % len(files)
137123

138-
odgcc = gifio.OnDiskGif(fname)
139-
with odgcc as odg:
140124

141-
if getenv('PYDOS_DISPLAYIO_COLORSPACE',"").upper() == 'BGR565_SWAPPED':
142-
colorspace = displayio.Colorspace.BGR565_SWAPPED
143-
else:
144-
colorspace = displayio.Colorspace.RGB565_SWAPPED
125+
if fname[-4:].upper() in [".BMP",".PNG",".JPG",".RLE"]:
145126

146-
scalefactor = display.width / odg.width
147-
if display.height/odg.height < scalefactor:
148-
scalefactor = display.height/odg.height
127+
bitmap, palette = adafruit_imageload.load( \
128+
fname, bitmap=displayio.Bitmap, palette=displayio.Palette)
129+
130+
scalefactor = display.width / bitmap.width
131+
if display.height/bitmap.height < scalefactor:
132+
scalefactor = display.height/bitmap.height
149133

150134
if scalefactor < 1:
151-
print(f'scalefactor: {scalefactor}')
152-
bitframe = displayio.Bitmap(display.width,display.height,2**odg.bitmap.bits_per_value)
153-
bitmaptools.rotozoom(bitframe,odg.bitmap,scale=scalefactor)
154-
facecc = displayio.TileGrid(bitframe, \
155-
pixel_shader=displayio.ColorConverter(input_colorspace=colorspace))
135+
if singleimage:
136+
print(f'scalefactor: {scalefactor}')
137+
bitframe = displayio.Bitmap(display.width,display.height,2**bitmap.bits_per_value)
138+
bitmaptools.rotozoom(bitframe,bitmap,scale=scalefactor)
139+
facecc = displayio.TileGrid(bitframe,pixel_shader=palette)
140+
# pixel_shader=displayio.ColorConverter(input_colorspace=colorspace))
156141
pwidth = bitframe.width
157142
pheight = bitframe.height
158143
else:
159-
facecc = displayio.TileGrid(odg.bitmap, \
160-
pixel_shader=displayio.ColorConverter(input_colorspace=colorspace))
161-
pwidth = odg.bitmap.width
162-
pheight = odg.bitmap.height
144+
facecc = displayio.TileGrid(bitmap,pixel_shader=palette)
145+
# pixel_shader=displayio.ColorConverter(input_colorspace=colorspace))
146+
pwidth = bitmap.width
147+
pheight = bitmap.height
163148

149+
if singleimage:
150+
print("bitmap (w,h): ",bitmap.width,bitmap.height)
151+
print("scaled bitmap (w,h): ",pwidth,pheight)
152+
print("facecc (w,h): ",facecc.width,facecc.height)
153+
164154
if pwidth < display.width:
165155
facecc.x = (display.width-pwidth)//2
166156
if pheight < display.height:
@@ -169,27 +159,104 @@ def playimage(passedIn=""):
169159
splash.append(facecc)
170160
display.root_group = splash
171161

172-
start = 0
173-
next_delay = -1
174-
cmnd = ""
175-
# Display repeatedly.
176-
while cmnd.upper() != "Q":
177-
178-
if Pydos_ui.serial_bytes_available():
179-
cmnd = Pydos_ui.read_keyboard(1)
180-
print(cmnd, end="", sep="")
181-
if cmnd in "qQ":
182-
break
183-
while time.monotonic() > start and next_delay > time.monotonic()-start:
184-
pass
185-
next_delay = odg.next_frame()
186-
start = time.monotonic()
187-
if next_delay > 0:
188-
if scalefactor < 1:
189-
bitmaptools.rotozoom(bitframe,odg.bitmap,scale=scalefactor)
162+
if singleimage:
163+
input('Press Enter to close')
164+
break
165+
else:
166+
cmnd = ""
167+
stop = adafruit_ticks.ticks_add(adafruit_ticks.ticks_ms(),int(dispseconds*1000))
168+
while adafruit_ticks.ticks_less(adafruit_ticks.ticks_ms(),stop):
169+
if Pydos_ui.serial_bytes_available():
170+
cmnd = Pydos_ui.read_keyboard(1)
171+
print(cmnd, end="", sep="")
172+
if cmnd.upper() == "Q":
173+
break
174+
if cmnd.upper() == "Q":
175+
break
190176

191-
else:
192-
print('Unknown filetype')
177+
try:
178+
splash.pop()
179+
bitmap.deinit()
180+
bitmap = None
181+
facecc.bitmap.deinit()
182+
facecc = None
183+
if scalefactor < 1:
184+
bitframe.deinit()
185+
bitframe = None
186+
except:
187+
pass
188+
189+
elif fname[-4:].upper() in [".GIF"]:
190+
191+
odgcc = gifio.OnDiskGif(fname)
192+
with odgcc as odg:
193+
194+
if getenv('PYDOS_DISPLAYIO_COLORSPACE',"").upper() == 'BGR565_SWAPPED':
195+
colorspace = displayio.Colorspace.BGR565_SWAPPED
196+
else:
197+
colorspace = displayio.Colorspace.RGB565_SWAPPED
198+
199+
scalefactor = display.width / odg.width
200+
if display.height/odg.height < scalefactor:
201+
scalefactor = display.height/odg.height
202+
203+
if scalefactor < 1:
204+
if singleimage:
205+
print(f'scalefactor: {scalefactor}')
206+
bitframe = displayio.Bitmap(display.width,display.height,2**odg.bitmap.bits_per_value)
207+
bitmaptools.rotozoom(bitframe,odg.bitmap,scale=scalefactor)
208+
facecc = displayio.TileGrid(bitframe, \
209+
pixel_shader=displayio.ColorConverter(input_colorspace=colorspace))
210+
pwidth = bitframe.width
211+
pheight = bitframe.height
212+
else:
213+
facecc = displayio.TileGrid(odg.bitmap, \
214+
pixel_shader=displayio.ColorConverter(input_colorspace=colorspace))
215+
pwidth = odg.bitmap.width
216+
pheight = odg.bitmap.height
217+
218+
if pwidth < display.width:
219+
facecc.x = (display.width-pwidth)//2
220+
if pheight < display.height:
221+
facecc.y = (display.height-pheight)//2
222+
splash = displayio.Group()
223+
splash.append(facecc)
224+
display.root_group = splash
225+
226+
cmnd = ""
227+
# Display repeatedly.
228+
stop = adafruit_ticks.ticks_add(adafruit_ticks.ticks_ms(),int(dispseconds*1000))
229+
while adafruit_ticks.ticks_less(adafruit_ticks.ticks_ms(),stop) or dispseconds==-1:
230+
231+
if Pydos_ui.serial_bytes_available():
232+
cmnd = Pydos_ui.read_keyboard(1)
233+
print(cmnd, end="", sep="")
234+
if cmnd.upper() == "Q":
235+
break
236+
start = adafruit_ticks.ticks_ms()
237+
next_delay = odg.next_frame()
238+
start = adafruit_ticks.ticks_add(start,int(next_delay*1000))
239+
if next_delay > 0:
240+
if scalefactor < 1:
241+
bitmaptools.rotozoom(bitframe,odg.bitmap,scale=scalefactor)
242+
while adafruit_ticks.ticks_less(adafruit_ticks.ticks_ms(),start):
243+
pass
244+
if cmnd.upper() == "Q":
245+
break
246+
247+
try:
248+
splash.pop()
249+
odgcc = None
250+
facecc.bitmap.deinit()
251+
facecc = None
252+
if scalefactor < 1:
253+
bitframe.deinit()
254+
bitframe = None
255+
except:
256+
pass
257+
258+
else:
259+
print('Unknown filetype')
193260

194261
try:
195262
splash.pop()

0 commit comments

Comments
 (0)