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

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.5 ! root        9: char ScreenSnapShot_rcsid[] = "Hatari $Id: screenSnapShot.c,v 1.7 2004/04/19 08:53:47 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.5 ! root       16: #include "memAlloc.h"
1.1       root       17: #include "misc.h"
                     18: #include "screen.h"
                     19: #include "screenSnapShot.h"
                     20: #include "video.h"
                     21: #include "vdi.h"
                     22: 
1.1.1.2   root       23: 
                     24: int nScreenShots=0;                  /* Number of screen shots saved */
                     25: BOOL bRecordingAnimation=FALSE;      /* Recording animation? */
1.1       root       26: BOOL bGrabWhenChange;
                     27: int GrabFrameCounter,GrabFrameLatch;
                     28: 
1.1.1.2   root       29: /*-----------------------------------------------------------------------*/
1.1       root       30: /*
1.1.1.2   root       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.2   root       35:   char dummy[5];
                     36:   int i, num;
                     37:   DIR *workingdir = opendir(szWorkingDir);
                     38:   struct dirent *file;
                     39: 
                     40:   nScreenShots = 0;
1.1.1.4   root       41:   if(workingdir == NULL)  return;
1.1.1.2   root       42: 
                     43:   file = readdir(workingdir);
                     44:   while(file != NULL){
1.1.1.4   root       45:     if( strncmp("grab", file->d_name, 4) == 0 ) {
1.1.1.2   root       46:       /* copy next 4 numbers */
                     47:       for(i=0;i<4;i++)
                     48:         if(file->d_name[4+i] >= '0' && file->d_name[4+i] <= '9')
                     49:           dummy[i] = file->d_name[4+i]; 
                     50:         else break;
                     51: 
                     52:       dummy[i] = '\0'; /* null terminate */
1.1.1.4   root       53:       num = atoi(dummy);
                     54:       if(num > nScreenShots)  nScreenShots = num;
1.1.1.2   root       55:     }
                     56:     /* next file.. */
1.1.1.4   root       57:     file = readdir(workingdir);
1.1.1.2   root       58:   } 
                     59: }
                     60: 
                     61: /*-----------------------------------------------------------------------*/
1.1       root       62: /*
1.1.1.2   root       63:   Save screen shot out .BMP file with filename 'grab0000.bmp','grab0001.bmp'....
1.1       root       64: */
                     65: void ScreenSnapShot_SaveScreen(void)
                     66: {
1.1.1.5 ! root       67:   char *szFileName = Memory_Alloc(FILENAME_MAX);
        !            68: 
1.1.1.2   root       69:   ScreenSnapShot_GetNum();
1.1.1.3   root       70:   /* Create our filename */
                     71:   nScreenShots++;
                     72:   sprintf(szFileName,"%s/grab%4.4d.bmp",szWorkingDir,nScreenShots);
                     73:   if(SDL_SaveBMP(sdlscrn, szFileName))
                     74:     fprintf(stderr, "Screen dump failed!\n");
                     75:   else 
                     76:     fprintf(stderr, "Screen dump saved to: %s\n", szFileName);    
1.1.1.5 ! root       77: 
        !            78:   Memory_Free(szFileName);
1.1       root       79: }
                     80: 
1.1.1.2   root       81: /*-----------------------------------------------------------------------*/
1.1       root       82: /*
                     83:   Are we recording an animation?
                     84: */
                     85: BOOL ScreenSnapShot_AreWeRecording(void)
                     86: {
                     87:   return(bRecordingAnimation);
                     88: }
                     89: 
                     90: /*-----------------------------------------------------------------------*/
                     91: /*
                     92:   Start recording animation
                     93: */
                     94: void ScreenSnapShot_BeginRecording(BOOL bCaptureChange, int nFramesPerSecond)
                     95: {
                     96:   /* Set in globals */
                     97:   bGrabWhenChange = bCaptureChange;
                     98:   /* Set animation timer rate */
                     99:   GrabFrameCounter = 0;
                    100:   GrabFrameLatch = (int)(50.0f/(float)nFramesPerSecond);
                    101:   /* Start animation */
                    102:   bRecordingAnimation = TRUE;
                    103:   /* Set status bar */
1.1.1.4   root      104:   /*StatusBar_SetIcon(STATUS_ICON_SCREEN,ICONSTATE_ON);*/ /* Sorry - Hatari does not has a statusbar yet */
1.1       root      105:   /* And inform user */
                    106:   Main_Message("Screen-Shot recording started.",PROG_NAME /*,MB_OK|MB_ICONINFORMATION*/);
                    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;
                    119:     /* Turn off icon */
1.1.1.4   root      120:     /*StatusBar_SetIcon(STATUS_ICON_SCREEN,ICONSTATE_OFF);*/ /* Sorry - no statusbar support yet */
1.1       root      121:     /* And inform user */
                    122:     Main_Message("Screen-Shot recording stopped.",PROG_NAME /*,MB_OK|MB_ICONINFORMATION*/);
                    123:   }
                    124: }
                    125: 
1.1.1.2   root      126: /*-----------------------------------------------------------------------*/
1.1       root      127: /*
                    128:   Recording animation frame
                    129: */
                    130: void ScreenSnapShot_RecordFrame(BOOL bFrameChanged)
                    131: {
1.1.1.3   root      132:   /* As we recording? */
                    133:   if (bRecordingAnimation) {
1.1.1.2   root      134:     /* Yes, but on a change basis or a timer? */
1.1       root      135:     if (bGrabWhenChange) {
1.1.1.2   root      136:       /* On change, so did change this frame? */
1.1       root      137:       if (bFrameChanged)
                    138:         ScreenSnapShot_SaveScreen();
                    139:     }
                    140:     else {
1.1.1.2   root      141:       /* On timer, check for latch and save */
1.1       root      142:       GrabFrameCounter++;
                    143:       if (GrabFrameCounter>=GrabFrameLatch) {
                    144:         ScreenSnapShot_SaveScreen();
                    145:         GrabFrameCounter = 0;
                    146:       }
                    147:     }
                    148:   }
                    149: }

unix.superglobalmegacorp.com

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