From 17d8eb19c53f6cfb4176e2af28d6fb4ce5366b4b Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Thu, 1 Jun 2017 11:54:20 +0200 Subject: [PATCH 1/3] Fix jpeg's with width not matching psp buffer size. --- Core/HLE/sceJpeg.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Core/HLE/sceJpeg.cpp b/Core/HLE/sceJpeg.cpp index 676f46906a..95d2a6da37 100644 --- a/Core/HLE/sceJpeg.cpp +++ b/Core/HLE/sceJpeg.cpp @@ -139,12 +139,19 @@ static int __DecodeJpeg(u32 jpegAddr, int jpegSize, u32 imageAddr) { if (actual_components == 3) { u24_be *imageBuffer = (u24_be*)jpegBuf; u32 *abgr = (u32*)Memory::GetPointer(imageAddr); + int pspWidth; + for (int w = 2; w < 2048; w *= 2) { + if (w >= width) { + pspWidth = w; + break; + } + } for (int y = 0; y < height; ++y) { for (int x = 0; x < width; x++) { abgr[x] = convertARGBtoABGR(imageBuffer[x]); } imageBuffer += width; - abgr += width; + abgr += pspWidth; // Smallest value power of 2 fitting width. } } @@ -230,7 +237,7 @@ static int __JpegGetOutputInfo(u32 jpegAddr, int jpegSize, u32 colourInfoAddr) { #ifdef JPEG_DEBUG char jpeg_fname[256]; u8 *jpegDumpBuf = Memory::GetPointer(jpegAddr); - u32 jpeg_xxhash = XXH32((const char *)jpegBuf, jpegSize, 0xC0108888); + u32 jpeg_xxhash = XXH32((const char *)jpegDumpBuf, jpegSize, 0xC0108888); sprintf(jpeg_fname, "Jpeg\\%X.jpg", jpeg_xxhash); FILE *wfp = fopen(jpeg_fname, "wb"); if (!wfp) { From 7cee37c4e847f3805162f551c2b126581a182bb8 Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Thu, 1 Jun 2017 13:44:09 +0200 Subject: [PATCH 2/3] Needs to be square! O.o --- Core/HLE/sceJpeg.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/HLE/sceJpeg.cpp b/Core/HLE/sceJpeg.cpp index 95d2a6da37..59be70d604 100644 --- a/Core/HLE/sceJpeg.cpp +++ b/Core/HLE/sceJpeg.cpp @@ -141,7 +141,7 @@ static int __DecodeJpeg(u32 jpegAddr, int jpegSize, u32 imageAddr) { u32 *abgr = (u32*)Memory::GetPointer(imageAddr); int pspWidth; for (int w = 2; w < 2048; w *= 2) { - if (w >= width) { + if (w >= width && w >= height) { pspWidth = w; break; } @@ -151,7 +151,7 @@ static int __DecodeJpeg(u32 jpegAddr, int jpegSize, u32 imageAddr) { abgr[x] = convertARGBtoABGR(imageBuffer[x]); } imageBuffer += width; - abgr += pspWidth; // Smallest value power of 2 fitting width. + abgr += pspWidth; // Smallest value power of 2 fitting width and height(needs to be square!) } } From f10c9dfd8c8d42df5cb364ed1a901d3f29f9c2cb Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Thu, 1 Jun 2017 16:52:36 +0200 Subject: [PATCH 3/3] Initialize pspWidth and increase the max size. --- Core/HLE/sceJpeg.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/HLE/sceJpeg.cpp b/Core/HLE/sceJpeg.cpp index 59be70d604..790bcb0bb6 100644 --- a/Core/HLE/sceJpeg.cpp +++ b/Core/HLE/sceJpeg.cpp @@ -139,8 +139,8 @@ static int __DecodeJpeg(u32 jpegAddr, int jpegSize, u32 imageAddr) { if (actual_components == 3) { u24_be *imageBuffer = (u24_be*)jpegBuf; u32 *abgr = (u32*)Memory::GetPointer(imageAddr); - int pspWidth; - for (int w = 2; w < 2048; w *= 2) { + int pspWidth = 0; + for (int w = 2; w <= 4096; w *= 2) { if (w >= width && w >= height) { pspWidth = w; break;