LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: MineGame159 on August 17, 2019, 11:46:26

Title: [MODIFIED] stbi_load_from_memory returns corrupt jpeg
Post by: MineGame159 on August 17, 2019, 11:46:26
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:
Code: [Select]
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.
Title: Re: [MODIFIED] stbi_load_from_memory returns corrupt jpeg
Post by: sc on September 22, 2019, 08:32:58
I'm seeing the same 'Corrupt JPEG' output with the LWJGL3/demo-Image example.
Title: Re: [MODIFIED] stbi_load_from_memory returns corrupt jpeg
Post by: spasi on September 22, 2019, 12:12:01
I cannot reproduce this. What's the test environment (LWJGL version, OS, etc.)?
Title: Re: [MODIFIED] stbi_load_from_memory returns corrupt jpeg
Post by: sc on September 24, 2019, 07:31:08
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 ?
Title: Re: [MODIFIED] stbi_load_from_memory returns corrupt jpeg
Post by: spasi on September 24, 2019, 07:48:56
Yes, both jpg and png are supported. Could you share the image for which that message is produced?
Title: Re: [MODIFIED] stbi_load_from_memory returns corrupt jpeg
Post by: sc on September 24, 2019, 08:18:08
Sure, but I think it is for any png file (I tried several).
I've included 2 as attachment.
Title: Re: [MODIFIED] stbi_load_from_memory returns corrupt jpeg
Post by: spasi on October 15, 2019, 16:00:08
I'm sorry, forgot to reply to this. Looks like it's a known issue: stb#787 (https://github.com/nothings/stb/issues/787). For now, you can safely ignore the error message, as long as you get a non-NULL result.
Title: Re: [MODIFIED] stbi_load_from_memory returns corrupt jpeg
Post by: sc on October 15, 2019, 18:36:59
Thanks !