diff --git a/source/menu.cpp b/source/menu.cpp index 2b5a209..d33bd5e 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -951,6 +951,16 @@ static void WindowCredits(void * ptr) * Displays a list of games on the specified load device, and allows the user * to browse and select from this list. ***************************************************************************/ +static char* getImageFolder() +{ + switch(GCSettings.PreviewImage) + { + case 1 : return GCSettings.CoverFolder; break; + case 2 : return GCSettings.ArtworkFolder; break; + default: return GCSettings.ScreenshotsFolder; break; + } +} + static int MenuGameSelection() { int menu = MENU_NONE; @@ -1120,27 +1130,18 @@ static int MenuGameSelection() { previousBrowserIndex = browser.selIndex; previousPreviewImg = GCSettings.PreviewImage; - snprintf(imagePath, MAXJOLIET, "%s%s/%s.png", pathPrefix[GCSettings.LoadMethod], ImageFolder(), browserList[browser.selIndex].displayname); + snprintf(imagePath, MAXJOLIET, "%s%s/%s.png", pathPrefix[GCSettings.LoadMethod], getImageFolder(), browserList[browser.selIndex].displayname); - AllocSaveBuffer(); int width, height; - if(LoadFile(imagePath, SILENT)) + if(DecodePNGFromFile(imagePath, &width, &height, imgBuffer, 512, 512)) { - if(DecodePNG(savebuffer, &width, &height, imgBuffer, 512, 512)) - { - preview.SetImage(imgBuffer, width, height); - preview.SetScale( MIN(225.0f / width, 235.0f / height) ); - } - else - { - preview.SetImage(NULL, 0, 0); - } + preview.SetImage(imgBuffer, width, height); + preview.SetScale( MIN(225.0f / width, 235.0f / height) ); } - else + else { preview.SetImage(NULL, 0, 0); } - FreeSaveBuffer(); } if(settingsBtn.GetState() == STATE_CLICKED) diff --git a/source/snes9xgx.cpp b/source/snes9xgx.cpp index 4cb6e94..5f672dc 100644 --- a/source/snes9xgx.cpp +++ b/source/snes9xgx.cpp @@ -565,13 +565,3 @@ int main(int argc, char *argv[]) } // emulation loop } // main loop } - -char* ImageFolder() -{ - switch(GCSettings.PreviewImage) - { - case 1 : return GCSettings.CoverFolder; break; - case 2 : return GCSettings.ArtworkFolder; break; - default: return GCSettings.ScreenshotsFolder; break; - } -} diff --git a/source/snes9xgx.h b/source/snes9xgx.h index e9e4479..805c81b 100644 --- a/source/snes9xgx.h +++ b/source/snes9xgx.h @@ -124,8 +124,6 @@ struct SGCSettings{ int Interpolation; }; -char* ImageFolder(); - void ExitApp(); void ShutdownWii(); bool SupportedIOS(u32 ios); diff --git a/source/utils/pngu.c b/source/utils/pngu.c index 2f19ee6..c9df0fc 100644 --- a/source/utils/pngu.c +++ b/source/utils/pngu.c @@ -110,10 +110,6 @@ static int pngu_info (IMGCTX ctx) else if (ctx->source == PNGU_SOURCE_DEVICE) { - // Open file - if (!(ctx->fd = fopen (ctx->filename, "rb"))) - return PNGU_CANT_OPEN_FILE; - // Load first 8 bytes into magic buffer if (fread (magic, 1, 8, ctx->fd) != 8) { @@ -580,6 +576,29 @@ u8 * DecodePNG(const u8 *src, int * width, int * height, u8 *dstPtr, int maxwidt return dst; } +u8 * DecodePNGFromFile(const char *filepath, int * width, int * height, u8 *dstPtr, int maxwidth, int maxheight) +{ + FILE *file = fopen (filepath, "rb"); + + if (!file) + return NULL; + + IMGCTX ctx = PNGU_SelectImageFromDevice(filepath); + + if(!ctx) + return NULL; + + ctx->fd = file; + PNGUPROP imgProp; + u8 *dst = NULL; + + if(PNGU_GetImageProperties(ctx, &imgProp) == PNGU_OK && imgProp.imgWidth <= maxwidth && imgProp.imgHeight < maxheight) + dst = PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, width, height, dstPtr, maxwidth, maxheight); + + PNGU_ReleaseImageContext (ctx); + return dst; +} + int PNGU_EncodeFromRGB (IMGCTX ctx, u32 width, u32 height, void *buffer, u32 stride) { png_uint_32 rowbytes; diff --git a/source/utils/pngu.h b/source/utils/pngu.h index fa89650..bcf64f2 100644 --- a/source/utils/pngu.h +++ b/source/utils/pngu.h @@ -64,6 +64,7 @@ int PNGU_GetImageProperties (IMGCTX ctx, PNGUPROP *fileproperties); ****************************************************************************/ u8 * DecodePNG(const u8 *src, int *width, int *height, u8 *dst, int maxwidth, int maxheight); +u8 * DecodePNGFromFile(const char *filepath, int *width, int *height, u8 *dst, int maxwidth, int maxheight); int PNGU_EncodeFromRGB (IMGCTX ctx, u32 width, u32 height, void *buffer, u32 stride); int PNGU_EncodeFromGXTexture (IMGCTX ctx, u32 width, u32 height, void *buffer, u32 stride); int PNGU_EncodeFromEFB (IMGCTX ctx, u32 width, u32 height);