comparison render_sdl.c @ 2295:eb45ad9d8a3f

WIP "video" recording in APNG format
author Michael Pavone <pavone@retrodev.com>
date Fri, 10 Feb 2023 23:17:43 -0800
parents b2f788f08a31
children c79896ff1a2d
comparison
equal deleted inserted replaced
2294:7e995fb948c3 2295:eb45ad9d8a3f
1359 free(screenshot_path); 1359 free(screenshot_path);
1360 } 1360 }
1361 screenshot_path = path; 1361 screenshot_path = path;
1362 } 1362 }
1363 1363
1364 #ifndef DISABLE_ZLIB
1365 static apng_state *apng;
1366 static FILE *apng_file;
1367 #endif
1368 uint8_t render_saving_video(void)
1369 {
1370 #ifdef DISABLE_ZLIB
1371 return apng_file != NULL;
1372 #else
1373 return 0;
1374 #endif
1375 }
1376
1377 void render_end_video(void)
1378 {
1379 #ifndef DISABLE_ZLIB
1380 if (apng) {
1381 puts("Ending recording");
1382 end_apng(apng_file, apng);
1383 apng = NULL;
1384 apng_file = NULL;
1385 }
1386 #endif
1387 }
1388 void render_save_video(char *path)
1389 {
1390 render_end_video();
1391 #ifndef DISABLE_ZLIB
1392 apng_file = fopen(path, "wb");
1393 if (apng_file) {
1394 printf("Saving video to %s\n", path);
1395 } else {
1396 warning("Failed to open %s for writing\n", path);
1397 }
1398 #endif
1399 }
1400
1364 uint8_t render_create_window(char *caption, uint32_t width, uint32_t height, window_close_handler close_handler) 1401 uint8_t render_create_window(char *caption, uint32_t width, uint32_t height, window_close_handler close_handler)
1365 { 1402 {
1366 uint8_t win_idx = 0xFF; 1403 uint8_t win_idx = 0xFF;
1367 for (int i = 0; i < num_textures - FRAMEBUFFER_USER_START; i++) 1404 for (int i = 0; i < num_textures - FRAMEBUFFER_USER_START; i++)
1368 { 1405 {
1544 save_ppm(screenshot_file, buffer, shot_width, shot_height, LINEBUF_SIZE*sizeof(uint32_t)); 1581 save_ppm(screenshot_file, buffer, shot_width, shot_height, LINEBUF_SIZE*sizeof(uint32_t));
1545 #ifndef DISABLE_ZLIB 1582 #ifndef DISABLE_ZLIB
1546 } 1583 }
1547 #endif 1584 #endif
1548 } 1585 }
1586 #ifndef DISABLE_ZLIB
1587 if (apng_file) {
1588 if (!apng) {
1589 //TODO: more precise frame rate
1590 apng = start_apng(apng_file, width, height, video_standard == VID_PAL ? 50.0 : 60.0);
1591 }
1592 save_png24_frame(
1593 apng_file,
1594 buffer + overscan_left[video_standard] + LINEBUF_SIZE * overscan_top[video_standard],
1595 apng, width, height, LINEBUF_SIZE*sizeof(uint32_t)
1596 );
1597 }
1598 #endif
1549 } else { 1599 } else {
1550 #endif 1600 #endif
1551 //TODO: Support SYNC_AUDIO_THREAD/SYNC_EXTERNAL for render API framebuffers 1601 //TODO: Support SYNC_AUDIO_THREAD/SYNC_EXTERNAL for render API framebuffers
1552 if (which <= FRAMEBUFFER_EVEN && last != which) { 1602 if (which <= FRAMEBUFFER_EVEN && last != which) {
1553 uint8_t *cur_dst = (uint8_t *)locked_pixels; 1603 uint8_t *cur_dst = (uint8_t *)locked_pixels;