MCPcopy Create free account
hub / github.com/ImageOptim/libimagequant / for_pixels

Method for_pixels

src/rows.rs:20–36  ·  view source on GitHub ↗
(pixels: SeaCow<'pixels, RGBA>, width: u32, height: u32, stride: u32)

Source from the content-addressed store, hash-verified

18
19impl<'pixels> PixelsSource<'pixels, '_> {
20 pub(crate) fn for_pixels(pixels: SeaCow<'pixels, RGBA>, width: u32, height: u32, stride: u32) -> Result<Self, Error> {
21 if stride < width || height == 0 || width == 0 {
22 return Err(Error::ValueOutOfRange);
23 }
24 let stride = stride as usize;
25 let width = width as usize;
26 let height = height as usize;
27
28 let slice = pixels.as_slice();
29 let min_area = stride.checked_mul(height).and_then(|a| a.checked_add(width)).ok_or(Error::ValueOutOfRange)? - stride;
30 if slice.len() < min_area {
31 return Err(Error::BufferTooSmall);
32 }
33
34 let rows = SeaCow::boxed(slice.chunks(stride).map(|row| Pointer(row.as_ptr())).take(height).collect());
35 Ok(Self::Pixels { rows, pixels: Some(pixels) })
36 }
37}
38
39pub(crate) struct DynamicRows<'pixels, 'rows> {

Callers

nothing calls this directly

Calls 4

PointerClass · 0.85
chunksMethod · 0.80
as_sliceMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected