From d7201e510204f846af71639a370ec52f770cff1e Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Sun, 1 Aug 2021 12:49:55 +0200 Subject: [PATCH] Use libjpg addons for loading png files --- Makefile | 2 +- src/textures.c | 39 ++++++++------------------------------- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 6c6215d94..a11cb4567 100644 --- a/Makefile +++ b/Makefile @@ -110,7 +110,7 @@ EE_ASM_DIR = asm/ MAPFILE = opl.map EE_LDFLAGS += -Wl,-Map,$(MAPFILE) -EE_LIBS = -L$(PS2SDK)/ports/lib -L$(GSKIT)/lib -L./lib -lgskit -ldmakit -lgskit_toolkit -lpoweroff -lfileXio -lpatches -ljpeg -lpng -lz -ldebug -lm -lmc -lfreetype -lvux -lcdvd -lnetman -lps2ips -laudsrv -lpadx +EE_LIBS = -L$(PS2SDK)/ports/lib -L$(GSKIT)/lib -L./lib -lgskit -ldmakit -lgskit_toolkit -lpoweroff -lfileXio -lpatches -ljpeg_ps2_addons -ljpeg -lpng -lz -ldebug -lm -lmc -lfreetype -lvux -lcdvd -lnetman -lps2ips -laudsrv -lpadx EE_INCS += -I$(PS2SDK)/ports/include -I$(PS2SDK)/ports/include/freetype2 -I$(GSKIT)/include -I$(GSKIT)/ee/dma/include -I$(GSKIT)/ee/gs/include -I$(GSKIT)/ee/toolkit/include -Imodules/iopcore/common -Imodules/network/common -Imodules/hdd/common -Iinclude BIN2C = $(PS2SDK)/bin/bin2c diff --git a/src/textures.c b/src/textures.c index 4f94b61cb..516a7c9a1 100644 --- a/src/textures.c +++ b/src/textures.c @@ -2,7 +2,7 @@ #include "include/textures.h" #include "include/util.h" #include "include/ioman.h" -#include +#include #include extern void *load0_png; @@ -545,38 +545,15 @@ int texJpgLoad(GSTEXTURE *texture, const char *path, int texId, short psm) snprintf(filePath, sizeof(filePath), "%s%s.jpg", path, internalDefault[texId].name); else snprintf(filePath, sizeof(filePath), "%s.jpg", path); - FILE *file = fopen(filePath, "rb"); - if (file) { - jpg = jpgOpenFILE(file, JPG_NORMAL); - if (jpg != NULL) { - if (texSizeValidate(jpg->width, jpg->height, psm) < 0) { - jpgClose(jpg); - fclose(file); - return ERR_BAD_DIMENSION; - } - - size_t size = gsKit_texture_size_ee(jpg->width, jpg->height, psm); - texture->Mem = memalign(128, size); - - // failed allocation - if (!texture->Mem) { - LOG("TEXTURES JpgLoad: Failed to allocate %d bytes\n", size); - } else { - // okay - texUpdate(texture, jpg->width, jpg->height); - - jpgReadImage(jpg, (void *)texture->Mem); - result = 0; - } - } - } - if (jpg) - jpgClose(jpg); - - if (file) - fclose(file); + jpg = jpgFromFilename(filePath, JPG_NORMAL); + if (jpg) { + texture->Mem = jpg->buffer; + texUpdate(texture, jpg->width, jpg->height); + free(jpg); + result = 0; + } return result; }