3
3
import gifio
4
4
except :
5
5
pass
6
+ import adafruit_ticks
6
7
import adafruit_imageload
7
8
import bitmaptools
8
9
import displayio
9
- import time
10
10
from os import getenv
11
11
try :
12
12
from pydos_ui import Pydos_ui
79
79
def playimage (passedIn = "" ):
80
80
81
81
if passedIn != "" :
82
- fname = passedIn
82
+ flist = passedIn
83
83
else :
84
- fname = ""
84
+ flist = ""
85
85
86
- if fname == "" :
87
- fname = input ("Enter filename: " )
86
+ if flist == "" :
87
+ flist = input ("Enter filename: " )
88
88
try :
89
89
while Pydos_ui .virt_touched ():
90
90
pass
91
91
except :
92
92
pass
93
93
94
- if fname == passedIn :
94
+ if flist == passedIn :
95
95
print ('Press "q" to quit' )
96
96
else :
97
97
input ('Press "Enter" to continue, press "q" to quit' )
98
98
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
107
105
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
133
109
134
- input ('Press Enter to close' )
110
+ fileindx = 0
111
+ wildindx = 0
112
+ while True :
113
+ fname = files [fileindx ]
135
114
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 )
137
123
138
- odgcc = gifio .OnDiskGif (fname )
139
- with odgcc as odg :
140
124
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" ]:
145
126
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
149
133
150
134
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))
156
141
pwidth = bitframe .width
157
142
pheight = bitframe .height
158
143
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
163
148
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
+
164
154
if pwidth < display .width :
165
155
facecc .x = (display .width - pwidth )// 2
166
156
if pheight < display .height :
@@ -169,27 +159,104 @@ def playimage(passedIn=""):
169
159
splash .append (facecc )
170
160
display .root_group = splash
171
161
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
190
176
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' )
193
260
194
261
try :
195
262
splash .pop ()
0 commit comments