Commit graph

69 commits

Author SHA1 Message Date
Andrew
a30ee05ca8 Add test for image with truncated palette 2024-03-29 09:15:27 +13:00
Andrew
e503a5c8f9 Replace grayscale test file 2024-03-11 17:38:48 +13:00
andrews05
98fd4de30a
Reduce size of release binary (#592)
This PR makes 3 changes that together reduce binary size by around 25%:
- Sets lto="fat" in cargo.toml
- Sets panic="abort" in cargo.toml
- Sets location-detail=none in RUSTFLAGS

Closes #571

An unrelated change: I've replaced the zopfli test file with a smaller
one that runs much faster, as well as removing the slow test for
issue-133 which was related to an older alpha optimisation that is no
longer relevant.
2024-02-20 19:02:12 +01:00
andrews05
f6c24409f1
If only one filter selected use it for evaluations (#582)
The filters used during reduction evaluations are normally set to None &
Bigrams, regardless of any options. This PR makes a slight change so
that if only one filter is specified in the options, this filter will be
used for reduction evaluations too.

This resolves an odd situation affecting lower levels (when --fast is
enabled) where you may try to force the filter to a specific value but
it actually ends up different because a reduction evaluation was
smaller. It's particularly helpful if you're wanting it to be as fast as
possible by using `-o0 -f0` which will now exclusively use None instead
of trying the slower Bigrams as well.

As another use, you could try to brute force oxipng by iterating each
filter separately, though this may not actually achieve anything 😂

[edit] I also pulled the options out into a separate file, though this
wasn't relevant to the filter change.
2023-12-10 13:15:45 +01:00
Andrew
0b3302316b Tidy some issue tests 2023-10-10 11:03:08 +13:00
Andrew
b808807198 Add test 2023-10-10 11:03:08 +13:00
andrews05
b883c660fc
Additional palette sorting algorithm (#514)
This adds a new palette sorting algorithm that attempts to minimise
entropy by an approximate solution to the Traveling Salesman Problem.
The algorithm comes from "An efficient Re-indexing algorithm for
color-mapped images" by Battiato et al
(https://ieeexplore.ieee.org/document/1344033).
It's fast and effective and works in addition to the luma sort (which
remains the single most effective sort). In order to keep lower presets
fast though, I've only enabled this for o3 and higher.

Results on a set of 190 indexed images at `-o5`:
18,932,727 bytes - master
18,578,306 bytes - PR
18,559,863 bytes - PR + #509
(These images may be particularly suited to alternative sorting methods
- the gains here are not necessarily what should be expected on average)

Note I looked into the 120 different palette sorting methods from
TruePNG, as mentioned in #74 (and seen in action in the Zopfli KrzYmod
fork). They're... largely ineffective. The combination of all 120
methods are outperformed by just the existing luma sort plus this new
one. That's not to say there's nothing further to be gained from them,
but trying to brute force all the combinations definitely seems like a
bad idea. There are other algorithms I hope to explore in future...

@ace-dent Thought this might interest you


UPDATE: I realised a quick tweak to alpha values in the luma sort can
provide a great improvement on images with transparency. The following
numbers were taken with PR #509 as base.
`-o2`:
19,065,549 bytes - base (luma sort)
18,949,747 bytes - modified luma sort

`-o5`:
18,922,165 bytes - base (luma sort)
18,559,863 bytes - new sorting algorithm + luma sort
18,544,813 bytes - new sorting algorithm + modified luma sort
2023-07-11 12:33:57 -04:00
andrews05
39b00910ae
Use stronger compression in eval (#509) 2023-07-08 18:54:58 -04:00
andrews05
b846a2e909
Try to pick tRNS value that's valid at low depth (#520) 2023-07-07 20:56:15 -04:00
andrews05
ea5f1884be
Refactor aux chunk handling (#505) 2023-05-21 15:34:23 -04:00
andrews05
d8b7ebaf47
Further small reduction improvements (#504) 2023-05-16 20:53:05 -04:00
andrews05
9a500941d8
Raw API (#482) 2023-05-15 08:37:49 -04:00
andrews05
2f622fc7bd
Minor reduction improvements (#502)
* Fix bKGD conversion from gray to palette

* Allow grayscale reduction from 16 to 4 or less

* Refactor reduction evaluation sequence

* Separate palette into new file
2023-05-07 17:46:58 -04:00
Andrew
d43e63f562 Remove test 167 which is no longer relevant 2023-01-06 15:35:05 -05:00
andrews05
a3b104a2ed
Faster reductions (#479)
* Add grayscale depth tests and benches

* Don't include filter byte in PngImage.data

* Simplify reductions by not using scan lines

* Faster grayscale reduction

* Simplify reduce_color_type

* Faster depth reduction
2022-12-22 16:56:36 -05:00
andrews05
2008d09915
Reduce alpha to tRNS (#477) 2022-12-13 15:18:19 -05:00
andrews05
131a3c6af7
🚀 Revamp alpha optimisation (#475) 2022-12-10 21:14:50 -05:00
andrews05
54ee621e41
Fix Grayscale depth reduction with tRNS (#470) 2022-12-08 06:11:26 -05:00
andrews05
bd5a0b526b
More Reductions (#468)
* Add test for issue 195

* Reduce grayscale alpha to palette

* Black alpha before color type reductions
2022-12-07 13:22:13 -05:00
Josh Holmer
06e3feeee1 Use separate file for issue_182 test
Closes #412
2021-07-11 23:10:57 -04:00
Felix Hanau
56b94542a6 Fix decoding interlaced images with height or width <= 2 (#175) 2019-06-27 13:44:34 -04:00
Josh Holmer
c60bd82da7 Add test case for #171 2019-06-20 14:07:47 -04:00
Josh Holmer
7bd7c0cfc9 Bump image crate to handle large images
Closes #167 and #168
2019-03-26 14:14:01 -04:00
Kornel
9af874d21b Make reductions return a new uncompressed image (#158)
* Fix verbose message

* No cloning when restoring original data

* Make reductions return a new uncompressed image

Partially fixes #145

* Async reduction evaluator

* Assert

* Faster bit depth check

* Also try 4-bit depth for small-depth images

* Skip test when using miniz

* Ensure palette is trimmed after depth reduction

Fixes #159

* Fudge factor for reductions to prefer better reductions even if gzip estimation says otherwise
2019-01-27 03:22:49 -05:00
Josh Holmer
7594ec632b Add test file 2018-12-01 22:32:29 -05:00
Joshua Holmer
041c433ccb Handle non-standard sBIT headers
Closes #141
2018-11-26 13:10:21 -05:00
Kornel
96eda85806 Identify and drop useless sRGB profiles (#143) 2018-11-13 14:37:02 -05:00
Joshua Holmer
87e738dda2 Fix incorrect detection of images that can reduce bit depth
Closes #140
2018-10-11 08:29:48 -04:00
Josh Holmer
bb1737928e Fix RGB to Indexed reduction if transparency pixel exists
Closes #129
2018-08-11 23:33:55 -04:00
Josh Holmer
71d0f6fa31 Fix more issues with alpha optim on interlaced images
Closes #133
2018-08-11 20:27:45 -04:00
Josh Holmer
7303b94afc Fix issue with alpha optim on interlaced images
Closes #113
2018-07-27 23:03:36 -04:00
Josh Holmer
4d81e23542 Fix the benchmarking script to not overwrite the test file 2018-01-19 18:29:41 -05:00
Josh Holmer
9de0eeaf51 Compare performance of oxipng vs optipng
This adds a script to automate this process and add it to the README.
I'll just run it manually after a version release, for now.

Closes #81
2018-01-18 13:58:05 -05:00
Josh Holmer
f8c62de6c0 Fix unfiltering of first scan line in each pass of an interlaced input file
Closes #92
2017-12-23 00:36:41 -05:00
Josh Holmer
4d62f9f7f9 Fix failure to optimize on certain grayscale images
Closes #89
2017-11-21 12:38:33 -05:00
Emiel Beinema
b417e2bde7 Return an error when an APNG header is encountered 2017-09-30 23:50:52 +02:00
Josh Holmer
e17f911334 Fix a bug in palette reduction at less than 8 bits per pixel
Closes #82
2017-09-11 18:27:28 -04:00
Josh Holmer
e3a26b77a4 Fix a bug in reducing palettes with a bit depth of two
Closes #80
2017-09-10 23:26:39 -04:00
Josh Holmer
f41ef551d3 Enable option for multiple alpha transformations 2017-07-26 00:37:55 -04:00
Josh Holmer
413f1aac7c Automatically change transparent pixels to black 2017-07-24 08:47:27 -04:00
Josh Holmer
d18850ebab Ignore color reductions that would increase file size
Closes #61
2017-03-08 10:11:13 -05:00
Josh Holmer
6c8e7d253d Verify images are correct before outputting them, and fix a bug in certain images
Closes #60
2017-03-06 20:16:28 -05:00
Josh Holmer
c79ba3ab8a Version 0.14.4 2017-02-26 22:53:23 -05:00
Josh Holmer
87810829ce Fix issues in transparency palette reduction and release version 0.14.3 2017-02-25 23:33:55 -05:00
Josh Holmer
44818a854b Fix two bugs in reducing palette and release version 0.14.2 2017-02-22 15:45:46 -05:00
Josh Holmer
2810316f4e Reduce certain headers when reducing color type
Fixes #52
2016-12-12 09:57:18 -05:00
Josh Holmer
6d49d7b8f9 Implement zopfli compression, available as a CLI flag (-Z)
Improves compression by about 10% over DEFLATE, but takes a very long
time at the moment, so it is off by default.
2016-12-01 12:51:30 -05:00
Joshua Holmer
2659776bd5 Fix issue for interlacing images smaller than 4px
Fixes #42
2016-05-25 23:10:44 -04:00
Joshua Holmer
ecc19ad5cd Fix bug where interlaced images with certain widths would fail to optimize 2016-05-13 22:11:45 -04:00
Toby Lawrence
2573b20966 Add support for optimizing PNGs loaded in-memory.
In keeping with being able to use oxipng as a library, this adds a way
for developers to optimize a PNG already in memory, instead of requiring
  it to exist on disk first.
2016-05-05 07:54:52 -04:00