Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions source/gfx/JPEGTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@

GX2Texture *JPEG_LoadTexture(std::span<uint8_t> 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;
}

Expand Down Expand Up @@ -62,19 +64,16 @@ GX2Texture *JPEG_LoadTexture(std::span<uint8_t> data) {
goto error;
}

if (tjDecompress2(handle,
data.data(), data.size(),
static_cast<unsigned char *>(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<unsigned char *>(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);
Expand All @@ -86,6 +85,6 @@ GX2Texture *JPEG_LoadTexture(std::span<uint8_t> data) {
std::free(texture->surface.image);
}
std::free(texture);
tjDestroy(handle);
tj3Destroy(handle);
return nullptr;
}
4 changes: 2 additions & 2 deletions source/gfx/gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -476,4 +476,4 @@ BOOL GfxInitShaderAttribute(WHBGfxShaderGroup *group,
attrib->mask = GfxGetAttribFormatSel(format);
attrib->endianSwap = GX2_ENDIAN_SWAP_DEFAULT;
return TRUE;
}
}
Loading