From a11de0f607b3bb81a16c0e48ea2456ce57b0824f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandro=20S=C3=A1nchez=20Bach?= Date: Thu, 19 Sep 2013 23:40:43 +0200 Subject: [PATCH] Improved image decoding modules * Huge improvement in the speed of cell{Png|Gif|Jpg}DecDecodeData when reading input files. Note: Sorry if this commit is too "small", but I need to sync every change since I use two PCs. --- rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp | 9 ++------- rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp | 9 ++------- rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp | 9 ++------- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp index e35da3dd45..b8175f944c 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp @@ -193,14 +193,9 @@ int cellGifDecDecodeData(u32 mainHandle, u32 subHandle, u32 data_addr, u32 dataC //Decode GIF file. (TODO: Is there any faster alternative? Can we do it without external libraries?) int width, height, actual_components; - unsigned char *gif = new unsigned char [fileSize]; - for(u32 i = 0; i < fileSize; i++){ - gif[i] = Memory.Read8(buffer+i); - } + unsigned char *gif = (unsigned char*)Memory.VirtualToRealAddr(buffer); + unsigned char *image = stbi_load_from_memory(gif, fileSize, &width, &height, &actual_components, 4); Memory.Free(buffer); - - unsigned char *image = stbi_load_from_memory((const unsigned char*)gif, fileSize, &width, &height, &actual_components, 4); - delete[] gif; if (!image) return CELL_GIFDEC_ERROR_STREAM_FORMAT; u32 image_size = width * height * 4; diff --git a/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp index c9cbaba239..8f0f82c40e 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp @@ -213,14 +213,9 @@ int cellJpgDecDecodeData(u32 mainHandle, u32 subHandle, u32 data_addr, u32 dataC //Decode JPG file. (TODO: Is there any faster alternative? Can we do it without external libraries?) int width, height, actual_components; - unsigned char *jpg = new unsigned char [fileSize]; - for(u32 i = 0; i < fileSize; i++){ - jpg[i] = Memory.Read8(buffer+i); - } + unsigned char *jpg = (unsigned char*)Memory.VirtualToRealAddr(buffer); + unsigned char *image = stbi_load_from_memory(jpg, fileSize, &width, &height, &actual_components, 4); Memory.Free(buffer); - - unsigned char *image = stbi_load_from_memory((const unsigned char*)jpg, fileSize, &width, &height, &actual_components, 4); - delete[] jpg; if (!image) return CELL_JPGDEC_ERROR_STREAM_FORMAT; u32 image_size = width * height * 4; diff --git a/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp index 1a93351259..783ba3738e 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp @@ -198,14 +198,9 @@ int cellPngDecDecodeData(u32 mainHandle, u32 subHandle, u32 data_addr, u32 dataC //Decode PNG file. (TODO: Is there any faster alternative? Can we do it without external libraries?) int width, height, actual_components; - unsigned char *png = new unsigned char [fileSize]; - for(u32 i = 0; i < fileSize; i++){ - png[i] = Memory.Read8(buffer+i); - } + unsigned char *png = (unsigned char*)Memory.VirtualToRealAddr(buffer); + unsigned char *image = stbi_load_from_memory(png, fileSize, &width, &height, &actual_components, 4); Memory.Free(buffer); - - unsigned char *image = stbi_load_from_memory((const unsigned char*)png, fileSize, &width, &height, &actual_components, 4); - delete[] png; if (!image) return CELL_PNGDEC_ERROR_STREAM_FORMAT; u32 image_size = width * height * 4;