diff --git a/source/gfx/JPEGTexture.cpp b/source/gfx/JPEGTexture.cpp index 5ef5afa..2770085 100644 --- a/source/gfx/JPEGTexture.cpp +++ b/source/gfx/JPEGTexture.cpp @@ -7,21 +7,23 @@ GX2Texture *JPEG_LoadTexture(std::span data) { GX2Texture *texture = nullptr; + int height; + int width; - tjhandle handle = tjInitDecompress(); + tjhandle handle = tj3Init(TJINIT_DECOMPRESS); if (!handle) { - return nullptr; + goto error; } - int height; - int width; - int subsamp; - int colorspace; - if (tjDecompressHeader3(handle, - data.data(), data.size(), - &width, &height, - &subsamp, &colorspace)) { - DEBUG_FUNCTION_LINE_ERR("Failed to parse JPEG header\n"); + if (tj3DecompressHeader(handle, data.data(), data.size())) { + DEBUG_FUNCTION_LINE_ERR("Failed to parse JPEG header: %s\n", tj3GetErrorStr(handle)); + goto error; + } + + width = tj3Get(handle, TJPARAM_JPEGWIDTH); + height = tj3Get(handle, TJPARAM_JPEGHEIGHT); + if (width == -1 || height == -1) { + DEBUG_FUNCTION_LINE_ERR("Unknown JPEG image size\n"); goto error; } @@ -62,19 +64,16 @@ GX2Texture *JPEG_LoadTexture(std::span data) { goto error; } - if (tjDecompress2(handle, - data.data(), data.size(), - static_cast(texture->surface.image), - width, - texture->surface.pitch * 4, - height, - TJPF_RGBA, - 0)) { - DEBUG_FUNCTION_LINE_ERR("Failed to read JPEG image\n"); + if (tj3Decompress8(handle, + data.data(), data.size(), + static_cast(texture->surface.image), + texture->surface.pitch * 4, + TJPF_RGBA)) { + DEBUG_FUNCTION_LINE_ERR("Failed to read JPEG image: %s\n", tj3GetErrorStr(handle)); goto error; } - tjDestroy(handle); + tj3Destroy(handle); GX2Invalidate(GX2_INVALIDATE_MODE_CPU | GX2_INVALIDATE_MODE_TEXTURE, texture->surface.image, texture->surface.imageSize); @@ -86,6 +85,6 @@ GX2Texture *JPEG_LoadTexture(std::span data) { std::free(texture->surface.image); } std::free(texture); - tjDestroy(handle); + tj3Destroy(handle); return nullptr; } diff --git a/source/gfx/gfx.c b/source/gfx/gfx.c index 5bc9078..df33e02 100644 --- a/source/gfx/gfx.c +++ b/source/gfx/gfx.c @@ -200,7 +200,7 @@ static BOOL initBucketHeap() { sGfxHeapForeground = MEMCreateExpHeapEx(base, size, 0); if (!sGfxHeapForeground) { - WHBLogPrintf("%s: MEMCreateExpHeapEx(0x%08X, 0x%X, 0)", __FUNCTION__, base, size); + WHBLogPrintf("%s: MEMCreateExpHeapEx(%p, 0x%X, 0)", __FUNCTION__, base, size); return FALSE; } @@ -476,4 +476,4 @@ BOOL GfxInitShaderAttribute(WHBGfxShaderGroup *group, attrib->mask = GfxGetAttribFormatSel(format); attrib->endianSwap = GX2_ENDIAN_SWAP_DEFAULT; return TRUE; -} \ No newline at end of file +}