godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.62k stars 21.1k forks source link

Cannot import JPEG images with sampling factors not supported by jpgd #75349

Open TheYellowArchitect opened 1 year ago

TheYellowArchitect commented 1 year ago

Godot version

4.0.1

System information

Arch Linux

Issue description

There are certain .jpg images where Godot just cannot import the image. The image is not corrupted, all file editors display it normally. And ofc, an X cross sign appears on the image file in godot's filesystem tab. No preview, nor loading it to some texture or sprite works.

This bug was not created in 4.0.1, I can confirm it was present since 4.0 beta14. I also tested 3.5.1, it exists there too.

Steps to reproduce

  1. Open empty project
  2. Import this: 29284413

Minimal reproduction project

See above.

jmb462 commented 1 year ago

Seems that this JPG file use not supported sampling factors causing jpeg_decoder::init_frame() to failed.

File godot\thirdparty\basis_universal\encoder\jpgd.cpp line 2528

m_comp_h_samp = {2, 1, 1, 0} m_comp_v_samp = {2, 1, 2, 0} <= here, only value supported for the index 2 is 1.

Returning JPGD_UNSUPPORTED_SAMP_FACTORS error.

Calinou commented 1 year ago

File godot\thirdparty\basis_universal\encoder\jpgd.cpp line 2528

That JPEG decoder is only used by Basis Universal – I'm not even sure if this code is used in Godot.

https://github.com/godotengine/godot/blob/master/thirdparty/jpeg-compressor/jpgd.cpp is the decoder actually used by Godot, though its code appears nearly identical.

jmb462 commented 1 year ago

Following step by step debugger leads me to the Basis Universal file.