Skip to content

Commit c9a14e7

Browse files
committed
Include background image.
1 parent fa36329 commit c9a14e7

File tree

4 files changed

+140
-22
lines changed

4 files changed

+140
-22
lines changed

Video_Audio_Player/Video_Audio_Player.ino

Lines changed: 139 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#define circuit Computing_Shield2
1818

19+
#include "jpeglib.h"
1920
#include "Adafruit_GFX.h"
2021
#include "ZPUino_GFX.h"
2122
#include "PLL.h"
@@ -32,6 +33,8 @@
3233
#include "cbuffer.h"
3334
#include <Timer.h>
3435

36+
37+
3538
YM2149 ym2149;
3639
YMPLAYER ymplayer;
3740
//SID sid;
@@ -60,6 +63,90 @@ enum kButtonDirection {
6063
None = 5
6164
};
6265

66+
67+
//Image stuff.
68+
int width, height;
69+
70+
71+
72+
#define COLOR_BYTES 2
73+
#define COLOR_WEIGHT_R 5
74+
#define COLOR_WEIGHT_G 6
75+
#define COLOR_WEIGHT_B 5
76+
77+
#define COLOR_SHIFT_R (COLOR_WEIGHT_B+COLOR_WEIGHT_G)
78+
#define COLOR_SHIFT_G (COLOR_WEIGHT_B)
79+
#define COLOR_SHIFT_B 0
80+
81+
82+
unsigned short *imgbuf;
83+
84+
85+
86+
87+
void jpeg_error(jpeg_common_struct*)
88+
{
89+
printf("Error reading JPEG\r\n");
90+
while (1) {
91+
}
92+
}
93+
94+
int readjpeg(const char *file)
95+
{
96+
jpeg_decompress_struct cinfo;
97+
98+
jpeg_error_mgr defaultErrorManager;
99+
100+
cinfo.err = jpeg_std_error(&defaultErrorManager);
101+
102+
defaultErrorManager.error_exit = &jpeg_error;
103+
104+
FILE* pFile = fopen(file, "rb");
105+
if (!pFile)
106+
return -1;
107+
108+
jpeg_create_decompress(&cinfo);
109+
jpeg_stdio_src(&cinfo, pFile);
110+
jpeg_read_header(&cinfo, TRUE);
111+
jpeg_start_decompress(&cinfo);
112+
113+
printf("JPEG image info: %d x %d\n", cinfo.image_width, cinfo.image_height);
114+
115+
unsigned row_stride = cinfo.output_width * cinfo.output_components;
116+
117+
unsigned char *buffer = (unsigned char*)malloc(row_stride);
118+
119+
unsigned short v;
120+
uint16_t *imgbuf = gfx.getFramebuffer();
121+
122+
while(cinfo.output_scanline < cinfo.image_height)
123+
{
124+
int s = jpeg_read_scanlines(&cinfo, &buffer, 1);
125+
printf("%d\r\n",cinfo.output_scanline);
126+
unsigned char *ptr = buffer;
127+
int x;
128+
for (x=0; x<cinfo.image_width; x++) {
129+
uint16_t r = (ptr[0] >> (8 - COLOR_WEIGHT_R));
130+
uint16_t g = (ptr[1] >> (8 - COLOR_WEIGHT_G));
131+
uint16_t b = (ptr[2] >> (8 - COLOR_WEIGHT_B));
132+
v = (r<<(COLOR_SHIFT_R)) + (g<<COLOR_SHIFT_G) + (b<<COLOR_SHIFT_B);
133+
*imgbuf=v;
134+
ptr+=3;
135+
imgbuf++;
136+
}
137+
}
138+
jpeg_finish_decompress(&cinfo);
139+
jpeg_destroy_decompress(&cinfo);
140+
fclose(pFile);
141+
free(buffer);
142+
printf("All done\r\n");
143+
return 0;
144+
145+
}
146+
147+
148+
149+
63150
unsigned long timeout;
64151
int sidplayercounter = 0;
65152
kButtonDirection buttonPressed;
@@ -98,11 +185,34 @@ static void ymStart(void*)
98185

99186
#define MAXFILES 32
100187

188+
int fileExtension(const char* name, const char* extension, size_t length)
189+
{
190+
//Serial.println(extension);
191+
const char* ldot = strrchr(name, '.');
192+
if (ldot != NULL)
193+
{
194+
if (length == 0)
195+
length = strlen(extension);
196+
return strncmp(ldot + 1, extension, length) == 0;
197+
}
198+
return 0;
199+
}
200+
101201
char fileNames[MAXFILES][32];
102202

103203
static void onOpenFile(void *data)
104204
{
105-
char *name = (char*)data;
205+
char *name = (char*)data;
206+
if (fileExtension(name,"sid",3)) {
207+
sidplayer.loadFile(name);
208+
sidplayer.play(true);
209+
ymplayer.play(false);
210+
}
211+
if (fileExtension(name,"ymd",3)) {
212+
ymplayer.loadFile(name);
213+
ymplayer.play(true);
214+
sidplayer.play(false);
215+
}
106216
// Process file here.
107217
}
108218

@@ -139,6 +249,13 @@ static void createFileSelectionMenu(subMenu *menu, const char *filter_ext = NULL
139249
static void createMenus()
140250
{
141251
subMenu *config = new subMenu("Options");
252+
253+
subMenu *play = new subMenu("Play SID Files");
254+
config->appendChild(play);
255+
play->setParent(config);
256+
//createFileSelectionMenu(play, ".sid");
257+
createFileSelectionMenu(play);
258+
play->appendChild( new menuItem("< Back",(void(*)(void*))&menuSwitchTo, config) ) ;
142259

143260
// subMenu *sid = new subMenu("SID Audio");
144261
// config->appendChild(sid);
@@ -162,11 +279,7 @@ static void createMenus()
162279
config->appendChild( new menuItem("Exit",(void(*)(void*))&exitMenus) ) ;
163280

164281

165-
subMenu *play = new subMenu("Play");
166-
config->appendChild(play);
167-
play->setParent(config);
168-
createFileSelectionMenu(play);
169-
play->appendChild( new menuItem("< Back",(void(*)(void*))&menuSwitchTo, config) ) ;
282+
170283

171284
menuSetTop(config);
172285
}
@@ -188,21 +301,23 @@ void setup()
188301
{
189302
//delay(3000);
190303
Serial.begin(115200);
191-
Serial.println("Starting");
192-
gfx.begin(MODE_640x480);
193-
//gfx.begin( &modeline_640x480_60 );
194-
createMenus();
195-
//menuInit(128,128);
196-
menuInit(256,256);
197-
menusSetRenderer(&gfx);
198-
304+
Serial.println("Starting");
305+
199306
//Start SmallFS
200307
if (SmallFS.begin()<0) {
201308
Serial.println("No SmalLFS found.");
202309
}
203310
else{
204311
Serial.println("SmallFS Started.");
205-
}
312+
}
313+
314+
gfx.begin(MODE_640x480);
315+
//gfx.begin( &modeline_640x480_60 );
316+
createMenus();
317+
//menuInit(128,128);
318+
menuInit(256,256);
319+
menusSetRenderer(&gfx);
320+
206321

207322
//Set Wishbone slots for audio chips
208323
//sid.setup(14);
@@ -217,11 +332,11 @@ void setup()
217332
ym2149.V3.setVolume(15);
218333
//sid.setVolume(15);
219334

220-
sidplayer.loadFile("track1.sid");
221-
sidplayer.play(true);
222-
223-
ymplayer.loadFile("track2.ymd");
224-
ymplayer.play(true);
335+
// sidplayer.loadFile("track1.sid");
336+
// sidplayer.play(true);
337+
//
338+
// ymplayer.loadFile("track2.ymd");
339+
// ymplayer.play(true);
225340

226341
//Setup timer for YM and mod players, this generates an interrupt at 1700hz
227342
Timers.begin();
@@ -238,7 +353,9 @@ void setup()
238353
pinMode(JRIGHT, INPUT);
239354

240355
timeout=TIMEOUTMAX;
241-
showMenu();
356+
showMenu();
357+
358+
readjpeg("/smallfs/image.jpg");
242359
}
243360

244361
void loop()
@@ -295,6 +412,7 @@ void loop()
295412
}
296413
if (buttonPressed == Left) {
297414
//exitMenus(0);
415+
menuShowTop();
298416
}
299417
} else {
300418
if (buttonPressed == Select) {
120 KB
Loading

hdmi-generic/smallfs/image.jpg

120 KB
Loading

libraries/menus/menus.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void renderSingleSubMenu(subMenu *menu)
9797
int ypos = FIRSTITEMVPOS;
9898

9999
GFXFrameBuffer.clear( 0 );
100-
GFXFrameBuffer.setTransparentColor(0xfefe);
100+
//GFXFrameBuffer.setTransparentColor(0xfefe);
101101
//GFXFrameBuffer.setAlpha(TITLEALPHA);
102102

103103
/* Draw top rectangle */

0 commit comments

Comments
 (0)