Efficient-Compression-Tool icon indicating copy to clipboard operation
Efficient-Compression-Tool copied to clipboard

Optimize LodePNG

Open woot000 opened this issue 2 years ago • 2 comments

Refactor and optimize existing LodePNG functions

These changes decrease the size of the compiled LodePNG code and speed up optimizing PNGs using the --allfilters switch

On MSYS2 MINGW64 gcc 12.2.0, LodePNG code is

  • 10.62% smaller (170386 bytes -> 152288 bytes, 17.67kB smaller)
  • ~11.17% faster, using the command ect -4096 -strip --allfilters "neat image.png" (47.2513s -> 41.9741s)

On MSYS2 CLANG64 clang 15.0.0, LodePNG code is

  • 6.67% smaller (169356 bytes -> 158052 bytes, 11.04kB smaller)
  • ~11.83% faster, using the command ect -4096 -strip --allfilters "neat image.png" (42.8687s -> 37.7980s)

There's a ~0.5% speed increase for the --allfilters-b switch, otherwise there is no measurable speed difference optimizing PNGs not using --allfilters or --allfilters-b

woot000 avatar Sep 10 '22 15:09 woot000

Most other changes look fine, I'll try to go through them in the coming days, might take longer though due to other obligations

fhanau avatar Sep 11 '22 00:09 fhanau

Worked on this a while ago but only recently managed to clean it up given the large scale of changes within one pull request: With the latest commit, many of the changes are integrated. This includes all changes I find useful outside of small cosmetic changes and changes to filter() and optimize_palette(). While there are several changes in these functions that may be useful, reviewing them would be lengthy and complex work while only promising to gain small code size improvements and a tiny speedup in some scenarios. For now, I will leave this pull request open and might integrate filter/palette changes later on, but it is not a priority.

fhanau avatar Dec 16 '22 23:12 fhanau