BinomialLLC / basis_universal

Basis Universal GPU Texture Codec
Apache License 2.0
2.66k stars 260 forks source link

ERROR: Compressor kinda failed reading a source png! #270

Open Usnul opened 2 years ago

Usnul commented 2 years ago

Tried out the compressor today, immediately ran into an issue, Not much in the log to help.

command:

basisu -ktx2  -comp_level 6 -file "emissive_amaranth_blue_256.png" -output_file "emissive_amaranth_blue_256.ktx2"

console output:

Basis Universal GPU Texture Compressor v1.15
Copyright (C) 2019-2021 Binomial LLC, All rights reserved
Using SSE 4.1: 1, Multithreading: 1, Zstandard support: 1
Processing 1 total file(s)
ERROR: Failed reading source image: emissive_amaranth_blue_256.png
ERROR: Compressor failed reading a source image!

And here's the offending image emissive_amaranth_blue_256

Is it because there is too much red?

richgel999 commented 2 years ago

Hi, The provided PNG file is corrupted, so this behavior is correct. It has a CRC error in the iCCP chunk.

image

You can validate your .PNG using the "pngcheck" utility: http://www.libpng.org/pub/png/apps/pngcheck.html

richgel999 commented 2 years ago

PNG images are loaded using lodepng - it checks the header CRC's and zlib adler32's. Not all readers do, which is not correct behavior: https://lodev.org/lodepng/

If you can save your image to a valid and well-formed .PNG file, it'll load. This file is either not actually a .PNG file or is not well formed.

Thanks for the report - I'll save this as a test case, although if the file is invalid there's not much we can do.

Usnul commented 2 years ago

Thanks a lot for response @richgel999 , that's a useful utility!

The image was produced with GIMP 2.10.10

As for

although if the file is invalid there's not much we can do.

I would recommend a bit more info in the output. I literally went through the file chunk by chunk in a png reader via a debugger and couldn't find an issue. Also every reading tool I tried had no issue with it, so I was completely stumped. That is not to say "hey you guys, I'm so upset", it's that I'm sure others would appreciate some more info. At least something like "the file is corrupt".

Btw, I did find out that lodepng is used, and that fact didn't seem to help me, even poking around the source code.

richgel999 commented 2 years ago

I should be able to write more descriptive error output.