nothings / stb

stb single-file public domain libraries for C/C++
https://twitter.com/nothings
Other
26.58k stars 7.7k forks source link

stb_image.h: better corrupt image reporting #1365

Open nothings opened 2 years ago

nothings commented 2 years ago

The function void *stbi__load_main calls test() functions for each image format. If the function succeeds, then it accepts that it is the proper image format and calls the corresponding loader function (which may itself then fail). If the test() function fails, the next image format is attempted. If all attempted image formats fail, then a new error is generated: Image not of any known type, or corrupt.

This means that any attempt to report specific corruptions in the image formats during the "test" stage are discarded and never useful except in a debugger.

I propose rewriting this in some way so that if a test gets sufficiently far, it wins and its error diagnostic is actually reported. This may require two stages of test, or some kind of error code reported by test() which is "how likely is it that this is actually the correct image format for this file".

Making this change would hopefully make it easier for users to diagnose problems on their own, and make it easier for us to handle reports here since we might get more useful info in the initial report.

paulwratt commented 2 years ago

return (or set global array) weight-ing measure for each image type tried, like file does, then afterwards you can decide how you want to integrate that into the flow-control: auto "best weight", user/programmer determined, or just report "best weight" fail, etc