karlch/vimiv-qt

Way to suppress libpng warning

Closed this issue ยท 6 comments

I'd like to be able to suppress libpng warnings from printing into my console.

libpng warning: iCCP: known incorrect sRGB profile

Often the problem happen with bad PNG files, but I also noticed the issue on JPEG files. With some debugging, seems that thumbnail generation may be involved.

> file 1_160328214212_1.jpg
1_160328214212_1.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, Exif Standard: [TIFF image data, big-endian, direntries=13, height=5000, bps=0, PhotometricInterpretation=RGB, orientation=upper-left, width=3459], baseline, precision 8, 1080x1920, components 3
[20:44:20] DEBUG    <imutils.filelist>   Image filelist: loading single path /home/mateus/Pictures/test/1_160328214212_1.jpg
[20:44:20] DEBUG    <gui.thumbnail>      Updating thumbnails...
[20:44:20] DEBUG    <gui.thumbnail>      Adding new thumbnail '/home/mateus/Pictures/test/1_160328214212_1.jpg'
[20:44:20] DEBUG    <gui.thumbnail>      ... update completed
libpng warning: iCCP: known incorrect sRGB profile
[20:44:20] DEBUG    <gui.thumbnail>      Selecting thumbnail number 0
[20:44:20] DEBUG    <gui.library>        Selecting library path '/home/mateus/Pictures/test/1_160328214212_1.jpg' via slot
[20:44:20] DEBUG    <gui.library>        Selecting library row 2

I know I can redirect vimiv's output to /dev/null, but it would be nice to have libpng warning respecting vimiv's --log-level option. Currently even --log-level critical does not work at all...

This makes a lot of sense, I agree it would be nice to be able to silence non-internal warnings in general. Not sure how exactly this would work, this one certainly happens somewhere within the image loading of Qt, but hopefully there is some api to control how noisy Qt is. Definitely something to look into, thanks for the suggestion!

I've investigated this error a little. I think the reason the issue comes up with JPEG images is that ICC profiles are copied from the original image to its thumbnail. libpng is very stringent about not using outdated color profiles, so it produces an error when loading the thumbnail, but the JPEG decoder doesn't while loading the original.

The one way I know to directly suppress this error might be to change the callback function libpng uses to handle errors (this doesn't mean there aren't other ways), and that would involve changing the QT source code. Or using a different means to read PNG images.

As a potential workaround, it looks like there are functions in QImage to perform color space conversions. Maybe converting to the built-in sRGB profile from QT would satisfy libpng?

karlch commented

Thanks for investigating this!

Personally, I don't think this error is worth digging that deep. If there is a generic and simple way to make these types of messages comply with our log-level, great! But having a case-by-case workaround, potentially messing all the way with image loading, seems over the top ๐Ÿ˜Š

You're welcome!

And yeah, I'll tend to agree with you. It's mostly just an abstract drive to understand the problem, at this point. The best generic solution I can think of is piping the output through sed or something to scrub out the libpng entries.

karlch commented

I am not quite sure why this was missed until now, but using QLoggingCategory seems to work just fine, e.g. with

QLoggingCategory.setFilterRules("*.warning=false")

or passing it using the environment variable upon startup

QT_LOGGING_RULES="*.warning=false" vimiv

Should be quite simple to just apply corresponding rules when we set our log-level I hope ๐Ÿ˜Š

karlch commented

Just as an additional point, I wouldn't ever enable anything below warning, info and debug get waay to verbose for regular purposes.