#![allow(dead_code)]
use colorous::TURBO;
pub fn depth2image(depth: &[u8]) -> Option<Vec<u8>> {
assert!(depth.len() % 2 == 0);
let depth_u16 =
unsafe { std::slice::from_raw_parts(depth.as_ptr() as *const u16, depth.len() / 2) };
let (min, max) = depth_u16
.iter()
.fold((u16::MAX, u16::MIN), |(min, max), &d| {
(if d != 0 { min.min(d) } else { min }, max.max(d))
});
let bgr = depth_u16
.iter()
.flat_map(|&d| {
if d == 0 {
[0, 0, 0]
} else {
let normalized = (d - min) as f64 / (max - min) as f64;
let color = TURBO.eval_continuous(normalized);
[color.b, color.g, color.r]
}
})
.collect::<Vec<u8>>();
Some(bgr)
}
pub fn add_images(img1: &[u8], img2: &[u8]) -> Vec<u8> {
assert!(img1.len() == img2.len());
img1.iter()
.zip(img2.iter())
.map(|(&a, &b)| (a / 2) + (b / 2))
.collect::<Vec<u8>>()
}