diff --git a/.github/workflows/av1-grain-compact.yml b/.github/workflows/av1-grain-compact.yml deleted file mode 100644 index baa437f..0000000 --- a/.github/workflows/av1-grain-compact.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: av1-grain-compact - -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - build-test: - strategy: - matrix: - platform: [ubuntu-latest, macos-latest, windows-latest] - - runs-on: ${{ matrix.platform }} - - steps: - - uses: actions/checkout@v3 - - - name: Install Rust stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - components: rustfmt, clippy - - - name: Run rustfmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: -- --check --verbose - - - name: Run cargo clippy - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --all-targets --tests --benches -- -D warnings - - - name: Build - run: cargo build --verbose --tests --benches - - - name: Run tests - run: cargo test --verbose - - - name: Generate docs - run: cargo doc --no-deps diff --git a/.github/workflows/av1-grain-macos.yml b/.github/workflows/av1-grain-macos.yml deleted file mode 100644 index b8b8e9c..0000000 --- a/.github/workflows/av1-grain-macos.yml +++ /dev/null @@ -1,243 +0,0 @@ -#FIXME -# - valgrind cannot be installed on macos, only on linux -# - rust-code-analysis is not tested on macos, so no static analysis - -name: av1-grain-macos - -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - build-test: - runs-on: macos-latest - - steps: - - uses: actions/checkout@v3 - - - name: Install Rust stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - components: rustfmt, clippy - - - name: Run rustfmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: -- --check --verbose - - - name: Run cargo clippy - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --all-targets --tests --benches -- -D warnings - - - name: Build - run: cargo build --verbose --tests --benches - - - name: Run tests - run: cargo test --verbose - - - name: Generate docs - run: cargo doc --no-deps - - code-coverage: - runs-on: macos-latest - - steps: - - uses: actions/checkout@v3 - - - name: Install Rust stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Install grcov - env: - GRCOV_LINK: https://github.com/mozilla/grcov/releases/download - GRCOV_VERSION: v0.8.7 - run: | - curl -L "$GRCOV_LINK/$GRCOV_VERSION/grcov-x86_64-apple-darwin.tar.bz2" | - tar xj -C $HOME/.cargo/bin - - - name: Install llvm-tools-preview - run: | - rustup component add llvm-tools-preview - - # Not necessary on a newly created image, but strictly advised - - name: Run cargo clean - run: | - cargo clean - - - name: Run tests - env: - CARGO_INCREMENTAL: 0 - LLVM_PROFILE_FILE: "av1-grain-%p-%m.profraw" - RUSTFLAGS: > - -Cinstrument-coverage -Ccodegen-units=1 -Clink-dead-code - -Coverflow-checks=off - RUSTDOCFLAGS: > - -Cinstrument-coverage -Ccodegen-units=1 -Clink-dead-code - -Coverflow-checks=off - run: | - cargo test --verbose - - - name: Get coverage data for coveralls - run: | - grcov . --binary-path ./target/debug/ -s . -t lcov --branch \ - --ignore-not-existing --ignore "/*" --ignore "../*" -o lcov.info - - - name: Coveralls upload - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: lcov.info - - # - name: Get total coverage - # run: | - # grcov . --binary-path ./target/debug/ -t covdir -s . \ - # --token YOUR_COVDIR_TOKEN > covdir.json - # - # - name: Evaluate code coverage value - # shell: bash - # run: | - # # Retrieve code coverage associated to the repository - # FLOAT_COVERAGE=$(jq '.coveragePercent' covdir.json) - # # Round the float value to the nearest value - # COVERAGE_OUTPUT=$(printf "%.0f" $FLOAT_COVERAGE) - # # If code coverage >= 80, green traffic light - # if [ $COVERAGE_OUTPUT -ge 80 ] - # then - # echo "$COVERAGE_OUTPUT > 80 --> Green" - # # If code coverage is >=60 but < 80, orange traffic light - # elif [ $COVERAGE_OUTPUT -ge 60 ] - # then - # echo "60 <= $COVERAGE_OUTPUT < 80 --> Orange" - # # Otherwise, red traffic light - # else - # echo "$COVERAGE_OUTPUT < 60 --> Red" - # exit 1 - # fi - - undefined-behaviour-fuzzy-dynamic-analysis: - runs-on: macos-latest - - steps: - - uses: actions/checkout@v3 - - - name: Cache produced data - uses: actions/cache@v3 - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ - key: ${{ runner.os }}-cargo-ci-${{ hashFiles('**/Cargo.toml') }} - - - name: Install Rust nightly and miri - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - components: miri - override: true - - # FIXME Use binaries - - name: Install cargo-fuzz - run: | - cargo install cargo-fuzz --force - - - name: Run miri - env: - # -Zrandomize-layout makes sure not to rely on the layout of anything - # that might change - RUSTFLAGS: -Zrandomize-layout - # -Zmiri-check-number-validity enables checking of integer and float - # validity (e.g., they must be initialized and not carry - # pointer provenance) as part of enforcing validity invariants. - # -Zmiri-tag-raw-pointers enables a lot of extra UB checks relating - # to raw pointer aliasing rules. - # -Zmiri-symbolic-alignment-check makes the alignment check more strict. - MIRIFLAGS: > - -Zmiri-check-number-validity -Zmiri-tag-raw-pointers - -Zmiri-symbolic-alignment-check - run: cargo miri test - - # FIXME Create a template with a dummy series of fuzzy tests - - name: Init cargo-fuzz - run: cargo fuzz init - - - name: Run cargo-fuzz - run: cargo fuzz build - - weighted-code-coverage: - runs-on: macos-latest - - steps: - - uses: actions/checkout@v3 - - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Install grcov - env: - GRCOV_LINK: https://github.com/mozilla/grcov/releases/download - GRCOV_VERSION: v0.8.7 - GRCOV_BINARY: grcov-x86_64-apple-darwin.tar.bz2 - run: | - curl -L "$GRCOV_LINK/$GRCOV_VERSION/$GRCOV_BINARY" | - tar xj -C $HOME/.cargo/bin - - - name: Install weighted-code-coverage - env: - WCC_LINK: https://github.com/giovannitangredi/weighted-code-coverage/releases/download - WCC_VERSION: v0.1.0 - WCC_BINARY: weighted-code-coverage-0.1.0-x86_64-apple-darwin.tar.gz - run: | - curl -L "$WCC_LINK/$WCC_VERSION/$WCC_BINARY" | - tar xz -C $HOME/.cargo/bin - - - name: Install llvm-tools-preview - run: | - rustup component add llvm-tools-preview - - # Not necessary on a newly created image, but strictly advised - - name: Run cargo clean - run: | - cargo clean - - - name: Run tests - env: - RUSTFLAGS: "-Cinstrument-coverage" - LLVM_PROFILE_FILE: "av1-grain-%p-%m.profraw" - run: | - cargo test --verbose - - - name: Run grcov - run: | - grcov . --binary-path ./target/debug/ -t coveralls -s . --token YOUR_COVERALLS_TOKEN > coveralls.json - - - name: Run weighted-code-coverage - run: | - mkdir $HOME/wcc-output - weighted-code-coverage -p src/ -j coveralls.json -c --json $HOME/wcc-output/out.json - - - name: Upload weighted-code-coverage data - uses: actions/upload-artifact@v3 - with: - name: weighted-code-coverage-macos - path: ~/wcc-output/out.json diff --git a/.github/workflows/av1-grain-ubuntu.yml b/.github/workflows/av1-grain-ubuntu.yml deleted file mode 100644 index 893338f..0000000 --- a/.github/workflows/av1-grain-ubuntu.yml +++ /dev/null @@ -1,294 +0,0 @@ -name: av1-grain-ubuntu - -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - build-test: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Install Rust stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - components: rustfmt, clippy - - - name: Run rustfmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: -- --check --verbose - - - name: Run cargo clippy - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --all-targets --tests --benches -- -D warnings - - - name: Build - run: cargo build --verbose --tests --benches - - - name: Run tests - run: cargo test --verbose - - - name: Generate docs - run: cargo doc --no-deps - - code-coverage: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Install Rust stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Install grcov - env: - GRCOV_LINK: https://github.com/mozilla/grcov/releases/download - GRCOV_VERSION: v0.8.7 - run: | - curl -L "$GRCOV_LINK/$GRCOV_VERSION/grcov-x86_64-unknown-linux-musl.tar.bz2" | - tar xj -C $HOME/.cargo/bin - - - name: Install llvm-tools-preview - run: | - rustup component add llvm-tools-preview - - # Not necessary on a newly created image, but strictly advised - - name: Run cargo clean - run: | - cargo clean - - - name: Run tests - env: - CARGO_INCREMENTAL: 0 - LLVM_PROFILE_FILE: "av1-grain-%p-%m.profraw" - RUSTFLAGS: > - -Cinstrument-coverage -Ccodegen-units=1 -Clink-dead-code - -Coverflow-checks=off - RUSTDOCFLAGS: > - -Cinstrument-coverage -Ccodegen-units=1 -Clink-dead-code - -Coverflow-checks=off - run: | - cargo test --verbose - - - name: Get coverage data for coveralls - run: | - grcov . --binary-path ./target/debug/ -s . -t lcov --branch \ - --ignore-not-existing --ignore "/*" --ignore "../*" -o lcov.info - - - name: Coveralls upload - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: lcov.info - - # - name: Get total coverage - # run: | - # grcov . --binary-path ./target/debug/ -t covdir -s . \ - # --token YOUR_COVDIR_TOKEN > covdir.json - # - # - name: Evaluate code coverage value - # shell: bash - # run: | - # # Retrieve code coverage associated to the repository - # FLOAT_COVERAGE=$(jq '.coveragePercent' covdir.json) - # # Round the float value to the nearest value - # COVERAGE_OUTPUT=$(printf "%.0f" $FLOAT_COVERAGE) - # # If code coverage >= 80, green traffic light - # if [ $COVERAGE_OUTPUT -ge 80 ] - # then - # echo "$COVERAGE_OUTPUT > 80 --> Green" - # # If code coverage is >=60 but < 80, orange traffic light - # elif [ $COVERAGE_OUTPUT -ge 60 ] - # then - # echo "60 <= $COVERAGE_OUTPUT < 80 --> Orange" - # # Otherwise, red traffic light - # else - # echo "$COVERAGE_OUTPUT < 60 --> Red" - # exit 1 - # fi - - memory-and-threads-dynamic-analysis: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Install Rust stable - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - - name: Install valgrind - run: | - sudo apt-get install valgrind - - # FIXME Use binaries - - name: Install cargo-valgrind - run: | - cargo install cargo-valgrind - - # Usage of the `help` command as base command, please replace it - # with the effective command that valgrind has to analyze - - name: Run cargo-valgrind - run: | - cargo valgrind run -- --help - - undefined-behaviour-fuzzy-dynamic-analysis: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Cache produced data - uses: actions/cache@v3 - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ - key: ${{ runner.os }}-cargo-ci-${{ hashFiles('**/Cargo.toml') }} - - - name: Install Rust nightly and miri - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - components: miri - override: true - - # FIXME Use binaries - - name: Install cargo-fuzz - run: | - cargo install cargo-fuzz --force - - - name: Run miri - env: - # -Zrandomize-layout makes sure not to rely on the layout of anything - # that might change - RUSTFLAGS: -Zrandomize-layout - # -Zmiri-check-number-validity enables checking of integer and float - # validity (e.g., they must be initialized and not carry - # pointer provenance) as part of enforcing validity invariants. - # -Zmiri-tag-raw-pointers enables a lot of extra UB checks relating - # to raw pointer aliasing rules. - # -Zmiri-symbolic-alignment-check makes the alignment check more strict. - MIRIFLAGS: > - -Zmiri-check-number-validity -Zmiri-tag-raw-pointers - -Zmiri-symbolic-alignment-check - run: cargo miri test - - # FIXME Create a template with a dummy series of fuzzy tests - - name: Init cargo-fuzz - run: cargo fuzz init - - - name: Run cargo-fuzz - run: cargo fuzz build - - static-code-analysis: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Install rust-code-analysis - env: - RCA_LINK: https://github.com/mozilla/rust-code-analysis/releases/download - RCA_VERSION: v0.0.23 - run: | - mkdir -p $HOME/.local/bin - curl -L "$RCA_LINK/$RCA_VERSION/rust-code-analysis-linux-cli-x86_64.tar.gz" | - tar xz -C $HOME/.local/bin - echo "$HOME/.local/bin" >> $GITHUB_PATH - - - name: Run rust-code-analysis - run: | - mkdir $HOME/rca-json - # FIXME: Update rca version to analyze the entire directory of a repo - rust-code-analysis-cli --metrics -O json --pr -o "$HOME/rca-json" -p src/ - - - name: Upload rust-code-analysis json - uses: actions/upload-artifact@v3 - with: - name: rca-json-ubuntu - path: ~/rca-json - - weighted-code-coverage: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Install grcov - env: - GRCOV_LINK: https://github.com/mozilla/grcov/releases/download - GRCOV_VERSION: v0.8.7 - GRCOV_BINARY: grcov-x86_64-unknown-linux-musl.tar.bz2 - run: | - curl -L "$GRCOV_LINK/$GRCOV_VERSION/$GRCOV_BINARY" | - tar xj -C $HOME/.cargo/bin - - - name: Install weighted-code-coverage - env: - WCC_LINK: https://github.com/giovannitangredi/weighted-code-coverage/releases/download - WCC_VERSION: v0.1.0 - WCC_BINARY: weighted-code-coverage-0.1.0-x86_64-unknown-linux-gnu.tar.gz - run: | - curl -L "$WCC_LINK/$WCC_VERSION/$WCC_BINARY" | - tar xz -C $HOME/.cargo/bin - - - name: Install llvm-tools-preview - run: | - rustup component add llvm-tools-preview - - # Not necessary on a newly created image, but strictly advised - - name: Run cargo clean - run: | - cargo clean - - - name: Run tests - env: - RUSTFLAGS: "-Cinstrument-coverage" - LLVM_PROFILE_FILE: "av1-grain-%p-%m.profraw" - run: | - cargo test --verbose - - - name: Run grcov - run: | - grcov . --binary-path ./target/debug/ -t coveralls -s . --token YOUR_COVERALLS_TOKEN > coveralls.json - - - name: Run weighted-code-coverage - run: | - mkdir $HOME/wcc-output - weighted-code-coverage -p src/ -j coveralls.json -c --json $HOME/wcc-output/out.json - - - name: Upload weighted-code-coverage data - uses: actions/upload-artifact@v3 - with: - name: weighted-code-coverage-ubuntu - path: ~/wcc-output/out.json diff --git a/.github/workflows/av1-grain-windows.yml b/.github/workflows/av1-grain-windows.yml deleted file mode 100644 index c5dd694..0000000 --- a/.github/workflows/av1-grain-windows.yml +++ /dev/null @@ -1,141 +0,0 @@ -# FIXME -# - Code coverage on Windows does not work because there are problems -# with grcov paths -# - valgrind cannot be installed on Windows, only on linux -# - cargo-fuzz and AddressSanitizer are not supported on Windows - -name: av1-grain-windows - -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - build-test: - runs-on: windows-latest - - steps: - - uses: actions/checkout@v3 - - - name: Install Rust stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - components: rustfmt, clippy - - - name: Run rustfmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: -- --check --verbose - - - name: Run cargo clippy - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --all-targets --tests --benches -- -D warnings - - - name: Build - run: cargo build --verbose --tests --benches - - - name: Run tests - run: cargo test --verbose - - - name: Generate docs - run: cargo doc --no-deps - - static-code-analysis: - runs-on: windows-latest - - steps: - - uses: actions/checkout@v3 - - - name: Install rust-code-analysis - env: - RCA_LINK: https://github.com/mozilla/rust-code-analysis/releases/download - RCA_VERSION: v0.0.23 - run: | - mkdir -p $HOME/bin - curl -LO "$Env:RCA_LINK/$env:RCA_VERSION/rust-code-analysis-win-cli-x86_64.zip" - 7z e -y "rust-code-analysis-win-cli-x86_64.zip" -o"$HOME/bin" - echo "$HOME/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - - - name: Run rust-code-analysis - run: | - mkdir $HOME/rca-json - # FIXME: Update rca version to analyze the entire directory of a repo - rust-code-analysis-cli --metrics -O json --pr -o "$HOME/rca-json" -p src/ - - - name: Upload rust-code-analysis json - uses: actions/upload-artifact@v3 - with: - name: rca-json-windows - path: ~/rca-json - - weighted-code-coverage: - runs-on: windows-latest - - steps: - - uses: actions/checkout@v3 - - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - - name: Install grcov - env: - GRCOV_LINK: https://github.com/mozilla/grcov/releases/download - GRCOV_VERSION: v0.8.7 - GRCOV_BINARY: grcov-x86_64-pc-windows-msvc.zip - run: | - curl -LO "$Env:GRCOV_LINK/$Env:GRCOV_VERSION/$Env:GRCOV_BINARY" - 7z e -y "$Env:GRCOV_BINARY" -o"${env:USERPROFILE}\.cargo\bin" - - - name: Install weighted-code-coverage - env: - WCC_LINK: https://github.com/giovannitangredi/weighted-code-coverage/releases/download - WCC_VERSION: v0.1.0 - WCC_BINARY: weighted-code-coverage-0.1.0-x86_64-pc-windows-msvc.zip - run: | - curl -LO "$Env:WCC_LINK/$Env:WCC_VERSION/$Env:WCC_BINARY" - 7z e -y "$Env:WCC_BINARY" -o"${env:USERPROFILE}\.cargo\bin" - - - name: Install llvm-tools-preview - run: | - rustup component add llvm-tools-preview - - # Not necessary on a newly created image, but strictly advised - - name: Run cargo clean - run: | - cargo clean - - - name: Run tests - env: - RUSTFLAGS: "-Cinstrument-coverage" - LLVM_PROFILE_FILE: "av1-grain-%p-%m.profraw" - run: | - cargo test --verbose - - - name: Run grcov - run: | - grcov . --binary-path ./target/debug/ -t coveralls -s . --token YOUR_COVERALLS_TOKEN > coveralls.json - - - name: Run weighted-code-coverage - run: | - mkdir $HOME/wcc-output - weighted-code-coverage -p src/ -j coveralls.json -c --json $HOME/wcc-output/out.json - - - name: Upload weighted-code-coverage data - uses: actions/upload-artifact@v3 - with: - name: weighted-code-coverage-windows - path: ~/wcc-output/out.json diff --git a/.github/workflows/av1-grain.yml b/.github/workflows/av1-grain.yml new file mode 100644 index 0000000..1171d37 --- /dev/null +++ b/.github/workflows/av1-grain.yml @@ -0,0 +1,102 @@ +name: av1-grain + +on: + push: + branches: + - main + pull_request: + branches: + - main + +env: + CARGO_INCREMENTAL: 0 + RUSTFLAGS: "-Dwarnings" + + GRCOV_LINK: "https://github.com/mozilla/grcov/releases/download" + GRCOV_VERSION: "v0.8.19" + +jobs: + clippy-rustfmt: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v4 + - name: Install Rust stable with rustfmt and clippy + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt, clippy + + - name: Run rustfmt + run: cargo fmt --all -- --check + + - name: Run clippy + run: cargo clippy --all-features --all-targets + + build-test: + runs-on: ubuntu-22.04 + needs: clippy-rustfmt + + steps: + - uses: actions/checkout@v4 + - name: Install Rust stable + uses: dtolnay/rust-toolchain@stable + + - name: Run build + run: cargo build --all-features --all-targets + + - name: Run tests + run: cargo test + + code-coverage: + runs-on: ubuntu-22.04 + needs: clippy-rustfmt + + steps: + - uses: actions/checkout@v4 + - name: Install Rust stable with llvm-tools-preview + uses: dtolnay/rust-toolchain@stable + with: + components: llvm-tools-preview + + - name: Install grcov + run: | + curl -L "$GRCOV_LINK/$GRCOV_VERSION/grcov-x86_64-unknown-linux-musl.tar.bz2" | + tar xj -C "$HOME/.cargo/bin" + + - name: Run instrumented tests + env: + RUSTFLAGS: "-Dwarnings -Cinstrument-coverage -Clink-dead-code" + LLVM_PROFILE_FILE: "av1-grain-%p-%m.profraw" + run: cargo test + + - name: Get coverage data + run: | + grcov . --binary-path target/debug/ -s . -t lcov --branch \ + --keep-only 'src/*' -o lcov.info + + - name: Codecov upload + uses: codecov/codecov-action@v4 + with: + files: lcov.info + token: ${{ secrets.CODECOV_TOKEN }} + + miri: + runs-on: ubuntu-22.04 + needs: clippy-rustfmt + + steps: + - uses: actions/checkout@v4 + - name: Install Rust nightly with Miri + uses: dtolnay/rust-toolchain@nightly + with: + components: miri + + # Avoid cluttering output of next step with auto-setup + - name: Run miri setup + run: cargo miri setup + + - name: Run miri test + env: + RUSTFLAGS: "-Zrandomize-layout" + MIRIFLAGS: "-Zmiri-symbolic-alignment-check" + run: cargo miri test diff --git a/src/create.rs b/src/create.rs index 3c047f5..576d0eb 100644 --- a/src/create.rs +++ b/src/create.rs @@ -170,15 +170,15 @@ pub fn generate_photon_noise_params( #[must_use] #[cfg(feature = "unstable")] pub fn generate_film_grain_params( - start_time: u64, - end_time: u64, - args: NoiseGenArgs, + _start_time: u64, + _end_time: u64, + _args: NoiseGenArgs, ) -> GrainTableSegment { todo!("SCIENCE"); // GrainTableSegment { - // start_time, - // end_time, - // scaling_points_y: generate_luma_noise_points(args), + // _start_time, + // _end_time, + // scaling_points_y: generate_luma_noise_points(_args), // scaling_points_cb: ArrayVec::new(), // scaling_points_cr: ArrayVec::new(), // scaling_shift: 8, diff --git a/src/diff.rs b/src/diff.rs index a85759f..dc461c9 100644 --- a/src/diff.rs +++ b/src/diff.rs @@ -2,7 +2,7 @@ use anyhow::{ensure, Result}; use num_rational::Rational64; use v_frame::{frame::Frame, pixel::Pixel}; -use self::solver::{FlatBlockFinder, NoiseModel}; +use self::solver::{FlatBlockFinder, NoiseModel, NoiseModelStatus}; use crate::{util::frame_into_u8, GrainTableSegment}; mod solver; @@ -75,7 +75,7 @@ impl DiffGenerator { log::debug!("Updating noise model"); let status = self.noise_model.update(source, denoised, &flat_blocks); - if status == NoiseStatus::DifferentType { + if status == NoiseModelStatus::DifferentType { let cur_timestamp = self.frame_count as u64 * 10_000_000u64 * *self.fps.denom() as u64 / *self.fps.numer() as u64; log::debug!( @@ -97,22 +97,6 @@ impl DiffGenerator { } } -#[derive(Debug)] -enum NoiseStatus { - Ok, - DifferentType, - Error(anyhow::Error), -} - -impl PartialEq for NoiseStatus { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (&Self::Error(_), &Self::Error(_)) => true, - _ => core::mem::discriminant(self) == core::mem::discriminant(other), - } - } -} - fn verify_dimensions_match(source: &Frame, denoised: &Frame) -> Result<()> { let res_1 = (source.planes[0].cfg.width, source.planes[0].cfg.height); let res_2 = (denoised.planes[0].cfg.width, denoised.planes[0].cfg.height); diff --git a/src/diff/solver.rs b/src/diff/solver.rs index 2c92b62..7b59191 100644 --- a/src/diff/solver.rs +++ b/src/diff/solver.rs @@ -2,12 +2,11 @@ mod util; use std::ops::{Add, AddAssign}; -use anyhow::anyhow; use arrayvec::ArrayVec; use v_frame::{frame::Frame, math::clamp, plane::Plane}; use self::util::{extract_ar_row, get_block_mean, get_noise_var, linsolve, multiply_mat}; -use super::{NoiseStatus, BLOCK_SIZE, BLOCK_SIZE_SQUARED}; +use super::{BLOCK_SIZE, BLOCK_SIZE_SQUARED}; use crate::{ diff::solver::util::normalized_cross_correlation, GrainTableSegment, DEFAULT_GRAIN_SEED, NUM_UV_COEFFS, NUM_UV_POINTS, NUM_Y_COEFFS, NUM_Y_POINTS, @@ -360,6 +359,13 @@ pub(super) struct NoiseModel { coords: Vec<[isize; 2]>, } +#[derive(PartialEq, Eq)] +pub(super) enum NoiseModelStatus { + Ok, + DifferentType, + Error, +} + impl NoiseModel { #[must_use] pub fn new() -> Self { @@ -374,7 +380,7 @@ impl NoiseModel { NoiseModelState::new(n + 1), NoiseModelState::new(n + 1), ]; - let mut coords = Vec::new(); + let mut coords = Vec::with_capacity(n); let neg_lag = -(NOISE_MODEL_LAG as isize); for y in neg_lag..=0 { @@ -402,7 +408,7 @@ impl NoiseModel { source: &Frame, denoised: &Frame, flat_blocks: &[u8], - ) -> NoiseStatus { + ) -> NoiseModelStatus { let num_blocks_w = (source.planes[0].cfg.width + BLOCK_SIZE - 1) / BLOCK_SIZE; let num_blocks_h = (source.planes[0].cfg.height + BLOCK_SIZE - 1) / BLOCK_SIZE; let mut y_model_different = false; @@ -417,7 +423,8 @@ impl NoiseModel { // Check that we have enough flat blocks let num_blocks = flat_blocks.iter().filter(|b| **b > 0).count(); if num_blocks <= 1 { - return NoiseStatus::Error(anyhow!("Not enough flat blocks to update noise estimate")); + // need more than one flat block to update estimate + return NoiseModelStatus::Error; } let frame_dims = (source.planes[0].cfg.width, source.planes[0].cfg.height); @@ -446,10 +453,7 @@ impl NoiseModel { .eqns .set_chroma_coefficient_fallback_solution(); } else { - return NoiseStatus::Error(anyhow!( - "Solving latest noise equation system failed on plane {}", - channel - )); + return NoiseModelStatus::Error; } } self.add_noise_std_observations( @@ -463,9 +467,7 @@ impl NoiseModel { num_blocks_h, ); if !self.latest_state[channel].strength_solver.solve() { - return NoiseStatus::Error(anyhow!( - "Failed to solve strength solver for latest state" - )); + return NoiseModelStatus::Error; } // Check noise characteristics and return if error @@ -489,10 +491,7 @@ impl NoiseModel { .eqns .set_chroma_coefficient_fallback_solution(); } else { - return NoiseStatus::Error(anyhow!( - "Solving combined noise equation system failed on plane {}", - channel - )); + return NoiseModelStatus::Error; } } @@ -500,17 +499,15 @@ impl NoiseModel { &self.latest_state[channel].strength_solver; if !self.combined_state[channel].strength_solver.solve() { - return NoiseStatus::Error(anyhow!( - "Failed to solve strength solver for combined state" - )); + return NoiseModelStatus::Error; }; } if y_model_different { - return NoiseStatus::DifferentType; + return NoiseModelStatus::DifferentType; } - NoiseStatus::Ok + NoiseModelStatus::Ok } #[allow(clippy::too_many_lines)]