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

Image compresses better with duplicate entries kept in palette #553

Open
Rainboom-Dash opened this issue Sep 19, 2023 · 13 comments
Open

Image compresses better with duplicate entries kept in palette #553

Rainboom-Dash opened this issue Sep 19, 2023 · 13 comments
Labels
T-Compression Relates to improving the compression ratio of images

Comments

@Rainboom-Dash
Copy link

I'm getting increased file sizes with the latest commits that I built on Sept 4th versus the latest stable release
I've tested the default libdeflate compression and zopfli and both are increasing file size considerably
sourceimagetocompress
This is not the only image that is getting increased file sizes but it is one of the more significant ones that has a few percent increase (maybe because the file size is smaller to begin with)
On average it seems the latest commits decrease file size slightly... but there are some regressions
I thought maybe it was just the libdeflate since the version was changed but it seems zopfli is affected as well...
withlateststablerelease
withlatestcommits
The image I tested with has had optipng run on it (the site I downloaded from automatically does that)

@andrews05
Copy link
Collaborator

Hi @Rainboom-Dash, thanks for posting this.
This is quite interesting. The image has many duplicate entries in the palette which somehow are helping it to compress better. The current code assumes that duplicate entries are bad and will always remove them to reduce the palette size. Some investigation will be needed to understand this better and see how we can improve it, but in the meantime you can avoid palette reduction by using the --np flag.

@ace-dent Do you know anything about deliberate duplicates in a palette like this? I'm pretty sure optipng wouldn't do that.

@andrews05 andrews05 added the T-Compression Relates to improving the compression ratio of images label Sep 20, 2023
@ace-dent
Copy link

ace-dent commented Sep 20, 2023

@Rainboom-Dash - very interesting file. Where did it come from and do you know what software produced it?
@andrews05 - never seen this before... will investigate! Metadata suggests software called GLDPNG ...? There is always the potential that the input palette is more optimal; so perhaps a --np pass should always be run for the most extreme settings?... not sure if some smarter detection is possible...?

The pngthermal image shows the surprisingly very low entropy achieved across the whole image...

rainbowdash png thermal

@Rainboom-Dash
Copy link
Author

I downloaded from https://derpibooru.org/images/3198446 which was taken from https://www.deviantart.com/boxwari/art/Flurry-Musicante-981750954 which I just now realized I probably should of downloaded from Deviantart just to get closer to the source

It does seem like --np gets a few percent better compression here

@TPS
Copy link

TPS commented Sep 20, 2023

FWICT, this is 2 separate issues now:

Did I misunderstand?

Also, does the observation of the duplicate palette entries corresponding to allowing better compression make sense, or is that a potential correlation/causation error?

@ace-dent
Copy link

@andrews05 - I wonder if the edge preference heuristic I suggested, is failing here...?

@ace-dent
Copy link

Attached version produced with other tools. Reduced palette and smaller IDAT size.

rainbowdash

@andrews05
Copy link
Collaborator

@ace-dent The target IDAT size is 47918, as achieved with --np (or v8).
Disabling the edge heuristic in oxipng made little difference.

I took a quick look at the GLDPNG source. It's definitely not an optimiser or doing anything interesting with the palette, so either something else is responsible for this or it's just accidental (entirely possible).

@TPS The structure/order of palette can have a big impact on line filtering. It's not unthinkable that some weird optimisation might be achieved by spreading out the colours like this, it's just not something I've seen or considered before. Nor can I imagine how one might implement such a strategy.

@Rainboom-Dash Would you be able to post a couple more samples that have regressed like this?

@TPS
Copy link

TPS commented Sep 20, 2023

@andrews05 Since @ace-dent has found tools that solve this sensibly (optimized reduced pallette & IDAT), IMHO, not worth pursuing this weird "ordering," but rather, whatever those tools are doing.

@Rainboom-Dash
Copy link
Author

@andrews05 I believe the other losses are due to libdeflate and it's usually around 0.1% file size increase or less... and usually it has decreased file size not increased... it's just sometimes it increases... but yeah, it's pretty small and I think that will just happen when the algorithm changes..

@andrews05
Copy link
Collaborator

@Rainboom-Dash Good to know. This one remains a unique mystery then.

I've just posted a PR to resolve this by keeping the original palette, same as it did in v8. But I think we should keep the issue open for further investigation.

@andrews05 andrews05 changed the title Increased file sizes with latest commits versus latest stable release Image with duplicate entries in palette compresses better than when duplicates are removed Sep 22, 2023
@andrews05 andrews05 changed the title Image with duplicate entries in palette compresses better than when duplicates are removed Image compresses better with duplicate entries kept in palette Sep 22, 2023
@TPS
Copy link

TPS commented Sep 22, 2023

@andrews05 Per @ace-dent's note above, this title change doesn't represent the current best for this image, just the weird quirky original? So maybe analyze the intermediate & try to meet/beat that? 🙇🏾‍♂️

@ace-dent It'd probably really help if you'd post what toolchain you used to get your result. 🙇🏾‍♂️

@andrews05
Copy link
Collaborator

@TPS If you check the image @ace-dent posted, it's larger than the result of both oxipng v8 and oxipng master, whose sizes are shown in the first post. So I'm not quite sure what it's demonstrating, unless he posted the wrong image?

@TPS
Copy link

TPS commented Sep 23, 2023

Attached version produced with other tools. Reduced palette and smaller IDAT size.

@ace-dent Did you post the correct version of the image?

@andrews05 andrews05 mentioned this issue Dec 1, 2024
AlexTMjugador pushed a commit that referenced this issue Dec 2, 2024
I've replaced a few tests with synthetic images and removed a number
that I don't believe are relevant anymore.

I've also removed the #553 test without replacement as I don't know how
to synthesise a replacement and the issue is still open anyway.

Going forward I think we should avoid adding any new "issue" tests and
instead synthesise something suitable in one of the other collections.

Closes #655.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Compression Relates to improving the compression ratio of images
Projects
None yet
Development

No branches or pull requests

4 participants