Skip to main content

decode_png

Function decode_png 

Source
pub fn decode_png(bytes: &[u8]) -> Result<(Vec<u8>, u32, u32), CvError>
Expand description

Decode a PNG byte stream into packed RGB8 plus dimensions.

Returns (rgb, width, height) where rgb.len() == width * height * 3. Any PNG colour type is normalised to RGB8: RGB is copied, RGBA drops the alpha channel, grayscale replicates the single sample across R/G/B, and grayscale+alpha replicates luma while dropping alpha. Palette/low-bit-depth and 16-bit inputs are expanded/stripped to 8-bit via normalize_to_color8.

Cold path only. Any decode failure maps to a CvError — never panics.