The pair of pixel_format and pixels types is very C-like, without type safety.
This is especially clear with the addition of L16 format, which is difficult to safely read. Reading it as .chunks(2) requires dealing with endianness (the docs don't say which endian it is), and casting it to &[u16] is not possible to do safely due to risk of insufficient alignment. So assuming it's a native endian, it requires a totally unsafe loop with pointer arithmetic and ptr::read_unaligned.
It would be better to expose pixel formats in a type-safe manner, like:
enum Pixels {
L8(Vec<u8>),
L16(Vec<u16>),
RGB24(Vec<RGB<u8>>),
}
The pair of
pixel_formatandpixelstypes is very C-like, without type safety.This is especially clear with the addition of
L16format, which is difficult to safely read. Reading it as.chunks(2)requires dealing with endianness (the docs don't say which endian it is), and casting it to&[u16]is not possible to do safely due to risk of insufficient alignment. So assuming it's a native endian, it requires a totallyunsafeloop with pointer arithmetic andptr::read_unaligned.It would be better to expose pixel formats in a type-safe manner, like: