Compare commits

..

15 Commits

Author SHA1 Message Date
kageru 1c062e6dd0
Add LICENSE file
Thanks tdeo for pointing this out
2021-05-29 07:55:38 +02:00
kageru 146743d2c7
Use fixed array for lut generation
The old version that was generated at runtime didn’t actually contain
1.0 as a value, so getting full white output for int input was impossible.
2020-09-11 15:51:41 +02:00
kageru 0499d6e166
Add an explanation for the two dlls to the readme 2020-06-24 21:17:39 +02:00
kageru 40604b2692
update build script 2020-06-22 13:52:30 +02:00
kageru 79596bc4bd
Clamp input values for float if necessary 2020-06-22 13:01:18 +02:00
kageru 9fa8270564
Update release build script
Default binaries are now compiled for haswell or higher
because using FMA instructions results in a noticeable performance gain.
2020-05-26 18:18:21 +02:00
kageru 1f3957f449
Update dependencies 2020-05-26 18:12:58 +02:00
kageru 8ef0654595
No longer use LUT for 32bit input
That means you’ll finally get full 32bit precision, not just 8bit.
This comes at a cost (~20% lower FPS), but it’s a lot more accurate,
and there’s potentially room for optimization in the future because we
actually do math now instead of just hacky lookups in a 256-element
vector.
2020-05-26 18:12:39 +02:00
kageru d762821b88
Add benchmarks 2020-05-24 20:46:23 +02:00
kageru d9b960c6c1
Remove unneeded test import
Now this builds on stable again. I’ll put future benchmarks under
benches/ to be sure.
2020-05-17 00:22:53 +02:00
kageru 9d6482204d
Fix test 2020-05-15 20:28:50 +02:00
kageru 4831298a9b
Optimize LUT generation
Directly calling f32::mul_add is actually more accurate and faster here
because rustc seems to be unable to rearrange the original instructions
in a way that can utilize `fma`.
When directly comparing the two implementations, mul_add was about 10%
faster on my machine (Ryzen 1700 with native target in rustflags).
Relevant Godbolt: https://godbolt.org/z/DDRZ4-
2020-05-13 23:26:23 +02:00
kageru 7b2a14deaf
add script to build release binaries 2020-04-13 13:10:23 +02:00
kageru 8529163d68
No longer error on out of range float input 2020-04-13 13:09:00 +02:00
kageru cde9f6656b
Update dependencies 2020-04-03 22:28:47 +02:00
8 changed files with 769 additions and 99 deletions

597
Cargo.lock generated
View File

@ -2,34 +2,51 @@
# It is not intended for manual editing.
[[package]]
name = "adaptivegrain-rs"
version = "0.2.0"
version = "0.3.0"
dependencies = [
"criterion",
"failure",
"lazy_static",
"vapoursynth",
"vapoursynth-sys",
]
[[package]]
name = "backtrace"
version = "0.3.44"
name = "addr2line"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4036b9bf40f3cf16aba72a3d65e8a520fc4bafcdc7079aea8f848c58c5b5536"
checksum = "a49806b9dadc843c61e7c97e72490ad7f7220ae249012fbda9ad0609457c0543"
dependencies = [
"backtrace-sys",
"cfg-if",
"libc",
"rustc-demangle",
"gimli",
]
[[package]]
name = "backtrace-sys"
version = "0.1.32"
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"cc",
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
[[package]]
name = "backtrace"
version = "0.3.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0df2f85c8a2abbe3b7d7e748052fdd9b76a0458fdeb16ad4223f5eca78c7c130"
dependencies = [
"addr2line",
"cfg-if",
"libc",
"object",
"rustc-demangle",
]
[[package]]
@ -39,10 +56,37 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "cc"
version = "1.0.50"
name = "bstr"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd"
checksum = "31accafdb70df7871592c058eca3985b71104e15ac32f64706022c58867da931"
dependencies = [
"lazy_static",
"memchr",
"regex-automata",
"serde",
]
[[package]]
name = "bumpalo"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5356f1d23ee24a1f785a56d1d1a5f0fd5b0f6a0c0fb2412ce11da71649ab78f6"
[[package]]
name = "byteorder"
version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
[[package]]
name = "cast"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0"
dependencies = [
"rustc_version",
]
[[package]]
name = "cfg-if"
@ -51,10 +95,131 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "failure"
version = "0.1.6"
name = "clap"
version = "2.33.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9"
checksum = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129"
dependencies = [
"bitflags",
"textwrap",
"unicode-width",
]
[[package]]
name = "criterion"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63f696897c88b57f4ffe3c69d8e1a0613c7d0e6c4833363c8560fbde9c47b966"
dependencies = [
"atty",
"cast",
"clap",
"criterion-plot",
"csv",
"itertools",
"lazy_static",
"num-traits",
"oorandom",
"plotters",
"rayon",
"regex",
"serde",
"serde_derive",
"serde_json",
"tinytemplate",
"walkdir",
]
[[package]]
name = "criterion-plot"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddeaf7989f00f2e1d871a26a110f3ed713632feac17f65f03ca938c542618b60"
dependencies = [
"cast",
"itertools",
]
[[package]]
name = "crossbeam-deque"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
"maybe-uninit",
]
[[package]]
name = "crossbeam-epoch"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace"
dependencies = [
"autocfg",
"cfg-if",
"crossbeam-utils",
"lazy_static",
"maybe-uninit",
"memoffset",
"scopeguard",
]
[[package]]
name = "crossbeam-queue"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c695eeca1e7173472a32221542ae469b3e9aac3a4fc81f7696bcad82029493db"
dependencies = [
"cfg-if",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
dependencies = [
"autocfg",
"cfg-if",
"lazy_static",
]
[[package]]
name = "csv"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00affe7f6ab566df61b4be3ce8cf16bc2576bca0963ceb0955e45d514bf9a279"
dependencies = [
"bstr",
"csv-core",
"itoa",
"ryu",
"serde",
]
[[package]]
name = "csv-core"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90"
dependencies = [
"memchr",
]
[[package]]
name = "either"
version = "1.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
[[package]]
name = "failure"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86"
dependencies = [
"backtrace",
"failure_derive",
@ -62,9 +227,9 @@ dependencies = [
[[package]]
name = "failure_derive"
version = "0.1.6"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08"
checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4"
dependencies = [
"proc-macro2",
"quote",
@ -72,6 +237,45 @@ dependencies = [
"synstructure",
]
[[package]]
name = "gimli"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcc8e0c9bce37868955864dbecd2b1ab2bdf967e6f28066d65aaac620444b65c"
[[package]]
name = "hermit-abi"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91780f809e750b0a89f5544be56617ff6b1227ee485bcb06ebe10cdf89bd3b71"
dependencies = [
"libc",
]
[[package]]
name = "itertools"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b"
dependencies = [
"either",
]
[[package]]
name = "itoa"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e"
[[package]]
name = "js-sys"
version = "0.3.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa5a448de267e7358beaf4a5d849518fe9a0c13fce7afd44b06e68550e5562a7"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
@ -80,28 +284,149 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.67"
version = "0.2.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018"
checksum = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f"
[[package]]
name = "log"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
dependencies = [
"cfg-if",
]
[[package]]
name = "maybe-uninit"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
[[package]]
name = "memchr"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
[[package]]
name = "memoffset"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4fc2c02a7e374099d4ee95a193111f72d2110197fe200272371758f6c3643d8"
dependencies = [
"autocfg",
]
[[package]]
name = "num-traits"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096"
dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
dependencies = [
"hermit-abi",
"libc",
]
[[package]]
name = "object"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cbca9424c482ee628fa549d9c812e2cd22f1180b9222c9200fdfa6eb31aecb2"
[[package]]
name = "oorandom"
version = "11.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94af325bc33c7f60191be4e2c984d48aaa21e2854f473b85398344b60c9b6358"
[[package]]
name = "plotters"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9b1d9ca091d370ea3a78d5619145d1b59426ab0c9eedbad2514a4cee08bf389"
dependencies = [
"js-sys",
"num-traits",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "proc-macro2"
version = "1.0.9"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435"
checksum = "1502d12e458c49a4c9cbff560d0fe0060c252bc29799ed94ca2ed4bb665a0101"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.2"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
checksum = "54a21852a652ad6f610c9510194f398ff6f8692e334fd1145fed931f7fbe44ea"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rayon"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db6ce3297f9c85e16621bb8cca38a06779ffc31bb8184e1be4bed2be4678a098"
dependencies = [
"crossbeam-deque",
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08a89b46efaf957e52b18062fb2f4660f8b8a4dde1807ca002690868ef2c85a9"
dependencies = [
"crossbeam-deque",
"crossbeam-queue",
"crossbeam-utils",
"lazy_static",
"num_cpus",
]
[[package]]
name = "regex"
version = "1.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692"
dependencies = [
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4"
dependencies = [
"byteorder",
]
[[package]]
name = "regex-syntax"
version = "0.6.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae"
[[package]]
name = "rustc-demangle"
version = "0.1.16"
@ -109,10 +434,83 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
[[package]]
name = "syn"
version = "1.0.16"
name = "rustc_version"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "123bd9499cfb380418d509322d7a6d52e5315f064fe4b3ad18a53d6b92c07859"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver",
]
[[package]]
name = "ryu"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed3d612bc64430efeb3f7ee6ef26d590dce0c43249217bddc62112540c7941e1"
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "1.0.110"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99e7b308464d16b56eba9964e4972a3eee817760ab60d88c3f86e1fecb08204c"
[[package]]
name = "serde_derive"
version = "1.0.110"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "818fbf6bfa9a42d3bfcaca148547aa00c7b915bec71d1757aa2d44ca68771984"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "993948e75b189211a9b31a7528f950c6adc21f9720b6438ff80a7fa2f864cea2"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "syn"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95b5f192649e48a5302a13f2feb224df883b98933222369e4b3b0fe2a5447269"
dependencies = [
"proc-macro2",
"quote",
@ -131,6 +529,31 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "textwrap"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
dependencies = [
"unicode-width",
]
[[package]]
name = "tinytemplate"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45e4bc5ac99433e0dcb8b9f309dd271a165ae37dde129b9e0ce1bfdd8bfe4891"
dependencies = [
"serde",
"serde_json",
]
[[package]]
name = "unicode-width"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479"
[[package]]
name = "unicode-xid"
version = "0.2.0"
@ -139,9 +562,9 @@ checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
[[package]]
name = "vapoursynth"
version = "0.2.0"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5f4c52d0d5b9a26d1832eb7844addb260690346df865a623e6eed5c43966527"
checksum = "e378bb0210b411e41b16083e2cf274d3fcb3c92071dbcc332cbac713ab6c33a0"
dependencies = [
"bitflags",
"failure",
@ -152,9 +575,115 @@ dependencies = [
[[package]]
name = "vapoursynth-sys"
version = "0.2.2"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "227c62a7b77206c27238593c3106bb5b932a873fbf93cc167d7cae03cd9aa039"
checksum = "c5ad7879f2893d1574b128d26e65aedf38c3c01ac3af1c7d09cc6bc4c5148b87"
dependencies = [
"cfg-if",
]
[[package]]
name = "walkdir"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d"
dependencies = [
"same-file",
"winapi",
"winapi-util",
]
[[package]]
name = "wasm-bindgen"
version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3c7d40d09cdbf0f4895ae58cf57d92e1e57a9dd8ed2e8390514b54a47cc5551"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3972e137ebf830900db522d6c8fd74d1900dcfc733462e9a12e942b00b4ac94"
dependencies = [
"bumpalo",
"lazy_static",
"log",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cd85aa2c579e8892442954685f0d801f9129de24fa2136b2c6a539c76b65776"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eb197bd3a47553334907ffd2f16507b4f4f01bbec3ac921a7719e0decdfe72a"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a91c2916119c17a8e316507afaaa2dd94b47646048014bbdf6bef098c1bb58ad"
[[package]]
name = "web-sys"
version = "0.3.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bc359e5dd3b46cb9687a051d50a2fdd228e4ba7cf6fcf861a5365c3d671a642"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "winapi"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View File

@ -1,15 +1,20 @@
[package]
name = "adaptivegrain-rs"
version = "0.2.1"
version = "0.3.0"
authors = ["kageru"]
edition = "2018"
[dependencies]
failure = "0.1"
lazy_static = "1.3.0"
vapoursynth = "0.2"
vapoursynth-sys = "0.2"
failure = "0.1.8"
vapoursynth = "0.3.0"
vapoursynth-sys = "0.3.0"
[lib]
crate-type = ["cdylib"]
crate-type = ["cdylib", "rlib"]
[dev-dependencies]
criterion = "0.3"
[[bench]]
name = "mask"
harness = false

8
LICENSE Normal file
View File

@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright © 2021 kageru
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -45,15 +45,25 @@ No idea what the minimum version is,
Binaries for Windows and Linux are in the release tab.
## FAQ
**What’s the no-fma dll? Which one do I need?**
There are two Windows builds of the plugin, one for CPUs that support
[FMA instructions](https://en.wikipedia.org/wiki/FMA_instruction_set) and one for those that don’t.
If your CPU is a Haswell (for Intel) or Piledriver (for AMD) or newer,
you can use the regular version (which is about 20% faster).
Otherwise, grab no-fma.
The Linux build uses fma instructions.
I trust that if you’re a Linux user on older hardware,
you know how to compile your own binaries.
**Why do I have to call std.PlaneStats() manually?**
~~Because I didn’t want to reimplement it. `kagefunc.adaptive_grain(clip, show_mask=True)` does that for you and then just returns the mask.~~
Because I was too dumb to realize [this](http://www.vapoursynth.com/doc/api/vapoursynth.h.html#invoke) exists.
I’ll fix that at some point.
I’ll fix that at some point.
**Why doesn’t this also add grain?**
I was going to do that originally,
but it just goes back to the same point
about not wanting to reimplement
something that already exists.
but I didn’t want to reimplement grain
when we already have a working grain filter.

17
benches/mask.rs Normal file
View File

@ -0,0 +1,17 @@
use adaptivegrain_rs::mask::*;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
fn mask_value(c: &mut Criterion) {
black_box(FLOAT_RANGE.iter().count());
let ls = black_box(calc_luma_scaling(0.412323, 10.0));
c.bench_function("mask value y=0.412", |b| {
b.iter(|| {
FLOAT_RANGE.iter().for_each(|&x| {
black_box(get_mask_value(black_box(x), ls));
});
})
});
}
criterion_group!(mask, mask_value);
criterion_main!(mask);

14
build_release.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/sh
# Set rustflags without target-cpu to build for legacy hosts.
# I only build this for windows because Linux users on old machines can just compile their own binary
# --emit=asm forces rustc to compile the crate with only one thread, which can help the optimizer (1-2% faster on my machine)
RUSTFLAGS="--emit asm" cargo build --release --target=x86_64-pc-windows-gnu --locked
mv target/x86_64-pc-windows-gnu/release/adaptivegrain_rs.dll ./adaptivegrain_rs-no-fma.dll
RUSTFLAGS="-C target-cpu=haswell --emit asm" cargo build --release --locked
RUSTFLAGS="-C target-cpu=haswell --emit asm" cargo build --release --target=x86_64-pc-windows-gnu --locked
mv target/x86_64-pc-windows-gnu/release/adaptivegrain_rs.dll ./
mv target/release/libadaptivegrain_rs.so ./
strip libadaptivegrain_rs.so
strip adaptivegrain_rs.dll
strip adaptivegrain_rs-no-fma.dll

View File

@ -1,11 +1,9 @@
#[macro_use]
extern crate failure;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate vapoursynth;
mod mask;
pub mod mask;
use self::mask::Mask;
use failure::Error;

View File

@ -12,22 +12,24 @@ pub struct Mask<'core> {
pub luma_scaling: f32,
}
lazy_static! {
static ref FLOAT_RANGE: Vec<f32> = {
[0f32; 256]
.iter()
.enumerate()
.map(|(i, _f)| (i as f32) / 256.0)
.collect()
};
#[rustfmt::skip]
static FLOAT_RANGE: [f32; 256] = [0.0, 0.003921569, 0.007843138, 0.011764706, 0.015686275, 0.019607844, 0.023529412, 0.02745098, 0.03137255, 0.03529412, 0.039215688, 0.043137256, 0.047058824, 0.050980393, 0.05490196, 0.05882353, 0.0627451, 0.06666667, 0.07058824, 0.07450981, 0.078431375, 0.08235294, 0.08627451, 0.09019608, 0.09411765, 0.09803922, 0.101960786, 0.105882354, 0.10980392, 0.11372549, 0.11764706, 0.12156863, 0.1254902, 0.12941177, 0.13333334, 0.13725491, 0.14117648, 0.14509805, 0.14901961, 0.15294118, 0.15686275, 0.16078432, 0.16470589, 0.16862746, 0.17254902, 0.1764706, 0.18039216, 0.18431373, 0.1882353, 0.19215687, 0.19607843, 0.2, 0.20392157, 0.20784314, 0.21176471, 0.21568628, 0.21960784, 0.22352941, 0.22745098, 0.23137255, 0.23529412, 0.23921569, 0.24313726, 0.24705882, 0.2509804, 0.25490198, 0.25882354, 0.2627451, 0.26666668, 0.27058825, 0.27450982, 0.2784314, 0.28235295, 0.28627452, 0.2901961, 0.29411766, 0.29803923, 0.3019608, 0.30588236, 0.30980393, 0.3137255, 0.31764707, 0.32156864, 0.3254902, 0.32941177, 0.33333334, 0.3372549, 0.34117648, 0.34509805, 0.34901962, 0.3529412, 0.35686275, 0.36078432, 0.3647059, 0.36862746, 0.37254903, 0.3764706, 0.38039216, 0.38431373, 0.3882353, 0.39215687, 0.39607844, 0.4, 0.40392157, 0.40784314, 0.4117647, 0.41568628, 0.41960785, 0.42352942, 0.42745098, 0.43137255, 0.43529412, 0.4392157, 0.44313726, 0.44705883, 0.4509804, 0.45490196, 0.45882353, 0.4627451, 0.46666667, 0.47058824, 0.4745098, 0.47843137, 0.48235294, 0.4862745, 0.49019608, 0.49411765, 0.49803922, 0.5019608, 0.5058824, 0.50980395, 0.5137255, 0.5176471, 0.52156866, 0.5254902, 0.5294118, 0.53333336, 0.5372549, 0.5411765, 0.54509807, 0.54901963, 0.5529412, 0.5568628, 0.56078434, 0.5647059, 0.5686275, 0.57254905, 0.5764706, 0.5803922, 0.58431375, 0.5882353, 0.5921569, 0.59607846, 0.6, 0.6039216, 0.60784316, 0.6117647, 0.6156863, 0.61960787, 0.62352943, 0.627451, 0.6313726, 0.63529414, 0.6392157, 0.6431373, 0.64705884, 0.6509804, 0.654902, 0.65882355, 0.6627451, 0.6666667, 0.67058825, 0.6745098, 0.6784314, 0.68235296, 0.6862745, 0.6901961, 0.69411767, 0.69803923, 0.7019608, 0.7058824, 0.70980394, 0.7137255, 0.7176471, 0.72156864, 0.7254902, 0.7294118, 0.73333335, 0.7372549, 0.7411765, 0.74509805, 0.7490196, 0.7529412, 0.75686276, 0.7607843, 0.7647059, 0.76862746, 0.77254903, 0.7764706, 0.78039217, 0.78431374, 0.7882353, 0.7921569, 0.79607844, 0.8, 0.8039216, 0.80784315, 0.8117647, 0.8156863, 0.81960785, 0.8235294, 0.827451, 0.83137256, 0.8352941, 0.8392157, 0.84313726, 0.84705883, 0.8509804, 0.85490197, 0.85882354, 0.8627451, 0.8666667, 0.87058824, 0.8745098, 0.8784314, 0.88235295, 0.8862745, 0.8901961, 0.89411765, 0.8980392, 0.9019608, 0.90588236, 0.9098039, 0.9137255, 0.91764706, 0.92156863, 0.9254902, 0.92941177, 0.93333334, 0.9372549, 0.9411765, 0.94509804, 0.9490196, 0.9529412, 0.95686275, 0.9607843, 0.9647059, 0.96862745, 0.972549, 0.9764706, 0.98039216, 0.9843137, 0.9882353, 0.99215686, 0.99607843, 1.0];
#[inline]
pub fn get_mask_value(x: f32, luma_scaling: f32) -> f32 {
f32::powf(
1.0 - (x
* (x.mul_add(
x.mul_add(x.mul_add(x.mul_add(18.188, -45.47), 36.624), -9.466),
1.124,
))),
luma_scaling,
)
}
#[inline]
fn get_mask_value(x: f32, y: f32, luma_scaling: f32) -> f32 {
f32::powf(
1.0 - (x * (1.124 + x * (-9.466 + x * (36.624 + x * (-45.47 + x * 18.188))))),
(y * y) * luma_scaling,
)
pub fn get_mask_value_clamping(x: f32, luma_scaling: f32) -> f32 {
get_mask_value(x.min(1.0).max(0.0), luma_scaling)
}
macro_rules! from_property {
@ -41,17 +43,11 @@ macro_rules! from_property {
macro_rules! int_filter {
($type:ty, $fname:ident) => {
fn $fname(
frame: &mut FrameRefMut,
src_frame: FrameRef,
depth: u8,
average: f32,
luma_scaling: f32,
) {
fn $fname(frame: &mut FrameRefMut, src_frame: FrameRef, depth: u8, luma_scaling: f32) {
let max = ((1 << depth) - 1) as f32;
let lut: Vec<$type> = FLOAT_RANGE
.iter()
.map(|x| (get_mask_value(*x, average, luma_scaling) * max) as $type)
.map(|x| (get_mask_value(*x, luma_scaling) * max) as $type)
.collect();
for row in 0..frame.height(0) {
for (pixel, src_pixel) in frame
@ -59,7 +55,7 @@ macro_rules! int_filter {
.iter_mut()
.zip(src_frame.plane_row::<$type>(0, row))
{
let i = (src_pixel.clone() >> (depth - 8)) as usize;
let i = (src_pixel >> (depth - 8)) as usize;
unsafe {
ptr::write(pixel, lut[i].clone());
}
@ -69,21 +65,27 @@ macro_rules! int_filter {
};
}
fn filter_for_float(frame: &mut FrameRefMut, src_frame: FrameRef, average: f32, luma_scaling: f32) {
let lut: Vec<f32> = FLOAT_RANGE
.iter()
.map(|x| get_mask_value(*x, average, luma_scaling))
.collect();
fn filter_for_float(frame: &mut FrameRefMut, src_frame: FrameRef, luma_scaling: f32) {
for row in 0..frame.height(0) {
for (pixel, src_pixel) in frame
frame
.plane_row_mut::<f32>(0, row)
.iter_mut()
.zip(src_frame.plane_row::<f32>(0, row).iter())
{
unsafe {
ptr::write(pixel, lut[(src_pixel * 255.99f32) as usize]);
}
}
.zip(src_frame.plane_row::<f32>(0, row))
.for_each(|(pixel, src_pixel)| unsafe {
ptr::write(pixel, get_mask_value(*src_pixel, luma_scaling));
});
}
}
fn filter_for_float_clamping(frame: &mut FrameRefMut, src_frame: FrameRef, luma_scaling: f32) {
for row in 0..frame.height(0) {
frame
.plane_row_mut::<f32>(0, row)
.iter_mut()
.zip(src_frame.plane_row::<f32>(0, row))
.for_each(|(pixel, src_pixel)| unsafe {
ptr::write(pixel, get_mask_value_clamping(*src_pixel, luma_scaling));
});
}
}
@ -143,7 +145,8 @@ impl<'core> Filter<'core> for Mask<'core> {
let src_frame = self.source.get_frame_filter(context, n).ok_or_else(|| {
format_err!("Could not retrieve source frame. This shouldn’t happen.")
})?;
let average = match src_frame.props().get::<f64>("PlaneStatsAverage") {
let props = src_frame.props();
let average = match props.get::<f64>("PlaneStatsAverage") {
Ok(average) => average as f32,
Err(_) => bail!(format!(
"{}: you need to run std.PlaneStats on the clip before calling this function.",
@ -157,15 +160,30 @@ impl<'core> Filter<'core> for Mask<'core> {
match depth {
0..=8 => {
int_filter!(u8, filter_8bit);
filter_8bit(&mut frame, src_frame, depth, average, self.luma_scaling)
filter_8bit(
&mut frame,
src_frame,
depth,
calc_luma_scaling(average, self.luma_scaling),
)
}
9..=16 => {
int_filter!(u16, filter_16bit);
filter_16bit(&mut frame, src_frame, depth, average, self.luma_scaling)
filter_16bit(
&mut frame,
src_frame,
depth,
calc_luma_scaling(average, self.luma_scaling),
)
}
17..=32 => {
int_filter!(u32, filter_32bit);
filter_32bit(&mut frame, src_frame, depth, average, self.luma_scaling)
filter_32bit(
&mut frame,
src_frame,
depth,
calc_luma_scaling(average, self.luma_scaling),
)
}
_ => bail!(format!(
"{}: input depth {} not supported",
@ -174,25 +192,96 @@ impl<'core> Filter<'core> for Mask<'core> {
}
}
SampleType::Float => {
if let Err(e) = verify_input_range(&src_frame.props()) {
bail!(e);
// If the input has pixel values outside of the valid range (0-1),
// those might also be out of range in the output.
// We use the min/max props to determine if output clamping is necessary.
let max = props
.get::<f64>("PlaneStatsMax")
.expect(&format!("{}: no PlaneStatsMax in frame props", PLUGIN_NAME));
let min = props
.get::<f64>("PlaneStatsMin")
.expect(&format!("{}: no PlaneStatsMin in frame props", PLUGIN_NAME));
if max > 1.0 || min < 0.0 {
filter_for_float_clamping(
&mut frame,
src_frame,
calc_luma_scaling(average, self.luma_scaling),
);
} else {
filter_for_float(
&mut frame,
src_frame,
calc_luma_scaling(average, self.luma_scaling),
);
}
filter_for_float(&mut frame, src_frame, average, self.luma_scaling);
}
}
Ok(frame.into())
}
}
fn verify_input_range<'a>(props: &vapoursynth::map::MapRef<'a, 'a>) -> Result<(), String> {
let max = props.get::<f64>("PlaneStatsMax").unwrap_or(1.0);
let min = props.get::<f64>("PlaneStatsMin").unwrap_or(0.0);
if min < 0.0 || max > 1.0 {
return Err(format!(
"{}: found invalid input. Some pixels are outside of the valid range.
You probably used a filter that operates on limited range without clipping properly, e.g. edgefixer, before converting to float.
This can be fixed by clipping all pixels to (0, 1) with Expr or converting to an integer format.", PLUGIN_NAME
));
}
Ok(())
pub fn calc_luma_scaling(average: f32, luma_scaling: f32) -> f32 {
let average = average.min(1.0).max(0.0);
average * average * luma_scaling
}
#[cfg(test)]
mod tests {
use super::*;
// Just in case this isn’t the last time I rewrite the lut builder:
#[rustfmt::skip]
static EXPECTED_MASK_02: [f32; 256] = [1.0, 0.998292, 0.99669147, 0.99519384, 0.9937948, 0.99249005, 0.99127513, 0.99014574, 0.98909765, 0.98812664, 0.9872284, 0.9863988, 0.98563385, 0.9849295, 0.9842816, 0.98368645, 0.9831401, 0.9826388, 0.9821788, 0.9817565, 0.98136836, 0.98101085, 0.98068064, 0.98037434, 0.9800887, 0.97982067, 0.979567, 0.97932476, 0.9790909, 0.9788629, 0.97863764, 0.97841257, 0.97818506, 0.9779526, 0.9777127, 0.977463, 0.97720116, 0.97692496, 0.97663224, 0.97632086, 0.97598886, 0.9756343, 0.9752552, 0.97484976, 0.97441626, 0.973953, 0.9734583, 0.97293067, 0.9723685, 0.97177035, 0.9711349, 0.9704607, 0.96974653, 0.96899116, 0.9681933, 0.9673519, 0.9664658, 0.965534, 0.9645555, 0.9635293, 0.96245456, 0.9613303, 0.96015584, 0.9589302, 0.9576528, 0.9563228, 0.95493966, 0.9535026, 0.9520111, 0.95046455, 0.9488624, 0.9472042, 0.94548935, 0.94371754, 0.9418882, 0.94000113, 0.9380558, 0.936052, 0.93398947, 0.9318677, 0.9296866, 0.9274459, 0.9251454, 0.92278486, 0.92036426, 0.91788334, 0.91534203, 0.91274023, 0.9100778, 0.9073548, 0.9045712, 0.9017268, 0.89882183, 0.8958562, 0.89282995, 0.8897432, 0.886596, 0.8833886, 0.88012075, 0.876793, 0.8734053, 0.8699578, 0.8664507, 0.8628842, 0.85925865, 0.8555742, 0.85183114, 0.8480296, 0.84417003, 0.8402527, 0.836278, 0.8322462, 0.82815754, 0.8240127, 0.81981164, 0.8155552, 0.8112436, 0.8068773, 0.8024568, 0.79798263, 0.7934552, 0.788875, 0.78424263, 0.77955866, 0.77482367, 0.7700382, 0.76520306, 0.7603186, 0.7553858, 0.750405, 0.74537706, 0.7403031, 0.73518324, 0.73001873, 0.72480994, 0.7195582, 0.714264, 0.7089286, 0.70355237, 0.6981368, 0.6926824, 0.6871906, 0.68166244, 0.6760984, 0.67050064, 0.66486925, 0.65920633, 0.6535124, 0.64778924, 0.6420377, 0.63625985, 0.6304561, 0.62462854, 0.6187791, 0.61290854, 0.60701925, 0.60111195, 0.5951895, 0.58925253, 0.5833042, 0.57734525, 0.5713786, 0.5654054, 0.55942863, 0.5534506, 0.5474728, 0.54149866, 0.5355294, 0.5295689, 0.52361876, 0.51768285, 0.5117627, 0.50586176, 0.49998415, 0.49413142, 0.48830834, 0.48251665, 0.47676167, 0.4710447, 0.4653721, 0.45974478, 0.45416957, 0.44864753, 0.44318435, 0.43778518, 0.4324514, 0.4271907, 0.42200384, 0.4168986, 0.41187632, 0.40694392, 0.4021045, 0.39736322, 0.39272374, 0.38819104, 0.38376838, 0.37945992, 0.3752701, 0.37120032, 0.36725762, 0.36344275, 0.35975853, 0.3562081, 0.35279226, 0.34951332, 0.3463715, 0.3433669, 0.34050032, 0.33777085, 0.3351737, 0.3327109, 0.33037695, 0.32816976, 0.32608336, 0.32411364, 0.32225302, 0.32049632, 0.31883442, 0.31725863, 0.31575835, 0.31432915, 0.31295443, 0.31162542, 0.31032994, 0.30905154, 0.30778122, 0.30649903, 0.30519295, 0.3038461, 0.30243647, 0.3009518, 0.29937094, 0.29767165, 0.29583326, 0.2938297, 0.29163584, 0.28922495, 0.28656486, 0.28362364, 0.28036165, 0.27673277, 0.2726987, 0.26819843, 0.2631695, 0.25753176, 0.25119466, 0.24403761, 0.23592123, 0.2266435, 0.2159501, 0.20344463, 0.18856688, 0.17031908, 0.1467575, 0.11270576, 0.00323677];
#[rustfmt::skip]
static EXPECTED_MASK_08: [f32; 256] = [1.0, 0.97301966, 0.9483565, 0.92581207, 0.9052065, 0.8863773, 0.86917543, 0.8534658, 0.8391256, 0.82604086, 0.81410825, 0.80323166, 0.79332286, 0.78429985, 0.7760863, 0.7686117, 0.7618097, 0.7556182, 0.7499784, 0.7448358, 0.74013805, 0.735836, 0.7318828, 0.7282341, 0.724847, 0.7216812, 0.7186976, 0.7158591, 0.7131299, 0.71047634, 0.70786506, 0.705265, 0.7026458, 0.6999789, 0.69723636, 0.69439274, 0.6914226, 0.68830246, 0.6850099, 0.6815241, 0.6778255, 0.6738958, 0.66971844, 0.6652776, 0.6605602, 0.65555304, 0.650246, 0.6446294, 0.6386957, 0.6324387, 0.6258541, 0.6189384, 0.6116908, 0.60411143, 0.59620154, 0.5879653, 0.5794071, 0.5705335, 0.5613522, 0.55187273, 0.5421053, 0.532062, 0.52175605, 0.5112014, 0.5004138, 0.4894094, 0.47820586, 0.46682078, 0.45527333, 0.44358265, 0.43176922, 0.41985318, 0.4078552, 0.39579678, 0.38369834, 0.37158158, 0.35946706, 0.3473761, 0.33532932, 0.3233465, 0.31144762, 0.29965213, 0.28797832, 0.27644426, 0.2650672, 0.2538632, 0.24284792, 0.23203576, 0.22144021, 0.21107364, 0.20094803, 0.19107313, 0.18145862, 0.17211263, 0.1630422, 0.15425344, 0.14575136, 0.13753979, 0.12962131, 0.121998124, 0.11467082, 0.107639365, 0.100902446, 0.09445834, 0.08830449, 0.08243708, 0.076852135, 0.07154449, 0.06650879, 0.061738882, 0.05722833, 0.052969858, 0.048956152, 0.045179587, 0.041631833, 0.03830488, 0.035190117, 0.032279003, 0.029562855, 0.027033038, 0.02468074, 0.022497335, 0.020474205, 0.018602902, 0.016875094, 0.015282571, 0.013817431, 0.012471816, 0.0112383105, 0.0101095475, 0.009078545, 0.008138663, 0.0072833193, 0.006506449, 0.0058021126, 0.0051648114, 0.004589231, 0.004070427, 0.0036036533, 0.0031845558, 0.0028089648, 0.0024730647, 0.0021732512, 0.0019061574, 0.0016687337, 0.0014580758, 0.0012715748, 0.001106781, 0.0009614784, 0.0008336202, 0.00072136015, 0.00062298466, 0.00053696934, 0.00046192406, 0.00039657977, 0.00033981237, 0.00029059322, 0.00024801854, 0.00021126306, 0.00017960659, 0.00015239452, 0.00012905747, 0.0001090837, 0.000092026974, 0.000077492776, 0.00006513292, 0.000054645934, 0.00004576495, 0.00003826129, 0.000031933254, 0.000026608495, 0.000022135933, 0.000018386958, 0.000015251044, 0.000012632214, 0.000010449756, 0.000008633694, 0.000007125597, 0.000005874811, 0.0000048395545, 0.000003983536, 0.0000032770909, 0.0000026945397, 0.0000022148818, 0.0000018204425, 0.0000014962245, 0.000001230123, 0.000001011725, 0.00000083269754, 0.00000068591316, 0.0000005656565, 0.00000046711415, 0.0000003863694, 0.00000032018005, 0.00000026590607, 0.00000022136388, 0.00000018477976, 0.0000001547046, 0.00000012993713, 0.000000109530006, 0.000000092677915, 0.00000007873675, 0.00000006718318, 0.00000005758441, 0.00000004959293, 0.000000042921464, 0.000000037336587, 0.000000032649805, 0.000000028704813, 0.0000000253699, 0.000000022546159, 0.00000002014448, 0.000000018095754, 0.000000016340236, 0.000000014830539, 0.000000013525465, 0.000000012392772, 0.00000001140364, 0.000000010534523, 0.0000000097651105, 0.000000009081434, 0.000000008466379, 0.000000007909084, 0.000000007399097, 0.000000006926191, 0.000000006484458, 0.0000000060654903, 0.000000005664892, 0.000000005277865, 0.00000000489944, 0.0000000045284674, 0.0000000041625015, 0.0000000038001398, 0.0000000034415308, 0.0000000030869618, 0.000000002738131, 0.000000002397576, 0.0000000020680777, 0.0000000017533902, 0.0000000014571282, 0.0000000011829588, 0.0000000009352538, 0.00000000071663736, 0.0000000005293817, 0.00000000037436287, 0.00000000025128466, 0.00000000015823709, 0.000000000092102735, 0.000000000048472164, 0.000000000022369412, 0.000000000008612706, 0.000000000002555328, 0.00000000000050143293, 0.00000000000004630252, 0.0000000000000006778562, 0.000000000000000000000000000000000000000145141];
#[test]
fn test_mask_values() {
FLOAT_RANGE
.iter()
.zip(EXPECTED_MASK_02.iter())
.for_each(|(&x, &exp)| {
let value = get_mask_value(x, calc_luma_scaling(0.2, 10.0));
assert!(
(value - exp).abs() < 0.0001,
"luma scaling 0.2: Mask was wrong at position {}, expected {}, got {}",
x,
exp,
value
);
});
FLOAT_RANGE
.iter()
.zip(EXPECTED_MASK_08.iter())
.for_each(|(&x, &exp)| {
let value = get_mask_value(x, calc_luma_scaling(0.8, 10.0));
assert!(
(value - exp).abs() < 0.0001,
"luma scaling 0.8: Mask was wrong at position {}, expected {}, got {}",
x,
exp,
value
);
});
}
#[test]
fn test_mask_values_clamping() {
FLOAT_RANGE
.iter()
.zip(EXPECTED_MASK_02.iter())
.for_each(|(&x, &exp)| {
assert!(
(get_mask_value_clamping(x, calc_luma_scaling(0.2, 10.0)) - exp).abs() < 0.0001
);
});
assert_eq!(
get_mask_value_clamping(1.1, calc_luma_scaling(0.99, 10.0)),
0.0
);
assert_eq!(
get_mask_value_clamping(-0.1, calc_luma_scaling(-0.1, 10.0)),
1.0
);
}
}