Hello Guest

[MODIFIED] stbi_load_from_memory returns corrupt jpeg

  • 7 Replies
  • 7354 Views
[MODIFIED] stbi_load_from_memory returns corrupt jpeg
« 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.
« Last Edit: August 17, 2019, 17:04:40 by MineGame159 »

*

Offline sc

  • *
  • 15
Re: [MODIFIED] stbi_load_from_memory returns corrupt jpeg
« Reply #1 on: September 22, 2019, 08:32:58 »
I'm seeing the same 'Corrupt JPEG' output with the LWJGL3/demo-Image example.

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: [MODIFIED] stbi_load_from_memory returns corrupt jpeg
« Reply #2 on: September 22, 2019, 12:12:01 »
I cannot reproduce this. What's the test environment (LWJGL version, OS, etc.)?

*

Offline sc

  • *
  • 15
Re: [MODIFIED] stbi_load_from_memory returns corrupt jpeg
« Reply #3 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 ?

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: [MODIFIED] stbi_load_from_memory returns corrupt jpeg
« Reply #4 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?

*

Offline sc

  • *
  • 15
Re: [MODIFIED] stbi_load_from_memory returns corrupt jpeg
« Reply #5 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.

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: [MODIFIED] stbi_load_from_memory returns corrupt jpeg
« Reply #6 on: October 15, 2019, 16:00:08 »
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.

*

Offline sc

  • *
  • 15
Re: [MODIFIED] stbi_load_from_memory returns corrupt jpeg
« Reply #7 on: October 15, 2019, 18:36:59 »
Thanks !