kornia-io 0.2.0

Image and Video IO library in Rust for computer vision
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// This function expects the size of output to be input.len() / 2;
pub fn convert_buf_u8_u16_into_slice(input: &[u8], output: &mut [u16]) {
    for (i, chunk) in input.chunks_exact(2).enumerate() {
        output[i] = u16::from_be_bytes([chunk[0], chunk[1]]);
    }
}

pub fn convert_buf_u16_u8(buf: &[u16]) -> Vec<u8> {
    let mut buf_u8: Vec<u8> = Vec::with_capacity(buf.len() * 2);

    for byte in buf {
        let be_bytes = byte.to_be_bytes();
        buf_u8.extend_from_slice(&be_bytes);
    }

    buf_u8
}