add SANE_{,UN}FIX

This commit is contained in:
Magnus Ulimoen 2020-07-25 12:18:40 +02:00
parent da7d757e1c
commit 4fa167eb2a
1 changed files with 8 additions and 0 deletions

View File

@ -16,6 +16,14 @@ pub const fn SANE_VERSION_BUILD(code: SANE_Int) -> SANE_Word {
(code >> 0) as SANE_Word & 0xffff
}
pub fn SANE_FIX(v: f64) -> SANE_Word {
(v * (1 << SANE_FIXED_SCALE_SHIFT) as f64) as SANE_Word
}
pub fn SANE_UNFIX(v: SANE_Word) -> f64 {
v as f64 / (1 << SANE_FIXED_SCALE_SHIFT) as f64
}
#[cfg(test)]
mod tests {
use super::*;