I realized having to host this potentially indefinitely might not be the best idea, so I am going to shut down this gitea instance eventually.
You’ll have time, at least until the end of 2022, probably longer, but please just get all your stuff somewhere safe in case we ever disappear.
If any of your build scripts rely on my (kageru’s) projects hosted here, check my Github or IEW on Github for encoding projects. If you can’t find what you’re looking there, tell me to migrate it.

Compare commits

...

6 Commits

Author SHA1 Message Date
kageru 1c062e6dd0
Add LICENSE file 1 year ago
kageru 146743d2c7
Use fixed array for lut generation 2 years ago
kageru 0499d6e166
Add an explanation for the two dlls to the readme 2 years ago
kageru 40604b2692
update build script 2 years ago
kageru 79596bc4bd
Clamp input values for float if necessary 2 years ago
kageru 9fa8270564
Update release build script 2 years ago
  1. 1
      Cargo.lock
  2. 1
      Cargo.toml
  3. 8
      LICENSE
  4. 18
      README.md
  5. 14
      build_release.sh
  6. 2
      src/lib.rs
  7. 97
      src/mask.rs

1
Cargo.lock generated

@ -6,7 +6,6 @@ version = "0.3.0"
dependencies = [
"criterion",
"failure",
"lazy_static",
"vapoursynth",
"vapoursynth-sys",
]

@ -6,7 +6,6 @@ edition = "2018"
[dependencies]
failure = "0.1.8"
lazy_static = "1.4.0"
vapoursynth = "0.3.0"
vapoursynth-sys = "0.3.0"

@ -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.

@ -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.

@ -1,10 +1,14 @@
#!/bin/sh
# set rustflags as empty to make sure we’re not building for march=native,
# as these are public release builds
RUSTFLAGS="" cargo build --release --locked
RUSTFLAGS="" cargo build --release --target=x86_64-pc-windows-gnu --locked
mv target/release/libadaptivegrain_rs.so ./
# 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

@ -1,8 +1,6 @@
#[macro_use]
extern crate failure;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate vapoursynth;
pub mod mask;

@ -12,9 +12,8 @@ pub struct Mask<'core> {
pub luma_scaling: f32,
}
lazy_static! {
pub static ref FLOAT_RANGE: Vec<f32> = (0..256).map(|i| (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 {
@ -28,6 +27,11 @@ pub fn get_mask_value(x: f32, luma_scaling: f32) -> f32 {
)
}
#[inline]
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 {
($prop: expr) => {
match $prop {
@ -73,6 +77,18 @@ fn filter_for_float(frame: &mut FrameRefMut, src_frame: FrameRef, 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));
});
}
}
impl<'core> Filter<'core> for Mask<'core> {
fn video_info(&self, _api: API, _core: CoreRef<'core>) -> Vec<VideoInfo<'core>> {
let info = self.source.info();
@ -129,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.",
@ -175,11 +192,28 @@ impl<'core> Filter<'core> for Mask<'core> {
}
}
SampleType::Float => {
filter_for_float(
&mut frame,
src_frame,
calc_luma_scaling(average, self.luma_scaling),
);
// 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),
);
}
}
}
Ok(frame.into())
@ -187,6 +221,7 @@ impl<'core> Filter<'core> for Mask<'core> {
}
pub fn calc_luma_scaling(average: f32, luma_scaling: f32) -> f32 {
let average = average.min(1.0).max(0.0);
average * average * luma_scaling
}
@ -196,23 +231,57 @@ mod tests {
// 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.99829847, 0.99670357, 0.9952108, 0.99381596, 0.99251467, 0.9913026, 0.99017555, 0.98912925, 0.9881595, 0.9872621, 0.98643315, 0.98566836, 0.98496383, 0.98431563, 0.98371994, 0.9831729, 0.9826707, 0.98220986, 0.9817866, 0.9813975, 0.9810391, 0.980708, 0.980401, 0.9801147, 0.9798461, 0.97959214, 0.97934985, 0.9791162, 0.9788885, 0.9786639, 0.97843987, 0.9782137, 0.97798294, 0.97774506, 0.9774978, 0.9772388, 0.97696584, 0.9766768, 0.97636956, 0.9760422, 0.97569263, 0.97531915, 0.97491974, 0.97449285, 0.9740367, 0.9735496, 0.9730301, 0.9724766, 0.9718877, 0.97126204, 0.9705982, 0.96989495, 0.96915096, 0.9683652, 0.9675364, 0.9666635, 0.9657455, 0.96478134, 0.9637701, 0.96271086, 0.96160275, 0.9604449, 0.9592366, 0.95797706, 0.9566655, 0.9553014, 0.95388395, 0.95241266, 0.95088685, 0.949306, 0.9476697, 0.9459774, 0.9442286, 0.9424229, 0.94056, 0.93863946, 0.93666095, 0.93462414, 0.9325288, 0.93037456, 0.9281613, 0.9258888, 0.9235568, 0.92116517, 0.9187138, 0.9162025, 0.9136312, 0.91099983, 0.9083083, 0.9055567, 0.90274477, 0.8998728, 0.8969405, 0.8939482, 0.8908958, 0.88778335, 0.88461095, 0.8813788, 0.87808704, 0.87473565, 0.871325, 0.8678552, 0.8643263, 0.8607387, 0.8570925, 0.85338813, 0.8496256, 0.84580535, 0.8419277, 0.83799297, 0.83400136, 0.8299533, 0.8258492, 0.8216893, 0.8174741, 0.81320417, 0.80887955, 0.8045011, 0.80006903, 0.79558396, 0.7910463, 0.78645676, 0.7818155, 0.7771236, 0.7723811, 0.76758915, 0.7627478, 0.75785816, 0.75292087, 0.7479362, 0.74290544, 0.7378288, 0.7327075, 0.72754174, 0.72233313, 0.71708167, 0.7117891, 0.7064553, 0.7010822, 0.6956699, 0.69022, 0.6847333, 0.6792108, 0.67365366, 0.668063, 0.6624399, 0.65678567, 0.65110123, 0.6453887, 0.63964826, 0.63388246, 0.6280915, 0.622278, 0.61644244, 0.6105874, 0.6047135, 0.5988235, 0.5929182, 0.58700025, 0.58107054, 0.57513213, 0.5691858, 0.56323487, 0.55728036, 0.5513258, 0.54537195, 0.5394228, 0.5334794, 0.52754575, 0.52162296, 0.5157146, 0.50982434, 0.5039534, 0.49810678, 0.4922856, 0.48649472, 0.48073623, 0.47501534, 0.46933344, 0.46369645, 0.4581058, 0.45256722, 0.44708318, 0.4416599, 0.4362986, 0.4310061, 0.42578426, 0.42064053, 0.41557512, 0.41059688, 0.4057069, 0.4009107, 0.39621186, 0.39161587, 0.3871265, 0.38274762, 0.37848303, 0.37433672, 0.37031212, 0.36641234, 0.36264044, 0.35899892, 0.35549006, 0.35211465, 0.34887564, 0.3457732, 0.34280726, 0.33997762, 0.33728316, 0.3347223, 0.33229122, 0.32998928, 0.3278117, 0.32575342, 0.32380822, 0.32197225, 0.32023716, 0.31859392, 0.31703717, 0.3155556, 0.31413817, 0.31277677, 0.31145856, 0.3101692, 0.3088991, 0.30763134, 0.30635372, 0.30504793, 0.30370083, 0.30229148, 0.30080518, 0.29921892, 0.29751524, 0.29566884, 0.29365554, 0.29145348, 0.28903463, 0.28636503, 0.28341296, 0.2801431, 0.27650893, 0.27246484, 0.2679581, 0.26291874, 0.25727344, 0.25092778, 0.24376981, 0.23564698, 0.22636926, 0.2156733, 0.20318091, 0.18831593, 0.17008513, 0.14654778, 0.11254175];
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.97312033, 0.94854075, 0.92606485, 0.9055145, 0.88672876, 0.86956084, 0.8538767, 0.839554, 0.82648087, 0.8145538, 0.8036785, 0.793767, 0.7847378, 0.7765157, 0.7690307, 0.76221645, 0.7560116, 0.7503583, 0.7452015, 0.7404903, 0.73617536, 0.73221, 0.72855055, 0.7251544, 0.72198164, 0.7189933, 0.71615267, 0.7134242, 0.7107743, 0.70816976, 0.7055801, 0.7029752, 0.7003262, 0.69760597, 0.6947885, 0.69184875, 0.68876356, 0.6855104, 0.68206835, 0.6784181, 0.6745413, 0.6704213, 0.66604257, 0.6613911, 0.65645486, 0.65122217, 0.6456841, 0.6398328, 0.6336617, 0.6271661, 0.6203427, 0.6131898, 0.6057077, 0.5978976, 0.5897622, 0.5813064, 0.57253623, 0.56345886, 0.55408335, 0.54441965, 0.5344795, 0.52427536, 0.5138211, 0.5031317, 0.4922232, 0.48111236, 0.46981704, 0.45835546, 0.4467467, 0.4350106, 0.42316702, 0.4112368, 0.39924026, 0.38719845, 0.37513202, 0.36306223, 0.35100925, 0.33899403, 0.32703626, 0.31515577, 0.30337203, 0.29170325, 0.28016755, 0.268782, 0.25756323, 0.2465265, 0.23568656, 0.22505718, 0.21465099, 0.20447965, 0.19455387, 0.18488336, 0.17547633, 0.1663404, 0.15748179, 0.14890584, 0.14061676, 0.13261788, 0.1249111, 0.11749773, 0.11037807, 0.10355142, 0.09701606, 0.09076972, 0.08480923, 0.07913076, 0.07372954, 0.06860047, 0.06373775, 0.05913521, 0.05478584, 0.05068255, 0.046817873, 0.043183923, 0.039772622, 0.03657578, 0.03358472, 0.030791199, 0.0281864, 0.025761817, 0.02350881, 0.021418924, 0.019483581, 0.017694633, 0.01604377, 0.014523158, 0.013124882, 0.011841504, 0.010665701, 0.009590316, 0.008608681, 0.0077141733, 0.0069006504, 0.0061620683, 0.005492886, 0.0048876274, 0.004341311, 0.0038490645, 0.003406462, 0.0030092031, 0.002653386, 0.0023353002, 0.0020515076, 0.0017988166, 0.0015742666, 0.0013751301, 0.0011988885, 0.0010432207, 0.0009060293, 0.0007853431, 0.0006794224, 0.000586633, 0.0005055344, 0.00043479103, 0.00037322083, 0.00031973835, 0.000273389, 0.00023330118, 0.00019870678, 0.00016891248, 0.00014331177, 0.00012135691, 0.00010257295, 0.00008653258, 0.00007286733, 0.000061247025, 0.000051388823, 0.00004304101, 0.000035988374, 0.0000300405, 0.000025035166, 0.000020831892, 0.000017307977, 0.000014360154, 0.000011898005, 0.000009845784, 0.000008137849, 0.0000067192714, 0.0000055424794, 0.0000045681495, 0.0000037622924, 0.000003096917, 0.0000025480817, 0.000002096078, 0.0000017240154, 0.0000014181916, 0.0000011669001, 0.0000009606775, 0.0000007913941, 0.0000006526048, 0.00000053876414, 0.00000044541238, 0.0000003688414, 0.0000003060302, 0.0000002544758, 0.0000002121291, 0.00000017731381, 0.0000001486616, 0.00000012505093, 0.00000010556544, 0.00000008945813, 0.000000076118496, 0.00000006504881, 0.000000055840008, 0.000000048164882, 0.000000041750454, 0.000000036374765, 0.000000031857045, 0.00000002804884, 0.000000024828736, 0.0000000220954, 0.000000019769583, 0.000000017782428, 0.000000016077687, 0.000000014608518, 0.000000013338133, 0.000000012233408, 0.000000011266786, 0.00000001041748, 0.000000009665278, 0.000000008993553, 0.000000008389807, 0.000000007841596, 0.000000007338018, 0.0000000068717365, 0.0000000064341195, 0.000000006019636, 0.0000000056219833, 0.000000005237641, 0.0000000048619975, 0.0000000044932946, 0.000000004128811, 0.0000000037683177, 0.0000000034110592, 0.0000000030578147, 0.000000002710866, 0.0000000023724578, 0.0000000020451252, 0.0000000017326667, 0.0000000014390599, 0.0000000011677407, 0.00000000092250246, 0.00000000070643236, 0.00000000052136806, 0.00000000036839945, 0.00000000024704733, 0.00000000015548153, 0.0000000000904045, 0.000000000047542185, 0.000000000021915018, 0.000000000008435807, 0.0000000000025014576, 0.0000000000004905257, 0.00000000000004525513, 0.0000000000000006622447];
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_lut() {
fn test_mask_values() {
FLOAT_RANGE
.iter()
.zip(EXPECTED_MASK_02.iter())
.for_each(|(&x, &exp)| {
assert!((get_mask_value(x, calc_luma_scaling(0.2, 10.0)) - exp).abs() < 0.0001);
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)| {
assert!((get_mask_value(x, calc_luma_scaling(0.8, 10.0)) - exp).abs() < 0.0001);
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
);
}
}

Loading…
Cancel
Save