tiff2 0.0.4

temporary async implementation of tiff - to be upstreamed into image-tiff
Documentation
use crate::ByteOrder;

/// Fix endianness. If `byte_order` matches the host, then conversion is a no-op.
pub fn fix_endianness(buf: &mut [u8], byte_order: ByteOrder, bit_depth: u8) {
    match byte_order {
        ByteOrder::LittleEndian => match bit_depth {
            0..=8 => {}
            9..=16 => buf.chunks_exact_mut(2).for_each(|v| {
                v.copy_from_slice(&u16::from_le_bytes((*v).try_into().unwrap()).to_ne_bytes())
            }),
            17..=32 => buf.chunks_exact_mut(4).for_each(|v| {
                v.copy_from_slice(&u32::from_le_bytes((*v).try_into().unwrap()).to_ne_bytes())
            }),
            _ => buf.chunks_exact_mut(8).for_each(|v| {
                v.copy_from_slice(&u64::from_le_bytes((*v).try_into().unwrap()).to_ne_bytes())
            }),
        },
        ByteOrder::BigEndian => match bit_depth {
            0..=8 => {}
            9..=16 => buf.chunks_exact_mut(2).for_each(|v| {
                v.copy_from_slice(&u16::from_be_bytes((*v).try_into().unwrap()).to_ne_bytes())
            }),
            17..=32 => buf.chunks_exact_mut(4).for_each(|v| {
                v.copy_from_slice(&u32::from_be_bytes((*v).try_into().unwrap()).to_ne_bytes())
            }),
            _ => buf.chunks_exact_mut(8).for_each(|v| {
                v.copy_from_slice(&u64::from_be_bytes((*v).try_into().unwrap()).to_ne_bytes())
            }),
        },
    };
}