pub fn convert_raw_bytes(
src: &[u8],
src_type: RasterDataType,
dst: &mut [u8],
dst_type: RasterDataType,
rounding: FloatToIntRounding,
) -> Result<()>Expand description
Converts raw raster bytes of src_type into raw bytes of dst_type, in a
single pass and without allocating.
The byte-level counterpart of convert_raw_into. Prefer the typed version
whenever the destination type is known at compile time; this one exists for
dynamically typed destinations and for the complex data types, which have no
RasterElement impl.
Neither slice needs any particular alignment.
§Errors
Returns OxiGeoError::InvalidParameter if either slice is not a whole
number of samples, or if the two sample counts differ.
§Examples
use oxigeo_core::buffer::{FloatToIntRounding, convert_raw_bytes};
use oxigeo_core::types::RasterDataType;
let src: Vec<u8> = [200u16, 1000, 65_535]
.iter()
.flat_map(|v| v.to_ne_bytes())
.collect();
let mut dst = vec![0u8; 3]; // three UInt8 samples
convert_raw_bytes(
&src,
RasterDataType::UInt16,
&mut dst,
RasterDataType::UInt8,
FloatToIntRounding::Nearest,
)?;
// 1000 saturates to 255 instead of wrapping to 232.
assert_eq!(dst, vec![200, 255, 255]);