pub(crate) fn lodepng_inspect(
    decoder: &DecoderSettings,
    inp: &[u8],
) -> Result<(Info, u32, u32), Error> {
    if inp.len() < 33 {
        /*error: the data length is smaller than the length of a PNG header*/
        return Err(Error(27));
    }
    /*when decoding a new PNG image, make sure all parameters created after previous decoding are reset*/
    let mut info_png = Info::new();
    if inp[0..8] != [137, 80, 78, 71, 13, 10, 26, 10] {
        /*error: the first 8 bytes are not the correct PNG signature*/
        return Err(Error(28));
    }
    if lodepng_chunk_length(&inp[8..]) != 13 {
        /*error: header size must be 13 bytes*/
        return Err(Error(94));
    }
    if lodepng_chunk_type(&inp[8..]) != b"IHDR" {
        /*error: it doesn't start with a IHDR chunk!*/
        return Err(Error(29));
    }
    /*read the values given in the header*/
    let w = lodepng_read32bit_int(&inp[16..]);
    let h = lodepng_read32bit_int(&inp[20..]);
    let bitdepth = inp[24];
    if bitdepth == 0 || bitdepth > 16 {
        return Err(Error(29));
    }
    info_png.color.set_bitdepth(inp[24] as u32);
    info_png.color.colortype = match inp[25] {
        0 => ColorType::Grey,
        2 => ColorType::Rgb,
        3 => ColorType::Palette,
        4 => ColorType::GreyAlpha,
        6 => ColorType::Rgba,
        _ => return Err(Error(31)),
    };
    info_png.compression_method = inp[26] as u32;
    info_png.filter_method = inp[27] as u32;
    info_png.interlace_method = inp[28] as u32;
    if w == 0 || h == 0 {
        return Err(Error(93));
    }
    if decoder.check_crc {
        let crc = lodepng_read32bit_int(&inp[29..]);
        let checksum = lodepng_crc32(&inp[12..(12 + 17)]);
        if crc != checksum {
            return Err(Error(57));
        };
    }
    if info_png.compression_method != 0 {
        /*error: only compression method 0 is allowed in the specification*/
        return Err(Error(32));
    }
    if info_png.filter_method != 0 {
        /*error: only filter method 0 is allowed in the specification*/
        return Err(Error(33));
    }
    if info_png.interlace_method > 1 {
        /*error: only interlace methods 0 and 1 exist in the specification*/
        return Err(Error(34));
    }
    check_png_color_validity(
        info_png.color.colortype,
        info_png.color.bitdepth(),
    )?;
    Ok((info_png, w, h))
}
/*read the information from the header and store it in the Info. return value is error*/
read the information from the header and store it in the Info. return value is error
read the information from the header and store it in the Info . return value is error
pub(crate) fn lodepng_inspect(
    decoder: &DecoderSettings,
    inp: &[u8],
) -> Result<(Info, u32, u32), Error> {
    if inp.len() < 33 {
        /*error: the data length is smaller than the length of a PNG header*/
        return Err(Error(27));
    }
    /*when decoding a new PNG image, make sure all parameters created after previous decoding are reset*/
    let mut info_png = Info::new();
    if inp[0..8] != [137, 80, 78, 71, 13, 10, 26, 10] {
        /*error: the first 8 bytes are not the correct PNG signature*/
        return Err(Error(28));
    }
    if lodepng_chunk_length(&inp[8..]) != 13 {
        /*error: header size must be 13 bytes*/
        return Err(Error(94));
    }
    if lodepng_chunk_type(&inp[8..]) != b"IHDR" {
        /*error: it doesn't start with a IHDR chunk!*/
        return Err(Error(29));
    }
    /*read the values given in the header*/
    let w = lodepng_read32bit_int(&inp[16..]);
    let h = lodepng_read32bit_int(&inp[20..]);
    let bitdepth = inp[24];
    if bitdepth == 0 || bitdepth > 16 {
        return Err(Error(29));
    }
    info_png.color.set_bitdepth(inp[24] as u32);
    info_png.color.colortype = match inp[25] {
        0 => ColorType::Grey,
        2 => ColorType::Rgb,
        3 => ColorType::Palette,
        4 => ColorType::GreyAlpha,
        6 => ColorType::Rgba,
        _ => return Err(Error(31)),
    };
    info_png.compression_method = inp[26] as u32;
    info_png.filter_method = inp[27] as u32;
    info_png.interlace_method = inp[28] as u32;
    if w == 0 || h == 0 {
        return Err(Error(93));
    }
    if decoder.check_crc {
        let crc = lodepng_read32bit_int(&inp[29..]);
        let checksum = lodepng_crc32(&inp[12..(12 + 17)]);
        if crc != checksum {
            return Err(Error(57));
        };
    }
    if info_png.compression_method != 0 {
        /*error: only compression method 0 is allowed in the specification*/
        return Err(Error(32));
    }
    if info_png.filter_method != 0 {
        /*error: only filter method 0 is allowed in the specification*/
        return Err(Error(33));
    }
    if info_png.interlace_method > 1 {
        /*error: only interlace methods 0 and 1 exist in the specification*/
        return Err(Error(34));
    }
    check_png_color_validity(
        info_png.color.colortype,
        info_png.color.bitdepth(),
    )?;
    Ok((info_png, w, h))
}
pub ( crate ) fn lodepng_inspect ( decoder : & DecoderSettings , inp : & [ u8 ] , ) -> Result < ( Info , u32 , u32 ) , Error > { if inp . len ( ) < 33 { /*error: the data length is smaller than the length of a PNG header*/ return Err ( Error ( 27 ) ) ; } /*when decoding a new PNG image, make sure all parameters created after previous decoding are reset*/ let mut info_png = Info :: new ( ) ; if inp [ 0 .. 8 ] != [ 137 , 80 , 78 , 71 , 13 , 10 , 26 , 10 ] { /*error: the first 8 bytes are not the correct PNG signature*/ return Err ( Error ( 28 ) ) ; } if lodepng_chunk_length ( & inp [ 8 .. ] ) != 13 { /*error: header size must be 13 bytes*/ return Err ( Error ( 94 ) ) ; } if lodepng_chunk_type ( & inp [ 8 .. ] ) != b" " { /*error: it doesn't start with a IHDR chunk!*/ return Err ( Error ( 29 ) ) ; } /*read the values given in the header*/ let w = lodepng_read32bit_int ( & inp [ 16 .. ] ) ; let h = lodepng_read32bit_int ( & inp [ 20 .. ] ) ; let bitdepth = inp [ 24 ] ; if bitdepth == 0 || bitdepth > 16 { return Err ( Error ( 29 ) ) ; } info_png . color . set_bitdepth ( inp [ 24 ] as u32 ) ; info_png . color . colortype = match inp [ 25 ] { 0 => ColorType :: Grey , 2 => ColorType :: Rgb , 3 => ColorType :: Palette , 4 => ColorType :: GreyAlpha , 6 => ColorType :: Rgba , _ => return Err ( Error ( 31 ) ) , } ; info_png . compression_method = inp [ 26 ] as u32 ; info_png . filter_method = inp [ 27 ] as u32 ; info_png . interlace_method = inp [ 28 ] as u32 ; if w == 0 || h == 0 { return Err ( Error ( 93 ) ) ; } if decoder . check_crc { let crc = lodepng_read32bit_int ( & inp [ 29 .. ] ) ; let checksum = lodepng_crc32 ( & inp [ 12 .. ( 12 + 17 ) ] ) ; if crc != checksum { return Err ( Error ( 57 ) ) ; } ; } if info_png . compression_method != 0 { /*error: only compression method 0 is allowed in the specification*/ return Err ( Error ( 32 ) ) ; } if info_png . filter_method != 0 { /*error: only filter method 0 is allowed in the specification*/ return Err ( Error ( 33 ) ) ; } if info_png . interlace_method > 1 { /*error: only interlace methods 0 and 1 exist in the specification*/ return Err ( Error ( 34 ) ) ; } check_png_color_validity ( info_png . color . colortype , info_png . color . bitdepth ( ) , ) ? ; Ok ( ( info_png , w , h ) ) }
read the information from the header and store it in the Info.
read the information from the header and store it in the Info .
decoder
&DecoderSettings
inp
&[u8]