Remix screencapture_begin into OutputFileCounter.

git-svn-id: https://svn.eduke32.com/eduke32@6532 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2017-12-01 06:19:19 +00:00
parent f9a90e6f33
commit c5ebf96217
3 changed files with 34 additions and 32 deletions

View file

@ -1227,6 +1227,12 @@ static FORCE_INLINE int32_t spriteheightofs(int16_t i, int32_t *height, int32_t
int screencapture(const char *filename, char inverseit) ATTRIBUTE((nonnull(1)));
int screencapture_tga(const char *filename, char inverseit) ATTRIBUTE((nonnull(1)));
struct OutputFileCounter {
uint16_t count = 0;
FILE * opennextfile(char *, char *);
FILE * opennextfile_withext(char *, const char *);
};
// PLAG: line utility functions
typedef struct s_equation {
float a, b, c;

View file

@ -4,46 +4,46 @@
#include "pngwrite.h"
uint16_t capturecount = 0;
//
// screencapture
//
static int screencapture_begin(char *fn, const char *ext, BFILE** filptr)
FILE *OutputFileCounter::opennextfile(char *fn, char *zeros)
{
bssize_t i;
FILE *file;
do // JBF 2004022: So we don't overwrite existing screenshots
{
if (capturecount > 9999) return -1;
if (count > 9999) return nullptr;
i = Bstrrchr(fn, '.')-fn-4;
fn[i++] = ((capturecount/1000)%10)+48;
fn[i++] = ((capturecount/100)%10)+48;
fn[i++] = ((capturecount/10)%10)+48;
fn[i++] = (capturecount%10)+48;
i++;
Bstrcpy(&fn[i], ext);
zeros[0] = ((count/1000)%10)+'0';
zeros[1] = ((count/100)%10)+'0';
zeros[2] = ((count/10)%10)+'0';
zeros[3] = (count%10)+'0';
if ((*filptr = Bfopen(fn, "rb")) == NULL) break;
Bfclose(*filptr);
capturecount++;
if ((file = fopen(fn, "rb")) == nullptr) break;
fclose(file);
count++;
} while (1);
*filptr = Bfopen(fn, "wb");
if (*filptr == NULL)
return -1;
return 0;
return fopen(fn, "wb");
}
FILE *OutputFileCounter::opennextfile_withext(char *fn, const char *ext)
{
char *dot = strrchr(fn, '.');
strcpy(dot+1, ext);
return opennextfile(fn, dot-4);
}
static OutputFileCounter capturecounter;
static void screencapture_end(char *fn, BFILE** filptr)
{
Bfclose(*filptr);
OSD_Printf("Saved screenshot to %s\n", fn);
Bfree(fn);
capturecount++;
capturecounter.count++;
}
# ifdef USE_OPENGL
@ -55,13 +55,12 @@ static void screencapture_end(char *fn, BFILE** filptr)
int screencapture(const char *filename, char inverseit)
{
char *fn = Xstrdup(filename);
BFILE *fp;
int const retval = screencapture_begin(fn, "png", &fp);
FILE *fp = capturecounter.opennextfile_withext(fn, "png");
if (retval)
if (fp == nullptr)
{
Bfree(fn);
return retval;
return -1;
}
uint8_t * const imgBuf = (uint8_t *) Xmalloc(xdim * ydim * (HICOLOR ? 3 : 1));
@ -136,13 +135,12 @@ int screencapture_tga(const char *filename, char inverseit)
char head[18] = { 0,1,1,0,0,0,1,24,0,0,0,0,0/*wlo*/,0/*whi*/,0/*hlo*/,0/*hhi*/,8,0 };
//char palette[4*256];
char *fn = Xstrdup(filename);
BFILE *fil;
i = screencapture_begin(fn, "tga", &fil);
if (i)
FILE *fil = capturecounter.opennextfile_withext(fn, "tga");
if (fil == nullptr)
{
Bfree(fn);
return i;
return -1;
}
#ifdef USE_OPENGL

View file

@ -10931,10 +10931,8 @@ void ExtCheckKeys(void)
extern int32_t engine_screenshot;
engine_screenshot = 1;
#else
extern uint16_t capturecount;
screencapture("captxxxx.tga", eitherSHIFT);
silentmessage("Saved screenshot %04d", capturecount-1);
silentmessage("Saved screenshot");
#endif
}
}