pub(crate) unsafe fn pack_rows(
base: *const u8,
pitch: usize,
row_bytes: usize,
height: usize,
) -> Option<Vec<u8>> {
if base.is_null() || pitch < row_bytes {
return None;
}
unsafe {
if pitch == row_bytes {
return Some(core::slice::from_raw_parts(base, row_bytes * height).to_vec());
}
let padded = core::slice::from_raw_parts(base, pitch * height);
let mut packed = Vec::with_capacity(row_bytes * height);
for row in 0..height {
let start = row * pitch;
packed.extend_from_slice(&padded[start..start + row_bytes]);
}
Some(packed)
}
}