Skip to main content

encode_borrowed

Function encode_borrowed 

Source
pub fn encode_borrowed<T: Sample>(
    width: u32,
    height: u32,
    depth: u32,
    bands: u32,
    data: &[T],
    masks: &[BitMask],
    no_data_value: Option<f64>,
    precision: Precision<T>,
) -> Result<Vec<u8>>
Expand description

Zero-copy multi-band encode entry point.

Encodes a raster image directly from a borrowed pixel slice, avoiding the buffer clone forced by the Image-based encode API. The pixel type T determines the LERC data type automatically via Sample; tolerances are expressed in T and widened to f64 internally, matching the typed slice helpers (encode_slice, encode_slice_masked).

§Data layout

data is band-major: outermost is band, then row-major within each band, then depth slices interleaved per pixel. Concretely, the value for band b, row r, column c, depth d is at index b * (width * height * depth) + (r * width + c) * depth + d.

data.len() must equal width * height * depth * bands.

§Validity masks

masks.len() must equal bands, with one BitMask per band (each having num_pixels() == width * height). For fully valid bands, pass BitMask::all_valid(width as usize * height as usize).

§Errors

Returns LercError::InvalidData if the data length, the number of masks, or any mask’s pixel count does not match the declared shape.

§Examples

use lerc::{Precision, encode_borrowed};
use lerc::bitmask::BitMask;

let width = 4u32;
let height = 3u32;
let pixels: Vec<f32> = (0..12).map(|i| i as f32).collect();
let masks = [BitMask::all_valid((width * height) as usize)];
let blob = encode_borrowed::<f32>(
    width, height, 1, 1,
    &pixels,
    &masks,
    None,
    Precision::Lossless,
).expect("encode failed");
assert!(!blob.is_empty());