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

Speed up optimized PNG compression with pre-computed parameters #1338

Open
heinezen opened this issue Nov 24, 2020 · 0 comments
Open

Speed up optimized PNG compression with pre-computed parameters #1338

heinezen opened this issue Nov 24, 2020 · 0 comments

Comments

@heinezen
Copy link
Member

@heinezen heinezen commented Nov 24, 2020

Required skills: Python, maybe Cython

Difficulty: Medium

The openage converter is able to optimize the compression for created PNG files by utilizing a search algorithm inspired by OptiPNG. To do this, the search algorithm first tries 8 different compression settings by creating PNGs with these settings in-memory. The compression settings that produced the smallest PNG are then used to export the image data into a PNG file. Using the optimized compression usually results in a much smaller file size (~50% of unoptimized size). However, the optimized compression is currently much slower as the resulting PNG has to be created 8 times (instead of 1 time with unoptimized compression) before it can be exported.

The way we can speed this process up is to save the best compression settings for each source image in a configuration file and use them as input during the PNG export phase. As a result, the PNG exporter can skip the 8 trials of the search algorithm and directly generate the "best" PNG. Furthermore, using optimized compression would then be as fast as using unoptimized compression.

To do this, we have to do the following:

  1. Save the best compression settings for each source image in a configuration file
  2. Load the file for media conversion and forward the compression settings to the PNG exporter
  3. Use the settings during PNG export (this is already implemented)

For the configuration file, TOML should be used. The compression settings should be accompanied by information to identify the source image file (i.e. filepath and a SHA-256 hash value).

Example:

# Header
# The version of this config file format
file_version = "1.0"
hash_algo = "SHA3-256"

[images]
    [2.slp]
    "filepath" = "graphics/2.slp"
    "hash" = "DEDF4675668799912378178479281"
    "settings" = [4, 5, 6, 7]

    [1080.slp]
    "filepath" = "graphics/1080.slp"
    "hash" = "79244847392374923749273497237"
    "settings" = [4, 5, 6, 7]

Further Reading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
convert
  
input
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.