mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-10 23:02:03 +00:00
Remix screencapture_begin into OutputFileCounter.
git-svn-id: https://svn.eduke32.com/eduke32@6532 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
f9a90e6f33
commit
c5ebf96217
3 changed files with 34 additions and 32 deletions
|
@ -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(const char *filename, char inverseit) ATTRIBUTE((nonnull(1)));
|
||||||
int screencapture_tga(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
|
// PLAG: line utility functions
|
||||||
typedef struct s_equation {
|
typedef struct s_equation {
|
||||||
float a, b, c;
|
float a, b, c;
|
||||||
|
|
|
@ -4,46 +4,46 @@
|
||||||
|
|
||||||
#include "pngwrite.h"
|
#include "pngwrite.h"
|
||||||
|
|
||||||
uint16_t capturecount = 0;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// screencapture
|
// 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
|
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;
|
zeros[0] = ((count/1000)%10)+'0';
|
||||||
fn[i++] = ((capturecount/1000)%10)+48;
|
zeros[1] = ((count/100)%10)+'0';
|
||||||
fn[i++] = ((capturecount/100)%10)+48;
|
zeros[2] = ((count/10)%10)+'0';
|
||||||
fn[i++] = ((capturecount/10)%10)+48;
|
zeros[3] = (count%10)+'0';
|
||||||
fn[i++] = (capturecount%10)+48;
|
|
||||||
i++;
|
|
||||||
Bstrcpy(&fn[i], ext);
|
|
||||||
|
|
||||||
if ((*filptr = Bfopen(fn, "rb")) == NULL) break;
|
if ((file = fopen(fn, "rb")) == nullptr) break;
|
||||||
Bfclose(*filptr);
|
fclose(file);
|
||||||
capturecount++;
|
count++;
|
||||||
} while (1);
|
} while (1);
|
||||||
|
|
||||||
*filptr = Bfopen(fn, "wb");
|
return fopen(fn, "wb");
|
||||||
if (*filptr == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
static void screencapture_end(char *fn, BFILE** filptr)
|
||||||
{
|
{
|
||||||
Bfclose(*filptr);
|
Bfclose(*filptr);
|
||||||
OSD_Printf("Saved screenshot to %s\n", fn);
|
OSD_Printf("Saved screenshot to %s\n", fn);
|
||||||
Bfree(fn);
|
Bfree(fn);
|
||||||
capturecount++;
|
capturecounter.count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
# ifdef USE_OPENGL
|
# ifdef USE_OPENGL
|
||||||
|
@ -55,13 +55,12 @@ static void screencapture_end(char *fn, BFILE** filptr)
|
||||||
int screencapture(const char *filename, char inverseit)
|
int screencapture(const char *filename, char inverseit)
|
||||||
{
|
{
|
||||||
char *fn = Xstrdup(filename);
|
char *fn = Xstrdup(filename);
|
||||||
BFILE *fp;
|
FILE *fp = capturecounter.opennextfile_withext(fn, "png");
|
||||||
int const retval = screencapture_begin(fn, "png", &fp);
|
|
||||||
|
|
||||||
if (retval)
|
if (fp == nullptr)
|
||||||
{
|
{
|
||||||
Bfree(fn);
|
Bfree(fn);
|
||||||
return retval;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t * const imgBuf = (uint8_t *) Xmalloc(xdim * ydim * (HICOLOR ? 3 : 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 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 palette[4*256];
|
||||||
char *fn = Xstrdup(filename);
|
char *fn = Xstrdup(filename);
|
||||||
BFILE *fil;
|
|
||||||
|
|
||||||
i = screencapture_begin(fn, "tga", &fil);
|
FILE *fil = capturecounter.opennextfile_withext(fn, "tga");
|
||||||
if (i)
|
if (fil == nullptr)
|
||||||
{
|
{
|
||||||
Bfree(fn);
|
Bfree(fn);
|
||||||
return i;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_OPENGL
|
#ifdef USE_OPENGL
|
||||||
|
|
|
@ -10931,10 +10931,8 @@ void ExtCheckKeys(void)
|
||||||
extern int32_t engine_screenshot;
|
extern int32_t engine_screenshot;
|
||||||
engine_screenshot = 1;
|
engine_screenshot = 1;
|
||||||
#else
|
#else
|
||||||
extern uint16_t capturecount;
|
|
||||||
|
|
||||||
screencapture("captxxxx.tga", eitherSHIFT);
|
screencapture("captxxxx.tga", eitherSHIFT);
|
||||||
silentmessage("Saved screenshot %04d", capturecount-1);
|
silentmessage("Saved screenshot");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue