mGUI: Improve savestate screenshot handling

This commit is contained in:
Vicki Pfau 2023-01-28 20:29:06 -08:00
parent 7bd0e91735
commit 70e31df683
2 changed files with 27 additions and 20 deletions

View File

@ -123,34 +123,39 @@ static void _drawState(struct GUIBackground* background, void* id) {
struct mGUIBackground* gbaBackground = (struct mGUIBackground*) background;
unsigned stateId = ((uint32_t) id) >> 16;
if (gbaBackground->p->drawScreenshot) {
unsigned w, h;
gbaBackground->p->core->desiredVideoDimensions(gbaBackground->p->core, &w, &h);
size_t size = w * h * BYTES_PER_PIXEL;
if (size != gbaBackground->imageSize) {
mappedMemoryFree(gbaBackground->image, gbaBackground->imageSize);
gbaBackground->image = NULL;
}
if (gbaBackground->image && gbaBackground->screenshotId == (stateId | SCREENSHOT_VALID)) {
gbaBackground->p->drawScreenshot(gbaBackground->p, gbaBackground->image, w, h, true);
color_t* pixels = gbaBackground->image;
if (pixels && gbaBackground->screenshotId == (stateId | SCREENSHOT_VALID)) {
gbaBackground->p->drawScreenshot(gbaBackground->p, pixels, gbaBackground->w, gbaBackground->h, true);
return;
} else if (gbaBackground->screenshotId != (stateId | SCREENSHOT_INVALID)) {
struct VFile* vf = mCoreGetState(gbaBackground->p->core, stateId, false);
color_t* pixels = gbaBackground->image;
if (!pixels) {
pixels = anonymousMemoryMap(size);
gbaBackground->image = pixels;
gbaBackground->imageSize = size;
}
bool success = false;
if (vf && isPNG(vf) && pixels) {
unsigned w, h;
if (vf && isPNG(vf)) {
png_structp png = PNGReadOpen(vf, PNG_HEADER_BYTES);
png_infop info = png_create_info_struct(png);
png_infop end = png_create_info_struct(png);
if (png && info && end) {
success = PNGReadHeader(png, info);
success = success && PNGReadPixels(png, info, pixels, w, h, w);
success = success && PNGReadFooter(png, end);
success = png && info && end;
success = success && PNGReadHeader(png, info);
w = png_get_image_width(png, info);
h = png_get_image_height(png, info);
size_t size = w * h * BYTES_PER_PIXEL;
success = success && (w < 0x4000) && (h < 0x4000);
if (success) {
if (size != gbaBackground->imageSize) {
mappedMemoryFree(pixels, gbaBackground->imageSize);
pixels = anonymousMemoryMap(size);
gbaBackground->image = pixels;
gbaBackground->imageSize = size;
}
success = pixels;
}
success = success && PNGReadPixels(png, info, pixels, w, h, w);
if (success) {
gbaBackground->w = w;
gbaBackground->h = h;
}
success = success && PNGReadFooter(png, end);
PNGReadClose(png, info, end);
}
if (vf) {

View File

@ -33,6 +33,8 @@ struct mGUIBackground {
color_t* image;
size_t imageSize;
uint16_t w;
uint16_t h;
unsigned screenshotId;
};