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

Improve best-filter-per-line heuristic used in filter mode 5 #16

Closed
shssoichiro opened this issue Mar 4, 2016 · 3 comments
Closed

Improve best-filter-per-line heuristic used in filter mode 5 #16

shssoichiro opened this issue Mar 4, 2016 · 3 comments
Assignees
Labels
I-High Issues that are breaking core functionality for a small number of users

Comments

@shssoichiro
Copy link
Owner

Noted via Reddit:

Here are some benchmarks I took for this.
The sample image was http://cdn.wccftech.com/wp-content/uploads/2015/03/The-Witcher-3-Wild-Hunt.png which is a 12MB 4k file.
Time:
opt-level Oxipng Optipng
2 33.01s 48.73s
3 62.01s 80.08s
4 240.07s 296.18s
Size decrease:
opt-level Oxipng Optipng
2 131049 bytes 249706 bytes
3 131049 bytes 249706 bytes
4 283777 bytes 283777 bytes

@shssoichiro shssoichiro added the I-High Issues that are breaking core functionality for a small number of users label Mar 4, 2016
@shssoichiro
Copy link
Owner Author

This is related to filter mode 5. The current heuristic for picking the best filter per line in mode 5 doesn't do as good of a job as the heuristic in optipng, and worse compression is the result.

@shssoichiro shssoichiro changed the title o1 through o3 modes compress significantly worse than optipng Improve best-filter-per-line heuristic used in filter mode 5 Mar 4, 2016
@shssoichiro
Copy link
Owner Author

I am having much trouble finding how optipng determines which filter to use per line in mode 5. It seems to be in libpng, but I can't find the code that libpng is using when PNG_ALL_FILTERS is set.

@shssoichiro shssoichiro added T-Help Wanted The core maintainer cannot work this issue and would like another developer to take a look and removed T-Help Wanted The core maintainer cannot work this issue and would like another developer to take a look labels Mar 8, 2016
@shssoichiro
Copy link
Owner Author

Discovered this on http://www.libpng.org/pub/png/book/chapter09.html

The approach that has by now become standard is known as the minimum sum of absolute differences heuristic and was first proposed by Lee Daniel Crocker in February 1995. In this approach, the filtered bytes are treated as signed values--that is, any value over 127 is treated as negative; 128 becomes -128 and 255 becomes -1. The absolute value of each is then summed, and the filter type that produces the smallest sum is chosen. This approach effectively gives preference to sequences that are close to zero and therefore is biased against filter type None.

@shssoichiro shssoichiro self-assigned this Mar 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-High Issues that are breaking core functionality for a small number of users
Projects
None yet
Development

No branches or pull requests

1 participant