|
|
1.1 root 1: /*
1.1.1.5 root 2: Hatari - screenSnapShot.c
1.1 root 3:
1.1.1.5 root 4: This file is distributed under the GNU Public License, version 2 or at
5: your option any later version. Read the file gpl.txt for details.
6:
7: Screen Snapshots.
1.1 root 8: */
1.1.1.8 ! root 9: const char ScreenSnapShot_rcsid[] = "Hatari $Id: screenSnapShot.c,v 1.14 2008/02/20 22:47:37 thothy Exp $";
1.1 root 10:
1.1.1.2 root 11: #include <SDL.h>
12: #include <dirent.h>
13: #include <string.h>
14:
1.1 root 15: #include "main.h"
1.1.1.6 root 16: #include "log.h"
1.1.1.8 ! root 17: #include "paths.h"
1.1 root 18: #include "screen.h"
19: #include "screenSnapShot.h"
20: #include "video.h"
21:
1.1.1.2 root 22:
1.1.1.6 root 23: BOOL bRecordingAnimation = FALSE; /* Recording animation? */
24: static int nScreenShots = 0; /* Number of screen shots saved */
25: static BOOL bGrabWhenChange;
1.1.1.8 ! root 26: static int GrabFrameCounter, GrabFrameLatch;
1.1.1.6 root 27:
1.1 root 28:
1.1.1.2 root 29: /*-----------------------------------------------------------------------*/
1.1.1.8 ! root 30: /**
! 31: * Scan working directory to get the screenshot number
! 32: */
1.1.1.5 root 33: static void ScreenSnapShot_GetNum(void)
34: {
1.1.1.8 ! root 35: char dummy[5];
! 36: int i, num;
! 37: DIR *workingdir = opendir(Paths_GetWorkingDir());
! 38: struct dirent *file;
! 39:
! 40: nScreenShots = 0;
! 41: if (workingdir == NULL) return;
! 42:
! 43: file = readdir(workingdir);
! 44: while (file != NULL)
! 45: {
! 46: if ( strncmp("grab", file->d_name, 4) == 0 )
! 47: {
! 48: /* copy next 4 numbers */
! 49: for (i = 0; i < 4; i++)
! 50: {
! 51: if (file->d_name[4+i] >= '0' && file->d_name[4+i] <= '9')
! 52: dummy[i] = file->d_name[4+i];
! 53: else
! 54: break;
! 55: }
! 56:
! 57: dummy[i] = '\0'; /* null terminate */
! 58: num = atoi(dummy);
! 59: if (num > nScreenShots) nScreenShots = num;
! 60: }
! 61: /* next file.. */
! 62: file = readdir(workingdir);
! 63: }
! 64:
! 65: closedir(workingdir);
1.1.1.2 root 66: }
67:
1.1.1.8 ! root 68:
1.1.1.2 root 69: /*-----------------------------------------------------------------------*/
1.1.1.8 ! root 70: /**
! 71: * Save screen shot out .BMP file with filename 'grab0000.bmp','grab0001.bmp'....
! 72: */
1.1 root 73: void ScreenSnapShot_SaveScreen(void)
74: {
1.1.1.8 ! root 75: char *szFileName = malloc(FILENAME_MAX);
1.1.1.6 root 76:
1.1.1.8 ! root 77: if (!szFileName) return;
1.1.1.5 root 78:
1.1.1.8 ! root 79: ScreenSnapShot_GetNum();
! 80: /* Create our filename */
! 81: nScreenShots++;
! 82: sprintf(szFileName,"%s/grab%4.4d.bmp", Paths_GetWorkingDir(), nScreenShots);
! 83: if (SDL_SaveBMP(sdlscrn, szFileName))
! 84: fprintf(stderr, "Screen dump failed!\n");
! 85: else
! 86: fprintf(stderr, "Screen dump saved to: %s\n", szFileName);
1.1.1.5 root 87:
1.1.1.8 ! root 88: free(szFileName);
1.1 root 89: }
90:
1.1.1.8 ! root 91:
1.1.1.2 root 92: /*-----------------------------------------------------------------------*/
1.1.1.8 ! root 93: /**
! 94: * Are we recording an animation?
! 95: */
1.1 root 96: BOOL ScreenSnapShot_AreWeRecording(void)
97: {
1.1.1.8 ! root 98: return bRecordingAnimation;
1.1 root 99: }
100:
1.1.1.8 ! root 101:
1.1 root 102: /*-----------------------------------------------------------------------*/
1.1.1.8 ! root 103: /**
! 104: * Start recording animation
! 105: */
1.1 root 106: void ScreenSnapShot_BeginRecording(BOOL bCaptureChange, int nFramesPerSecond)
107: {
1.1.1.8 ! root 108: /* Set in globals */
! 109: bGrabWhenChange = bCaptureChange;
! 110: /* Set animation timer rate */
! 111: GrabFrameCounter = 0;
! 112: GrabFrameLatch = (int)(50.0f/(float)nFramesPerSecond);
! 113: /* Start animation */
! 114: bRecordingAnimation = TRUE;
! 115:
! 116: /* And inform user */
! 117: Log_AlertDlg(LOG_INFO, "Screenshot recording started.");
1.1 root 118: }
119:
1.1.1.8 ! root 120:
1.1 root 121: /*-----------------------------------------------------------------------*/
1.1.1.8 ! root 122: /**
! 123: * Stop recording animation
! 124: */
1.1 root 125: void ScreenSnapShot_EndRecording()
126: {
1.1.1.8 ! root 127: /* Were we recording? */
! 128: if (bRecordingAnimation)
! 129: {
! 130: /* Stop animation */
! 131: bRecordingAnimation = FALSE;
1.1.1.6 root 132:
1.1.1.8 ! root 133: /* And inform user */
! 134: Log_AlertDlg(LOG_INFO, "Screenshot recording stopped.");
! 135: }
1.1 root 136: }
137:
1.1.1.8 ! root 138:
1.1.1.2 root 139: /*-----------------------------------------------------------------------*/
1.1.1.8 ! root 140: /**
! 141: * Recording animation frame
! 142: */
1.1 root 143: void ScreenSnapShot_RecordFrame(BOOL bFrameChanged)
144: {
1.1.1.8 ! root 145: /* As we recording? */
! 146: if (bRecordingAnimation)
! 147: {
! 148: /* Yes, but on a change basis or a timer? */
! 149: if (bGrabWhenChange)
! 150: {
! 151: /* On change, so did change this frame? */
! 152: if (bFrameChanged)
! 153: ScreenSnapShot_SaveScreen();
! 154: }
! 155: else
! 156: {
! 157: /* On timer, check for latch and save */
! 158: GrabFrameCounter++;
! 159: if (GrabFrameCounter>=GrabFrameLatch)
! 160: {
! 161: ScreenSnapShot_SaveScreen();
! 162: GrabFrameCounter = 0;
! 163: }
! 164: }
! 165: }
1.1 root 166: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.