Move screenshot function to gba-thread.h

This commit is contained in:
Jeffrey Pfau 2014-07-27 18:21:58 -07:00
parent b4d90e7e84
commit f39d7e3640
3 changed files with 16 additions and 16 deletions

View File

@ -7,6 +7,7 @@
#include "debugger/debugger.h" #include "debugger/debugger.h"
#include "util/patch.h" #include "util/patch.h"
#include "util/png-io.h"
#include "util/vfs.h" #include "util/vfs.h"
#include <signal.h> #include <signal.h>
@ -518,6 +519,18 @@ struct GBAThread* GBAThreadGetContext(void) {
} }
#endif #endif
void GBAThreadTakeScreenshot(struct GBAThread* threadContext) {
unsigned stride;
void* pixels = 0;
struct VFile* vf = threadContext->stateDir->openFile(threadContext->stateDir, "screenshot.png", O_CREAT | O_WRONLY);
threadContext->gba->video.renderer->getPixels(threadContext->gba->video.renderer, &stride, &pixels);
png_structp png = PNGWriteOpen(vf);
png_infop info = PNGWriteHeader(png, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS);
PNGWritePixels(png, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, stride, pixels);
PNGWriteClose(png, info);
vf->close(vf);
}
void GBASyncPostFrame(struct GBASync* sync) { void GBASyncPostFrame(struct GBASync* sync) {
if (!sync) { if (!sync) {
return; return;

View File

@ -106,6 +106,8 @@ void GBAThreadTogglePause(struct GBAThread* threadContext);
void GBAThreadPauseFromThread(struct GBAThread* threadContext); void GBAThreadPauseFromThread(struct GBAThread* threadContext);
struct GBAThread* GBAThreadGetContext(void); struct GBAThread* GBAThreadGetContext(void);
void GBAThreadTakeScreenshot(struct GBAThread* threadContext);
void GBASyncPostFrame(struct GBASync* sync); void GBASyncPostFrame(struct GBASync* sync);
bool GBASyncWaitFrameStart(struct GBASync* sync, int frameskip); bool GBASyncWaitFrameStart(struct GBASync* sync, int frameskip);
void GBASyncWaitFrameEnd(struct GBASync* sync); void GBASyncWaitFrameEnd(struct GBASync* sync);

View File

@ -6,7 +6,6 @@
#include "gba-serialize.h" #include "gba-serialize.h"
#include "gba-video.h" #include "gba-video.h"
#include "renderers/video-software.h" #include "renderers/video-software.h"
#include "util/png-io.h"
#include "util/vfs.h" #include "util/vfs.h"
#if SDL_VERSION_ATLEAST(2, 0, 0) && defined(__APPLE__) #if SDL_VERSION_ATLEAST(2, 0, 0) && defined(__APPLE__)
@ -18,8 +17,6 @@
#define SDL_BINDING_KEY 0x53444C4B #define SDL_BINDING_KEY 0x53444C4B
#define SDL_BINDING_BUTTON 0x53444C42 #define SDL_BINDING_BUTTON 0x53444C42
static void _takeScreenshot(struct GBAThread*);
bool GBASDLInitEvents(struct GBASDLEvents* context) { bool GBASDLInitEvents(struct GBASDLEvents* context) {
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) { if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) {
return false; return false;
@ -82,7 +79,7 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, struct GBASDLEvents
case SDLK_F12: case SDLK_F12:
if (event->type == SDL_KEYDOWN) { if (event->type == SDL_KEYDOWN) {
GBAThreadInterrupt(context); GBAThreadInterrupt(context);
_takeScreenshot(context); GBAThreadTakeScreenshot(context);
GBAThreadContinue(context); GBAThreadContinue(context);
} }
return; return;
@ -261,15 +258,3 @@ void GBASDLHandleEvent(struct GBAThread* context, struct GBASDLEvents* sdlContex
_GBASDLHandleJoyHat(context, &event->jhat); _GBASDLHandleJoyHat(context, &event->jhat);
} }
} }
static void _takeScreenshot(struct GBAThread* context) {
unsigned stride;
void* pixels = 0;
struct VFile* vf = context->stateDir->openFile(context->stateDir, "screenshot.png", O_CREAT | O_WRONLY);
context->gba->video.renderer->getPixels(context->gba->video.renderer, &stride, &pixels);
png_structp png = PNGWriteOpen(vf);
png_infop info = PNGWriteHeader(png, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS);
PNGWritePixels(png, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, stride, pixels);
PNGWriteClose(png, info);
vf->close(vf);
}