mirror of https://github.com/mgba-emu/mgba.git
mGUI: Improve savestate screenshot handling
This commit is contained in:
parent
7bd0e91735
commit
70e31df683
|
@ -123,34 +123,39 @@ static void _drawState(struct GUIBackground* background, void* id) {
|
||||||
struct mGUIBackground* gbaBackground = (struct mGUIBackground*) background;
|
struct mGUIBackground* gbaBackground = (struct mGUIBackground*) background;
|
||||||
unsigned stateId = ((uint32_t) id) >> 16;
|
unsigned stateId = ((uint32_t) id) >> 16;
|
||||||
if (gbaBackground->p->drawScreenshot) {
|
if (gbaBackground->p->drawScreenshot) {
|
||||||
unsigned w, h;
|
color_t* pixels = gbaBackground->image;
|
||||||
gbaBackground->p->core->desiredVideoDimensions(gbaBackground->p->core, &w, &h);
|
if (pixels && gbaBackground->screenshotId == (stateId | SCREENSHOT_VALID)) {
|
||||||
size_t size = w * h * BYTES_PER_PIXEL;
|
gbaBackground->p->drawScreenshot(gbaBackground->p, pixels, gbaBackground->w, gbaBackground->h, true);
|
||||||
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);
|
|
||||||
return;
|
return;
|
||||||
} else if (gbaBackground->screenshotId != (stateId | SCREENSHOT_INVALID)) {
|
} else if (gbaBackground->screenshotId != (stateId | SCREENSHOT_INVALID)) {
|
||||||
struct VFile* vf = mCoreGetState(gbaBackground->p->core, stateId, false);
|
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;
|
bool success = false;
|
||||||
if (vf && isPNG(vf) && pixels) {
|
unsigned w, h;
|
||||||
|
if (vf && isPNG(vf)) {
|
||||||
png_structp png = PNGReadOpen(vf, PNG_HEADER_BYTES);
|
png_structp png = PNGReadOpen(vf, PNG_HEADER_BYTES);
|
||||||
png_infop info = png_create_info_struct(png);
|
png_infop info = png_create_info_struct(png);
|
||||||
png_infop end = png_create_info_struct(png);
|
png_infop end = png_create_info_struct(png);
|
||||||
if (png && info && end) {
|
success = png && info && end;
|
||||||
success = PNGReadHeader(png, info);
|
success = success && PNGReadHeader(png, info);
|
||||||
success = success && PNGReadPixels(png, info, pixels, w, h, w);
|
w = png_get_image_width(png, info);
|
||||||
success = success && PNGReadFooter(png, end);
|
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);
|
PNGReadClose(png, info, end);
|
||||||
}
|
}
|
||||||
if (vf) {
|
if (vf) {
|
||||||
|
|
|
@ -33,6 +33,8 @@ struct mGUIBackground {
|
||||||
|
|
||||||
color_t* image;
|
color_t* image;
|
||||||
size_t imageSize;
|
size_t imageSize;
|
||||||
|
uint16_t w;
|
||||||
|
uint16_t h;
|
||||||
|
|
||||||
unsigned screenshotId;
|
unsigned screenshotId;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue