#![allow(unsafe_code)]
#![allow(clippy::cast_possible_wrap)]
#[inline]
#[must_use]
pub(crate) unsafe fn plane_row_ptr(data: *const u8, linesize: i32, y: usize) -> *const u8 {
unsafe { data.offset(y as isize * linesize as isize) }
}
#[cfg(test)]
mod tests {
use super::plane_row_ptr;
#[test]
fn positive_linesize_should_walk_rows_top_down() {
let mem = [10u8, 20, 30];
let data = mem.as_ptr();
let got: Vec<u8> = (0..3)
.map(|y| unsafe { *plane_row_ptr(data, 1, y) })
.collect();
assert_eq!(got, [10, 20, 30]);
}
#[test]
fn negative_linesize_should_walk_rows_top_down_without_flip() {
let mem = [10u8, 20, 30];
let data = unsafe { mem.as_ptr().add(2) };
let got: Vec<u8> = (0..3)
.map(|y| unsafe { *plane_row_ptr(data, -1, y) })
.collect();
assert_eq!(got, [30, 20, 10]);
}
#[test]
fn row_zero_should_return_base_pointer() {
let mem = [7u8; 4];
let data = mem.as_ptr();
assert_eq!(unsafe { plane_row_ptr(data, -13, 0) }, data);
}
}