Annotation of hatari/src/screenSnapShot.c, revision 1.1.1.6

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.6 ! root        9: char ScreenSnapShot_rcsid[] = "Hatari $Id: screenSnapShot.c,v 1.9 2005/06/05 14:19:39 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       root       17: #include "screen.h"
                     18: #include "screenSnapShot.h"
                     19: #include "video.h"
                     20: 
1.1.1.2   root       21: 
1.1.1.6 ! root       22: BOOL bRecordingAnimation = FALSE;           /* Recording animation? */
        !            23: static int nScreenShots = 0;                /* Number of screen shots saved */
        !            24: static BOOL bGrabWhenChange;
        !            25: static int GrabFrameCounter,GrabFrameLatch;
        !            26: 
1.1       root       27: 
1.1.1.2   root       28: /*-----------------------------------------------------------------------*/
1.1       root       29: /*
1.1.1.2   root       30:   Scan working directory to get the screenshot number
                     31: */
1.1.1.5   root       32: static void ScreenSnapShot_GetNum(void)
                     33: {
1.1.1.2   root       34:   char dummy[5];
                     35:   int i, num;
                     36:   DIR *workingdir = opendir(szWorkingDir);
                     37:   struct dirent *file;
                     38: 
                     39:   nScreenShots = 0;
1.1.1.4   root       40:   if(workingdir == NULL)  return;
1.1.1.2   root       41: 
                     42:   file = readdir(workingdir);
                     43:   while(file != NULL){
1.1.1.4   root       44:     if( strncmp("grab", file->d_name, 4) == 0 ) {
1.1.1.2   root       45:       /* copy next 4 numbers */
                     46:       for(i=0;i<4;i++)
                     47:         if(file->d_name[4+i] >= '0' && file->d_name[4+i] <= '9')
                     48:           dummy[i] = file->d_name[4+i]; 
                     49:         else break;
                     50: 
                     51:       dummy[i] = '\0'; /* null terminate */
1.1.1.4   root       52:       num = atoi(dummy);
                     53:       if(num > nScreenShots)  nScreenShots = num;
1.1.1.2   root       54:     }
                     55:     /* next file.. */
1.1.1.4   root       56:     file = readdir(workingdir);
1.1.1.2   root       57:   } 
                     58: }
                     59: 
                     60: /*-----------------------------------------------------------------------*/
1.1       root       61: /*
1.1.1.2   root       62:   Save screen shot out .BMP file with filename 'grab0000.bmp','grab0001.bmp'....
1.1       root       63: */
                     64: void ScreenSnapShot_SaveScreen(void)
                     65: {
1.1.1.6 ! root       66:   char *szFileName = malloc(FILENAME_MAX);
        !            67: 
        !            68:   if (!szFileName)  return;
1.1.1.5   root       69: 
1.1.1.2   root       70:   ScreenSnapShot_GetNum();
1.1.1.3   root       71:   /* Create our filename */
                     72:   nScreenShots++;
                     73:   sprintf(szFileName,"%s/grab%4.4d.bmp",szWorkingDir,nScreenShots);
                     74:   if(SDL_SaveBMP(sdlscrn, szFileName))
                     75:     fprintf(stderr, "Screen dump failed!\n");
                     76:   else 
                     77:     fprintf(stderr, "Screen dump saved to: %s\n", szFileName);    
1.1.1.5   root       78: 
1.1.1.6 ! root       79:   free(szFileName);
1.1       root       80: }
                     81: 
1.1.1.2   root       82: /*-----------------------------------------------------------------------*/
1.1       root       83: /*
                     84:   Are we recording an animation?
                     85: */
                     86: BOOL ScreenSnapShot_AreWeRecording(void)
                     87: {
                     88:   return(bRecordingAnimation);
                     89: }
                     90: 
                     91: /*-----------------------------------------------------------------------*/
                     92: /*
                     93:   Start recording animation
                     94: */
                     95: void ScreenSnapShot_BeginRecording(BOOL bCaptureChange, int nFramesPerSecond)
                     96: {
                     97:   /* Set in globals */
                     98:   bGrabWhenChange = bCaptureChange;
                     99:   /* Set animation timer rate */
                    100:   GrabFrameCounter = 0;
                    101:   GrabFrameLatch = (int)(50.0f/(float)nFramesPerSecond);
                    102:   /* Start animation */
                    103:   bRecordingAnimation = TRUE;
1.1.1.6 ! root      104: 
1.1       root      105:   /* And inform user */
1.1.1.6 ! root      106:   Log_AlertDlg(LOG_INFO, "Screenshot recording started.");
1.1       root      107: }
                    108: 
                    109: /*-----------------------------------------------------------------------*/
                    110: /*
                    111:   Stop recording animation
                    112: */
                    113: void ScreenSnapShot_EndRecording()
                    114: {
                    115:   /* Were we recording? */
                    116:   if (bRecordingAnimation) {
                    117:     /* Stop animation */
                    118:     bRecordingAnimation = FALSE;
1.1.1.6 ! root      119: 
1.1       root      120:     /* And inform user */
1.1.1.6 ! root      121:     Log_AlertDlg(LOG_INFO, "Screenshot recording stopped.");
1.1       root      122:   }
                    123: }
                    124: 
1.1.1.2   root      125: /*-----------------------------------------------------------------------*/
1.1       root      126: /*
                    127:   Recording animation frame
                    128: */
                    129: void ScreenSnapShot_RecordFrame(BOOL bFrameChanged)
                    130: {
1.1.1.3   root      131:   /* As we recording? */
                    132:   if (bRecordingAnimation) {
1.1.1.2   root      133:     /* Yes, but on a change basis or a timer? */
1.1       root      134:     if (bGrabWhenChange) {
1.1.1.2   root      135:       /* On change, so did change this frame? */
1.1       root      136:       if (bFrameChanged)
                    137:         ScreenSnapShot_SaveScreen();
                    138:     }
                    139:     else {
1.1.1.2   root      140:       /* On timer, check for latch and save */
1.1       root      141:       GrabFrameCounter++;
                    142:       if (GrabFrameCounter>=GrabFrameLatch) {
                    143:         ScreenSnapShot_SaveScreen();
                    144:         GrabFrameCounter = 0;
                    145:       }
                    146:     }
                    147:   }
                    148: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.