Coder Social home page Coder Social logo

boogerlad / pngwolf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hoehrmann/pngwolf

1.0 2.0 0.0 2.1 MB

`pngwolf` uses a genetic algorithm to find PNG scanline filter combinations that compress well

Home Page: http://bjoern.hoehrmann.de/pngwolf/

Assembly 0.18% C 18.50% Perl 1.40% C++ 79.78% Ruby 0.01% Objective-C 0.12% PHP 0.01% Shell 0.01%

pngwolf's Introduction

pngwolf is a tool to minimize the size of PNG image files. There are a number of factors that affect the size of PNG image files, such as the number of colors in the image and whether the image data is stored as RGBA data or in the form of references to a color palette. The main factor is the quality of the Deflate compression used to compress the image data, which is in turn affected by the quality of the compressor and how well the data to be compressed is arranged.

The PNG format supports a number of scanline filters that transform the image data by relating nearby pixels mathematically. Choosing the right filters for each scanline can make the image data more compressible. It is, however, infeasible for non-trivial images to find the best filters so typical encoders rely on a couple of heuristics to find good filters.

pngwolf employs a genetic algorithm to find better filter combinations than traditional heuristics. It derives a couple of filter combinations heuristically, adds a couple of random combinations, and then looks how well each combination compresses. Two very different combinations may compress similarily well, for instance, one combination may be very good for the first couple of scanlines, while the other may be very good for the last couple of scanlines. So taking the beginning of one combination and the tail of the other to make a new one may result in a combination that compresses better then the original two.

That is, in essence, what pngwolf does, over and over again. Further, the most widely used PNG encoders use the zlib library for compression. The zlib library favours speed over compression ratio in some cases, so whatever filters are selected to aid compression, the result with zlib may not be the smallest possible. The 7-Zip library by Igor Pavlov has a Deflate encoder that favours size over speed at certain settings. So, pngwolf attempts to make use of both: a fast zlib setting is used to estimate how well some filter combination aids compression, and when it gets bored, it uses 7-Zip to generate the final result.

Doing this pngwolf is able to compress some images better than other optimizers (like OptiPNG, AdvanceCOMP, pngcrush, and pngout), either because it finds better filter combinations then they do, or be- cause it uses 7-Zip's Deflate implementation (AdvanceCOMP uses that aswell, although an older version which sometimes performs better and sometimes worse, for reasons yet to be studied). It does not attempt to make other optimizations, like converting indexed images to RGB format.

None of the tools mentioned, including pngwolf follow any kind of ho- listic approach to PNG optimization, so to get the best results they need to be used in combination (and sometimes applying them repeatedly or in different orders provides the best results). As far as I can tell most other tools do not try to preserve the filter combination in the original image, so pngwolf should usually be used last or second-to- last in the optimization process.

For images that are already optimized using all the other tools, there is about 1% further reduction to be expected from pngwolf for suit- able images. Still, it should be rare to find images on the Web that pngwolf cannot compress a little bit further.

The tool suffers from the lack of a Deflate encoder that makes it easy store the results of data analysis (where are duplicate substrings in the data) and combine them (if you recall the earlier example where it takes the head of one combination and the tail of another, an encoder would not have to analyze all of the two parts again, only where they overlap). So it can often take a long time (as in minutes) to find the best results.

Regardless of the performance deficiency pngwolf is well-suited as a research tool to come up with better heuristics for filter selection, or to extend the genetic algorithm approach to other aspects of PNG op- timization (the main thing being considered is re-arranging the entries in color palettes so the image data compresses better). The tool logs extensive information in a YAML-based machine-readable format while it attempts to optimize images which should aid in that.

It also addresses two (other) user-interface issues I had in using the other tools, namely it allows you to make it stop trying to find better optimizations at well-specified points (such as the total time used), and if you start an optimization run but grow impatient and abort the program, results should not get lost, but should be stored anyway.

To compile on linux,

cmake CMakeLists.txt
make

pngwolf's People

Contributors

boogerlad avatar hoehrmann avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.