Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PNG files are often corrupted when inputs are monochrome. #426

Closed
tommyettinger opened this issue Nov 21, 2021 · 10 comments · Fixed by #470
Closed

PNG files are often corrupted when inputs are monochrome. #426

tommyettinger opened this issue Nov 21, 2021 · 10 comments · Fixed by #470
Labels
I-Medium Issues that are breaking core functionality, but have a known workaround T-Bug Some piece of the software is not working as intended

Comments

@tommyettinger
Copy link

tommyettinger commented Nov 21, 2021

Processing: Mona_Lisa-PNG8-Scatter-BW.png
    404x600 pixels, PNG format
    1x8 bits/pixel, Grayscale
    IDAT size = 18171 bytes
    File size = 18242 bytes
Reducing image to 1x1 bits/pixel, Grayscale
Trying: 6 combinations
Found better combination:
    zc = 0  zs = 0  f = 0        16966 bytes
    IDAT size = 16966 bytes (1205 bytes decrease)
    file size = 17037 bytes (1205 bytes = 6.61% decrease)
The resulting image is corrupted and will not be outputted.
This is a bug! Please report it at https://github.com/shssoichiro/oxipng/issues
The resulting image is corrupted

I don't know what's happening here, but I ran the command line oxipng -s -o 6 -Z --fix *BW.png in an attempt to figure out why earlier runs (without -Z, as well as with and without -D) had some corrupt images, but only for monochrome black and white PNGs (1-bit). All of the attached PNGs had corrupt output when given the above command line. I an on Windows 10 64-bit, and used a just-downloaded 5.0.1 release. Zopfli compression claimed it had significant size reductions, but then also that the output was corrupted and so was not saved. I don't have a Rust dev environment set up, and I suspect compiling oxipng from source would be a challenge for me, so I guess I'm just reporting what it says to report, and providing some of the images that failed.

Mona_Lisa-PNG8-BlueNoise-BW
Mona_Lisa-PNG8-ChaoticNoise-BW
Mona_Lisa-PNG8-Diffusion-BW
Mona_Lisa-PNG8-Gradient-BW
Mona_Lisa-PNG8-Neue-BW
Mona_Lisa-PNG8-None-BW
Mona_Lisa-PNG8-Pattern-BW
Mona_Lisa-PNG8-Scatter-BW

EDIT: I originally uploaded GIFs, not PNGs, though the contents were identical. Sorry about that!

@TPS
Copy link

TPS commented Nov 21, 2021

Just as a note, multiple other PNG tools have real problems with 1-bit/2-bit grayscale PNGs, so it'd be amazing to have 1 that works well w/ them! 🙇🏾‍♂️

@K0-RR
Copy link

K0-RR commented Nov 21, 2021

@tommyettinger the images you uploaded are for some reason gifs, not pngs.
https://user-images.githubusercontent.com/160684/142752853-ae28199a-0b6e-47ad-8344-26a75abb5b7f.gif

@shssoichiro shssoichiro added I-High Issues that are breaking core functionality for a small number of users T-Bug Some piece of the software is not working as intended labels Nov 21, 2021
@tommyettinger
Copy link
Author

Whoops, on it. I generate both. I'll edit the original post.

@K0-RR
Copy link

K0-RR commented Nov 21, 2021

Tried two images and everything seems to be working fine (oxipng 5.0.1 on Linux downloaded from the releases)

oxipng -s -o 6 -Z --fix ./142777810-135a9355-1404-40b1-b9cf-d01949d70370.png 
Level 4 and above are equivalent to level 3 for compressors other than zlib
Processing: ./142777810-135a9355-1404-40b1-b9cf-d01949d70370.png
    404x600 pixels, PNG format
    1 bits/pixel, 2 colors in palette
    IDAT size = 12214 bytes
    File size = 12289 bytes
Trying: 6 combinations
Found better combination:
    zc = 0  zs = 0  f = 0        12104 bytes
    IDAT size = 12104 bytes (110 bytes decrease)
    file size = 12179 bytes (110 bytes = 0.90% decrease)
Output: ./142777810-135a9355-1404-40b1-b9cf-d01949d70370.png

@TPS
Copy link

TPS commented Nov 21, 2021

So, maybe a Windows-build-only problem?

@tommyettinger Did you ever try it 1 PNG @ a time, or only via glob-match?

@shssoichiro
Copy link
Owner

I am also unable to reproduce this on Windows. I've tried using both a binary that I compiled myself, and the binary posted on the releases page.

@tommyettinger
Copy link
Author

tommyettinger commented Nov 22, 2021

I keep screwing this up, I am so sorry; I forgot that I had run pngout on the PNGs after I had uploaded the GIF files, but before I uploaded the PNGs again. This means the PNGs had already been successfully compressed and reduced to 1-bit depth. I'm going to regenerate the files and see if I can get the problem to occur again.
...
I did this and I think I know what the problem is. I think the files are already partially or fully corrupted because I ran apngopt on all PNG files in the original folder. I'm going to attach the files in a .zip to avoid potentially having them be re-encoded by GitHub's camo service. I don't think this is a problem with oxipng, even though oxipng seems to think it is; it is more likely a problem with apngopt (especially when run on non-animated PNG files).

λ oxipng -s -o 6 -Z --fix *BW.png
Level 4 and above are equivalent to level 3 for compressors other than zlib
Processing: Mona_Lisa-PNG8-BlueNoise-BW.png
    404x600 pixels, PNG format
    1x8 bits/pixel, Grayscale
    IDAT size = 13487 bytes
    File size = 13558 bytes
Reducing image to 1x1 bits/pixel, Grayscale
Trying: 6 combinations
Found better combination:
    zc = 0  zs = 0  f = 0        12104 bytes
    IDAT size = 12104 bytes (1383 bytes decrease)
    file size = 12175 bytes (1383 bytes = 10.20% decrease)
The resulting image is corrupted and will not be outputted.
This is a bug! Please report it at https://github.com/shssoichiro/oxipng/issues
The resulting image is corrupted
Processing: Mona_Lisa-PNG8-ChaoticNoise-BW.png
    404x600 pixels, PNG format
    1x8 bits/pixel, Grayscale
    IDAT size = 21975 bytes
    File size = 22046 bytes
Reducing image to 1x1 bits/pixel, Grayscale
Trying: 6 combinations
Found better combination:
    zc = 0  zs = 0  f = 0        19440 bytes
    IDAT size = 19440 bytes (2535 bytes decrease)
    file size = 19511 bytes (2535 bytes = 11.50% decrease)
The resulting image is corrupted and will not be outputted.
This is a bug! Please report it at https://github.com/shssoichiro/oxipng/issues
The resulting image is corrupted
Processing: Mona_Lisa-PNG8-Diffusion-BW.png
    404x600 pixels, PNG format
    1x8 bits/pixel, Grayscale
    IDAT size = 13132 bytes
    File size = 13203 bytes
Reducing image to 1x1 bits/pixel, Grayscale
Trying: 6 combinations
Found better combination:
    zc = 0  zs = 0  f = 0        12495 bytes
    IDAT size = 12495 bytes (637 bytes decrease)
    file size = 12566 bytes (637 bytes = 4.82% decrease)
The resulting image is corrupted and will not be outputted.
This is a bug! Please report it at https://github.com/shssoichiro/oxipng/issues
The resulting image is corrupted
Processing: Mona_Lisa-PNG8-Gradient-BW.png
    404x600 pixels, PNG format
    1x8 bits/pixel, Grayscale
    IDAT size = 14702 bytes
    File size = 14773 bytes
Reducing image to 1x1 bits/pixel, Grayscale
Trying: 6 combinations
Found better combination:
    zc = 0  zs = 0  f = 0        14096 bytes
    IDAT size = 14096 bytes (606 bytes decrease)
    file size = 14167 bytes (606 bytes = 4.10% decrease)
The resulting image is corrupted and will not be outputted.
This is a bug! Please report it at https://github.com/shssoichiro/oxipng/issues
The resulting image is corrupted
Processing: Mona_Lisa-PNG8-Neue-BW.png
    404x600 pixels, PNG format
    1x8 bits/pixel, Grayscale
    IDAT size = 16528 bytes
    File size = 16599 bytes
Reducing image to 1x1 bits/pixel, Grayscale
Trying: 6 combinations
Found better combination:
    zc = 0  zs = 0  f = 0        15688 bytes
    IDAT size = 15688 bytes (840 bytes decrease)
    file size = 15759 bytes (840 bytes = 5.06% decrease)
The resulting image is corrupted and will not be outputted.
This is a bug! Please report it at https://github.com/shssoichiro/oxipng/issues
The resulting image is corrupted
Processing: Mona_Lisa-PNG8-None-BW.png
    404x600 pixels, PNG format
    1x8 bits/pixel, Grayscale
    IDAT size = 7241 bytes
    File size = 7312 bytes
Reducing image to 1x1 bits/pixel, Grayscale
Trying: 6 combinations
Found better combination:
    zc = 0  zs = 0  f = 0        6470 bytes
    IDAT size = 6470 bytes (771 bytes decrease)
    file size = 6541 bytes (771 bytes = 10.54% decrease)
The resulting image is corrupted and will not be outputted.
This is a bug! Please report it at https://github.com/shssoichiro/oxipng/issues
The resulting image is corrupted
Processing: Mona_Lisa-PNG8-Pattern-BW.png
    404x600 pixels, PNG format
    1x8 bits/pixel, Grayscale
    IDAT size = 7654 bytes
    File size = 7725 bytes
Reducing image to 1x1 bits/pixel, Grayscale
Trying: 6 combinations
Found better combination:
    zc = 0  zs = 0  f = 0        6845 bytes
    IDAT size = 6845 bytes (809 bytes decrease)
    file size = 6916 bytes (809 bytes = 10.47% decrease)
The resulting image is corrupted and will not be outputted.
This is a bug! Please report it at https://github.com/shssoichiro/oxipng/issues
The resulting image is corrupted
Processing: Mona_Lisa-PNG8-Scatter-BW.png
    404x600 pixels, PNG format
    1x8 bits/pixel, Grayscale
    IDAT size = 18171 bytes
    File size = 18242 bytes
Reducing image to 1x1 bits/pixel, Grayscale
Trying: 6 combinations
Found better combination:
    zc = 0  zs = 0  f = 0        16966 bytes
    IDAT size = 16966 bytes (1205 bytes decrease)
    file size = 17037 bytes (1205 bytes = 6.61% decrease)
The resulting image is corrupted and will not be outputted.
This is a bug! Please report it at https://github.com/shssoichiro/oxipng/issues
The resulting image is corrupted

Before apngopt gets to these, the images are considered 8-bit-depth indexed-color PNGs; after apngopt is run, they become 8-bit-depth grayscale PNGs. I can run oxipng fine on the original files if I didn't run apngopt after generating them.

Here's the .zip of the problem files, after apngopt appears to have corrupted them:
apngopt_processed.zip

Feel free to close this issue if you agree that the problem lies outside oxipng.

EDIT: Sorry I forgot to reply to @TPS ; I did try with single files (no glob) and it has the same problems with apngopt output.

@shssoichiro
Copy link
Owner

shssoichiro commented Nov 22, 2021

Interesting. It does seem like there is potentially a problem with apngopt. However, if the png files are able to be parsed and displayed by an image viewer, which it seems they are, then oxipng should also be able to handle them gracefully. So I think there is some work to be done here on our side. Or at least more investigation into the bytes of the file, why this is being output differently than it's going in.

@shssoichiro shssoichiro added I-Medium Issues that are breaking core functionality, but have a known workaround and removed I-High Issues that are breaking core functionality for a small number of users labels Nov 22, 2021
@tommyettinger
Copy link
Author

That seems like a good approach to take. It also might help everyone understand the nature of the corruption, so apngopt can maybe fix it more easily. I used apngopt 1.4 , by the way.

@andrews05
Copy link
Collaborator

It turns out this is a bug in oxipng - see the explanation and fix in #470.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-Medium Issues that are breaking core functionality, but have a known workaround T-Bug Some piece of the software is not working as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants