godotengine / godot

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

Can't load textures in gray color space #91600

Open passivestar opened 3 months ago

passivestar commented 3 months ago

Tested versions

v4.3.dev6.official [89850d553]

System information

Godot v4.3.dev6 - macOS 14.4.1 - Vulkan (Forward+) - integrated Apple M1 Max - Apple M1 Max (10 Threads)

Issue description

image

This is what macos tells me about them:

image

This is what some online analyzer tells:

image image

image

RGB textures load with no problem

Steps to reproduce

MRP

Minimal reproduction project (MRP)

Image that gives an identical error provided by @theraot:

https://github.com/user-attachments/files/15511511/new_test.zip

theraot commented 2 months ago

I did some testing, playing with export settings in Gimp and seeing what caused an error. And what caused an error - which looks identical to the OP one - was trying to import a jpg exported with the setting "Use arithmetic coding". I cannot guarantee that it is the same issue, but this is the only way I managed to get the error, so I believe it likely is.

Gimp documentation says:

Arithmetic encoding is a form of entropy encoding (a lossless data compression scheme) that, since GIMP-2.10 can be used in exporting as JPEG. Images using arithmetic encoding can be 5 - 10 % smaller. But older software may have trouble opening these images.

Here is a wikipedia article on the topic: https://en.wikipedia.org/wiki/Arithmetic_coding

Here is the picture I created: test.zip

Notes:


Now, this is not a regression. I tested the same picture on multiple versions of Godot, and all versions from Godot 3.2 to 3.6 beta4 and from Godot 4.0 alpha1 to Godot 4.3 dev6 had a similar error (with differences in line number).

I hope this allows you to workaround the issue, and perhaps confirm if your textures use arithmetic coding.

And about fixes... Barring adding support for these pictures, this limitation should be documented, and perhaps the error message could be changed to something more useful.

Calinou commented 2 months ago

was trying to import a jpg exported with the setting "Use arithmetic coding"

This option is known for being poorly supported in various programs (even some web browsers will fail to load those JPEGs).

To improve the error message, I'm not sure if there's a reliable way to detect whether a JPEG uses arithmetic coding (either using the jpeg library we're currently using, or by reading the file's bytes directly if it faisl to load).

theraot commented 2 months ago

It seems to be already detected, although I do not know if that is surfaced to Godot: https://github.com/godotengine/godot/blob/master/thirdparty/jpeg-compressor/jpgd.cpp#L1054

passivestar commented 2 months ago

This option is known for being poorly supported in various programs (even some web browsers will fail to load those JPEGs)

Tested my problematic images with different software, all of the following load them with no problem:

I couldn't find any app that wouldn't open them. So maybe it's a different problem?

theraot commented 2 months ago

Ok, on my end Firefox won't render my test picture, so you might be correct on this being a different issue.

Notes:

passivestar commented 2 months ago

I put an image through some online analyzer and attached the results on top in case that gives any ideas

theraot commented 2 months ago

That confirms it does not have the markers for arithmetic encoding, but for Huffman encoding.

I'll post if I manage to make a test picture that resembles the OP info and causes the import error.

theraot commented 2 months ago

Ok, I have another problematic picture: new_test.zip (this time it is an exclamation mark because why not).

This is a Grayscale image with Chromma subsampling 4:2:0 (Gimp didn't let me set this subsampling, forcing 4:4:4 when using Grayscale, so I had to resource to other tools).

None of the applications that had problems with the old test picture have problems with this one. But the error message on Godot is the same. And I didn't find a version of Godot that would import it either.

passivestar commented 2 months ago

None of the applications that had problems with the old test picture have problems with this one. But the error message on Godot is the same. And I didn't find a version of Godot that would import it either.

Can confirm the same behavior on macOS

Here's your test picture loaded in unity with no problem:

image

Attached your picture as an MRP

passivestar commented 2 months ago

Decoding fails here with JPGD_UNSUPPORTED_SAMP_FACTORS:

https://github.com/godotengine/godot/blob/7b63ac488e6e27b1d712bbd6b55afae46c0028ff/thirdparty/jpeg-compressor/jpgd.cpp#L2570-L2571