Skip to content

Commit

Permalink
rate: add assertion for q57 input range (#2911)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmatth authored Mar 17, 2022
1 parent bbb262e commit 15c487b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ simd_helpers = "0.1"
wasm-bindgen = { version = "0.2.63", optional = true }
rust_hawktracer = "0.7.0"
arrayref = "0.3.6"
const_fn_assert = "0.1.2"

[dependencies.image]
version = "0.23"
Expand Down
4 changes: 2 additions & 2 deletions src/rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::api::ContextInner;
use crate::encoder::TEMPORAL_DELIMITER;
use crate::quantize::{ac_q, dc_q, select_ac_qi, select_dc_qi};
use crate::util::{clamp, ILog, Pixel};
use const_fn_assert::cfn_debug_assert;
use std::cmp;

// The number of frame sub-types for which we track distinct parameters.
Expand Down Expand Up @@ -107,9 +108,8 @@ const Q_MODEL_MUL: [i64; 4] = [
];

// Convert an integer into a Q57 fixed-point fraction.
// The integer must be in the range -64 to 63, inclusive.
pub(crate) const fn q57(v: i32) -> i64 {
// TODO: Add assert if it ever becomes possible to do in a const function.
cfn_debug_assert!(v >= -64 && v <= 63);
(v as i64) << 57
}

Expand Down

0 comments on commit 15c487b

Please sign in to comment.