[MODIFIED] stbi_load_from_memory returns corrupt jpeg

Started by MineGame159, August 17, 2019, 11:46:26

Previous topic - Next topic

MineGame159

I am trying to load a png file with stbi_load_from_memory, it returns bytebuffer that is not null but failure_reason is corrupt jpeg. What I am doing wrong? This is my code:
STBImage.stbi_set_flip_vertically_on_load(true);
byte[] encoded = file.readAllBytes();
ByteBuffer encodedBuffer = BufferUtils.createByteBuffer(encoded.length);
encodedBuffer.put(encoded);
encodedBuffer.flip();
ByteBuffer byteBuffer = STBImage.stbi_load_from_memory(encodedBuffer, width, height, bpp, 4);

file.readAllBytes() is correct I tested it.

It happens when loading from file stbi_load too.

sc

I'm seeing the same 'Corrupt JPEG' output with the LWJGL3/demo-Image example.

spasi

I cannot reproduce this. What's the test environment (LWJGL version, OS, etc.)?

sc

This is Windows10, lwjgl 3.2.3 (+ stb.jar)

If you run the lwjgl3/demo/image with a jpg or png file, both display correctly.
The msg printed from STBImage.stbi_failure_reason() prints :
* "ok : null" for the jpg
* "ok : currupt jpeg: for the png

As far as I know, it is ok to use the stb libr for png, right ?

spasi

Yes, both jpg and png are supported. Could you share the image for which that message is produced?

sc

Sure, but I think it is for any png file (I tried several).
I've included 2 as attachment.

spasi

I'm sorry, forgot to reply to this. Looks like it's a known issue: stb#787. For now, you can safely ignore the error message, as long as you get a non-NULL result.