comparison src/projectm-1.0/main.cxx @ 2246:f06b48381052

- drop protected: declarations, protected: is not needed here (and causes error on gcc4.3) - new screenshot code
author William Pitcock <nenolod@atheme.org>
date Mon, 17 Dec 2007 15:51:45 -0600
parents 0edf1cb262c0
children 822c887712dc
comparison
equal deleted inserted replaced
2245:0edf1cb262c0 2246:f06b48381052
38 extern "C" void projectM_xmms_init(void); 38 extern "C" void projectM_xmms_init(void);
39 extern "C" void projectM_cleanup(void); 39 extern "C" void projectM_cleanup(void);
40 extern "C" void projectM_render_pcm(gint16 pcm_data[2][512]); 40 extern "C" void projectM_render_pcm(gint16 pcm_data[2][512]);
41 extern "C" int worker_func(void *); 41 extern "C" int worker_func(void *);
42 std::string read_config(); 42 std::string read_config();
43 void saveSnapshotToFile();
44 43
45 extern "C" VisPlugin projectM_vtable; 44 extern "C" VisPlugin projectM_vtable;
46 45
47 int SDLThreadWrapper(void *); 46 int SDLThreadWrapper(void *);
48 void handle_playback_trigger(void *, void *); 47 void handle_playback_trigger(void *, void *);
59 SDL_Event event; 58 SDL_Event event;
60 SDL_Surface *screen; 59 SDL_Surface *screen;
61 SDL_Thread *worker_thread; 60 SDL_Thread *worker_thread;
62 SDL_sem *sem; 61 SDL_sem *sem;
63 62
64 protected: 63 public:
65 projectMPlugin() 64 projectMPlugin()
66 { 65 {
67 std::string configFile = read_config(); 66 std::string configFile = read_config();
68 ConfigFile config(configFile); 67 ConfigFile config(configFile);
69 68
110 this->pm = 0; 109 this->pm = 0;
111 110
112 aud_hook_dissociate("playback begin", handle_playback_trigger); 111 aud_hook_dissociate("playback begin", handle_playback_trigger);
113 } 112 }
114 113
115 public:
116 int run(void *unused) 114 int run(void *unused)
117 { 115 {
118 if (error) 116 if (error)
119 return -1; 117 return -1;
120 118
143 { 141 {
144 case PROJECTM_KEYDOWN: 142 case PROJECTM_KEYDOWN:
145 switch (key) 143 switch (key)
146 { 144 {
147 case PROJECTM_K_c: 145 case PROJECTM_K_c:
148 saveSnapshotToFile(); 146 this->takeScreenshot();
149 break; 147 break;
150 148
151 case PROJECTM_K_f: 149 case PROJECTM_K_f:
152 int w, h; 150 int w, h;
153 if (fullscreen == 0) 151 if (fullscreen == 0)
270 268
271 void triggerPlaybackBegin(PlaylistEntry *entry) 269 void triggerPlaybackBegin(PlaylistEntry *entry)
272 { 270 {
273 std::string title(entry->title); 271 std::string title(entry->title);
274 this->pm->projectM_setTitle(title); 272 this->pm->projectM_setTitle(title);
273 }
274
275 void takeScreenshot(void)
276 {
277 static int frame = 1;
278
279 std::string dumpPath(g_get_home_dir());
280 dumpPath.append(".projectM/");
281
282 gchar *frame_ = g_strdup_printf("%.8d.bmp", frame);
283
284 dumpPath.append(frame_);
285
286 SDL_Surface *bitmap;
287
288 GLint viewport[4];
289 long bytewidth;
290 GLint width, height;
291 long bytes;
292
293 glReadBuffer(GL_FRONT);
294 glGetIntegerv(GL_VIEWPORT, viewport);
295
296 width = viewport[2];
297 height = viewport[3];
298
299 bytewidth = width * 4;
300 bytewidth = (bytewidth + 3) & ~3;
301 bytes = bytewidth * height;
302
303 bitmap = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, 0, 0, 0, 0);
304 glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, bitmap->pixels);
305
306 SDL_SaveBMP(bitmap, dumpPath.c_str());
307
308 SDL_FreeSurface(bitmap);
309
310 frame++;
275 } 311 }
276 }; 312 };
277 313
278 /* glue to implementation section */ 314 /* glue to implementation section */
279 projectMPlugin *thePlugin = 0; 315 projectMPlugin *thePlugin = 0;
411 447
412 } 448 }
413 449
414 abort(); 450 abort();
415 } 451 }
416
417 int frame = 1;
418
419
420 void saveSnapshotToFile()
421 {
422 char dumpPath[512];
423 char Home[512];
424 //char *home;
425
426 SDL_Surface *bitmap;
427
428 GLint viewport[4];
429 long bytewidth;
430 GLint width, height;
431 long bytes;
432
433 glReadBuffer(GL_FRONT);
434 glGetIntegerv(GL_VIEWPORT, viewport);
435
436 width = viewport[2];
437 height = viewport[3];
438
439 bytewidth = width * 4;
440 bytewidth = (bytewidth + 3) & ~3;
441 bytes = bytewidth * height;
442
443 /*
444 glFinish();
445 glPixelStorei(GL_PACK_ALIGNMENT, 4);
446 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
447 glPixelStorei(GL_PACK_SKIP_ROWS, 0);
448 glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
449 */
450
451
452 bitmap = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, 0, 0, 0, 0);
453 glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, bitmap->pixels);
454
455 sprintf(dumpPath, "/.projectM/%.8d.bmp", frame++);
456 // home=getenv("HOME");
457 strcpy(Home, getenv("HOME"));
458 strcpy(Home + strlen(Home), dumpPath);
459 Home[strlen(Home)] = '\0';
460 SDL_SaveBMP(bitmap, Home);
461
462 SDL_FreeSurface(bitmap);
463
464
465 }