Commit graph

258 commits

Author SHA1 Message Date
Josh Holmer
9b5cd9a1a4 Fix a new clippy lint 2021-01-04 16:12:46 -05:00
Ingvar Stepanyan
e38c759563
Switch to crossbeam-channel + rayon::spawn (#327)
* Switch to crossbeam-channel + rayon::spawn

* Remove thread_spawn for evaluation altogether

This allows to avoid a deadlock when there is only one Rayon thread, and doesn't sacrifice performance, since the caller of .get_result() had to always block on the iterator to be finished anyway, and all the messages are already sent from separate threads.

* Fix `verbose_mode` test

This one is easier to "fix", since we're in control of the rayon pool - just adding one extra thread to the default number to make sure we always can one root "spawn" call without stealing from the actual pool.
2020-11-11 12:01:13 -05:00
Anhil
70f911fa3e
Make libdeflater and zopfli optional (#319)
* Make `libdeflater` and `zopfli` optional
2020-11-01 20:18:15 -05:00
Josh Holmer
b446a8a92e Optimize reading in files 2020-10-22 09:51:25 -04:00
Ingvar Stepanyan
7167a5e44d
Use the new stabilised fetch_min (#328)
A minor simplification using the corresponding new standard library function.

Bumps minimum Rust version to 1.45.0
2020-10-11 18:53:00 -04:00
Josh Holmer
0d9c23f4ce Fix new clippy lints from Rust 1.47 2020-10-09 20:20:52 -04:00
Josh Holmer
90c99e4509 Do not exit on first non-PNG file found in recursion
Closes #170
2020-08-12 10:59:43 -04:00
Josh Holmer
ad054cadb5 Fix new clippy lint 2020-07-20 20:23:04 -04:00
Josh Holmer
ea746da96c Readd the --force flag to the CLI
This was still present in the lib and options parsing,
but was not in the Clap args list for some reason.
2020-07-13 04:36:27 -04:00
Josh Holmer
fa11401eb1 Version 3.0.0 2020-05-06 10:11:47 -04:00
Ingvar Stepanyan
b06e077f8d
Add "max" level alias; various level-related warnings (#224)
* Update --help to exclude -a

* Add a deprecation warning to level 4 constructor

* Initialise logger earlier

* Add warning for level > 3 for non-zlib

It's not obvious immediately that these levels don't have any effect on libdeflater and Zopfli, since they don't iterate over zlib-specific fine-tuned options.

Hence, show warning so that user knows they're getting "downgraded" to level 3.

* Add "max" level alias; more level warnings

* Update --help trial numbers for non-zlib

* Fix incorrect trial numbers
2020-04-22 13:34:59 -04:00
Ingvar Stepanyan
fee76ca44f
Remove doc-hidden recursive option (#225)
As the comment mentions, this is used only in CLI interface, so there's no reason for it not to live directly in CLI code.

Ref: #220.
2020-04-20 08:51:18 -04:00
Ingvar Stepanyan
23ae9c302f
Switch to standard logging library (#218)
This allows to configure or compile away logging in the library from a single place in Rust apps.

For the CLI side, the usage and output remained the same, except it's now colour-coded.

Fixes #217.
2020-04-18 18:33:48 -04:00
Ingvar Stepanyan
3b754bfa09
Use clap conflict argument checks (#219)
Follow-up to #210.

I haven't noticed / forgotten that clap has own mechanism for conflicts between arguments, and it's probably best to use it instead of custom checks.
2020-04-18 12:20:28 -04:00
Ingvar Stepanyan
a497513d89
Move Zlib-specific options under Zlib compressor (#210)
Make it statically obvious that they're not compatible with other compressors.
2020-04-17 10:05:13 -04:00
Ingvar Stepanyan
e8ff6f7526
Remove unused (outdated?) options (#212)
Co-authored-by: Josh Holmer <jholmer.in@gmail.com>
2020-04-17 05:16:18 -04:00
Ingvar Stepanyan
bb332fa6d7
Don't override global rayon pool (#211)
Rayon uses a singleton global pool.

By default it's set to a regular spawn handler with number of logical CPU cores, but it can be overridden by Rust applications to customize number of threads, spawn handlers, exit handlers and other options.

Such customization should be usually done at the app level, because if a single library initialises the global pool, then Rayon will prevent any further overrides and they will error out. This can cause conflicts between libraries or library and user code and make them impossible to use together.

Hence, I've removed the `threads` option from the `Options` struct and instead moved initialisation to the CLI part of the codebase (main.rs).

Users of the library that didn't depend on custom `threads` number can keep using it as before - they'll still get same number of threads as number of logical CPU cores, while users who need fine-tuning, can do that by customizing rayon pool themselves at the top level of the app.

Note: another alternative to keep the option could've been to use `ThreadPoolBuilder::build` + `ThreadPool::install` to use a local pool just within OxiPNG, but that would ignore any customizations made by users in top-level pool and would prevent usage on targets that require custom spawn handlers like WebAssembly. As such, I've decided to avoid it.

Co-authored-by: Josh Holmer <jholmer.in@gmail.com>
2020-04-17 04:49:40 -04:00
Ingvar Stepanyan
4fd9203800 Bring back RefCell
It was accidentally removed as part of #208.
Fixes #214.
2020-04-16 18:31:24 -04:00
Ingvar Stepanyan
9b8361171f Revert "Unbreak no-default-features"
This reverts commit 4ef92089d5.
2020-04-16 18:31:24 -04:00
Josh Holmer
139b2878d0 Fix benchmark compilation
Closes #197
2020-04-15 13:26:28 -04:00
Josh Holmer
53368fcbbf Reexport indexmap structs 2020-04-15 13:26:28 -04:00
Josh Holmer
4ef92089d5 Unbreak no-default-features
In order to avoid problems with mutable references,
the approach is to use the eval sender for non-parallel.
Computations will still be done synchronously
with the fake synchronous rayon module.
2020-04-15 13:26:28 -04:00
Josh Holmer
43735086d1 Migrate to Github Actions
Closes #206
2020-04-15 13:26:28 -04:00
Ingvar Stepanyan
63e36ed43f
Simplify comparer (#208)
* Skip baselines earlier in the evaluator

We know that we'll throw them away anyway, so there is no point in even sending them to Sender and comparing them with others once we used them for the best candidate size.

* Simplify comparison logic
2020-04-14 17:09:52 -04:00
Ingvar Stepanyan
f747269151
Respect deadline in miniz (#200) 2020-03-31 23:31:17 -04:00
Ingvar Stepanyan
878bbedb37
Improve performance consistency (#202)
* Improve performance consistency

Switch from HashMap / HashSet to IndexMap / IndexSet for consistent iteration order of various options and, as a result, more predictable performance.
2020-03-31 21:54:05 -04:00
Ingvar Stepanyan
121558bf5c
Add libdeflater as an option (#203)
libdeflater is a Rust wrapper around
[libdeflate](https://github.com/ebiggers/libdeflate) - an alternative
heavily optimised library for deflate/zlib/gzip compression and
decompression that is intended for situations where upper bounds of the
output are well-known.

In my benchmarks on test files in the repo it has shown to be usually
both slightly faster and providing better compressed output than
cloudflare-zlib, but in some cases showing the opposite, so rather
than swapping defaults, it's currently provided as another option,
similarly to zopfli.

Since it's not strictly better in all cases, I'm not providing median
numbers, but you can check distribution histograms for time and size
differences here (all using `oxipng -o 6 -t 6 -P`):
https://docs.google.com/spreadsheets/d/1WOKgeYZBhLkQvMGAC36snN4azilElzOFhx63RJu0EZY/edit?usp=sharing
2020-03-31 20:24:57 -04:00
Kornel
681089f8c7
Remove the concept of size bias (#199)
Closes #198
2020-03-31 19:28:22 -04:00
Josh Holmer
bded03908f Silence cognitive complexity warnings 2020-03-02 01:45:04 -05:00
Josh Holmer
b9dc9e72bb Update image crate to 0.23 2020-03-02 01:44:53 -05:00
Josh Holmer
0e3c0b922d Enable more clippy lints and fix some clippy issues 2020-01-19 05:22:14 -05:00
Josh Holmer
139d29cc9b Version 2.3.0 2019-10-07 23:34:23 -04:00
Ingvar Stepanyan
659717cb1f Allow usage on wasm32-unknown-unknown target (#194)
* Avoid using time API when we don't need it

This avoids a syscall to the time API when the result is ignored later anyway.

This allows to use the library with default options on wasm32-unknown-unknown, where the unimplemented syscall would panic otherwise.

* eval_send doesn't need to be an Option

We can drop the value manually, thus avoiding unwrap on each access.

* Keep single `use rayon::prelude::*`

If either `rayon` is already imported, then `rayon::prelude::*` should always resolve.

* Extract comparator

* Fully enable non-parallel mode
2019-09-25 13:01:53 -04:00
Kamal Ahmad
68db304a2a Don't apply alpha optimizations unless --alpha is paseed (#187)
Closes #164
2019-09-24 11:33:50 -04:00
Kornel
e473958377 Palette sorting (#193)
* Implement alpha and luminosity palette sorting

* Also sort when reducing to palette

* Bump Rust version

* Color comparison
2019-09-10 18:13:05 -04:00
Kamal Ahmad
68b763bcdd Reduce alloc in filtering/unfiltering by reusing buffers (#191) 2019-09-04 11:09:54 -04:00
Felix Hanau
4adcc5e14a Interlacing fixes (#182)
* Fix decoding interlaced images with height or width <= 2

* Add Issue 175 test case

* Deinterlace tiny images correctly
2019-07-24 09:16:13 -04:00
Daniel Wong
4cb26d462e Allow disabling all alpha optimizations (#181)
Fixes a bug where oxipng would crash if alpha optimizations were all disabled.
2019-07-23 14:21:46 -04:00
Kamal Ahmad
34ee78dbbc Preallocate memory in reduced_alpha_to_up (#180) 2019-06-27 13:44:49 -04:00
Felix Hanau
56b94542a6 Fix decoding interlaced images with height or width <= 2 (#175) 2019-06-27 13:44:34 -04:00
Felix Hanau
c09e8f6d12 Make filter, zlib level and strategy deterministic (#179) 2019-06-27 10:05:35 -04:00
Josh Holmer
458e9f64a7 Fix --strip safe which was broken in 5b1121c9d 2019-06-19 15:27:43 -04:00
Josh Holmer
5b1121c9dd Make order of chunks deterministic by sorting chunks
Closes #174
2019-06-18 13:29:17 -04:00
Felix Hanau
5dcfe44ccd Fix info message and typos (#172) 2019-06-18 13:06:37 -04:00
Felix Hanau
cc290c0bdb Fixes for grey scale reduction (#171) 2019-06-18 13:04:26 -04:00
Josh Holmer
d86bc80f43 Prepare for next release 2019-02-01 17:27:03 -05:00
Kornel
485a127cf6 Remove Mutex from evaluation loop (#163) 2019-02-01 17:03:25 -05:00
Kornel
dad6230cf1 Check timeout more often during compression (#160) 2019-02-01 16:30:47 -05:00
Kornel
33890cf0fd Fake Rayon (#162)
Dummy implementation of Rayon's traits to avoid `#[cfg()]` and duplicated non-parallel code.
2019-01-28 13:35:42 -05:00
Kornel
0d4a9e06d6 Avoid using excessive number of threads (#161) 2019-01-27 04:15:41 -05:00