From 4fa167eb2a777354ff455c905e72f245311acd43 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Sat, 25 Jul 2020 12:18:40 +0200 Subject: [PATCH] add SANE_{,UN}FIX --- sane-sys/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sane-sys/src/lib.rs b/sane-sys/src/lib.rs index cf6af3c..4665c0c 100644 --- a/sane-sys/src/lib.rs +++ b/sane-sys/src/lib.rs @@ -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::*;