Skip to content

Commit

Permalink
Use libjpg addons for loading png files
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtrujy committed Aug 1, 2021
1 parent c2c0f53 commit d7201e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -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
Expand Down
39 changes: 8 additions & 31 deletions src/textures.c
Expand Up @@ -2,7 +2,7 @@
#include "include/textures.h"
#include "include/util.h"
#include "include/ioman.h"
#include <libjpg.h>
#include <libjpg_ps2_addons.h>
#include <png.h>

extern void *load0_png;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit d7201e5

Please sign in to comment.