pub fn derive_from_png(
		id: &str,
		png_data: Vec<u8>,
		config: &VeraPaletteLoadConfig,
	) -> Result<Self, Error> {
		let decoder = png::Decoder::new(&*png_data);
		let (dec_info, mut reader) = decoder.read_info()?;
		let info = reader.info();
		if info.bit_depth == png::BitDepth::Sixteen {
			return Err(
				ErrorKind::PNGInvalid(format!("PNG must be 8 bit color depth or less")).into(),
			);
		}

		let reader_step = info.color_type.samples();

		debug!("Palette load: Decoded PNG Info: {:?}", info);
		let (step, buf) = match info.palette.clone() {
			Some(p) => {
				info!("Creating new palette from image palette");
				(3, p)
			}
			None => {
				info!("Creating new palette from image data");
				let mut buf = vec![0; dec_info.buffer_size()];
				reader.next_frame(&mut buf)?;
				(reader_step, buf)
			}
		};

		let mut palette = match config.include_defaults {
			true => VeraPalette::blank_with_defaults(id),
			false => VeraPalette::blank(id),
		};

		// if creating a new palette, pass through the image data adding all palette
		// entries until we're done or we can't anymore
		for i in (0..buf.len()).step_by(step) {
			palette.add_entry(config.direct_load, buf[i], buf[i + 1], buf[i + 2])?;
		}
		if config.sort {
			palette.sort();
		}
		info!("Palette creation successful");
		Ok(palette)
	}
/// Derives a palette from the given png image
/// this will fail if the image > 254 distinct RGB or index values
Derives a palette from the given png image
this will fail if the image > 254 distinct RGB or index values
Derives a palette from the given png image this will fail if the image > 254 distinct RGB or index values
pub fn derive_from_png(
		id: &str,
		png_data: Vec<u8>,
		config: &VeraPaletteLoadConfig,
	) -> Result<Self, Error> {
		let decoder = png::Decoder::new(&*png_data);
		let (dec_info, mut reader) = decoder.read_info()?;
		let info = reader.info();
		if info.bit_depth == png::BitDepth::Sixteen {
			return Err(
				ErrorKind::PNGInvalid(format!("PNG must be 8 bit color depth or less")).into(),
			);
		}
		let reader_step = info.color_type.samples();
		debug!("Palette load: Decoded PNG Info: {:?}", info);
		let (step, buf) = match info.palette.clone() {
			Some(p) => {
				info!("Creating new palette from image palette");
				(3, p)
			}
			None => {
				info!("Creating new palette from image data");
				let mut buf = vec![0; dec_info.buffer_size()];
				reader.next_frame(&mut buf)?;
				(reader_step, buf)
			}
		};
		let mut palette = match config.include_defaults {
			true => VeraPalette::blank_with_defaults(id),
			false => VeraPalette::blank(id),
		};
		// if creating a new palette, pass through the image data adding all palette
		// entries until we're done or we can't anymore
		for i in (0..buf.len()).step_by(step) {
			palette.add_entry(config.direct_load, buf[i], buf[i + 1], buf[i + 2])?;
		}
		if config.sort {
			palette.sort();
		}
		info!("Palette creation successful");
		Ok(palette)
	}
pub fn derive_from_png ( id : & str , png_data : Vec < u8 > , config : & VeraPaletteLoadConfig , ) -> Result < Self , Error > { let decoder = png :: Decoder :: new ( & * png_data ) ; let ( dec_info , mut reader ) = decoder . read_info ( ) ? ; let info = reader . info ( ) ; if info . bit_depth == png :: BitDepth :: Sixteen { return Err ( ErrorKind :: PNGInvalid ( format ! ( " " ) ) . into ( ) , ) ; } let reader_step = info . color_type . samples ( ) ; debug ! ( " " info ) ; let ( step , buf ) = match info . palette . clone ( ) { Some ( p ) => { info ! ( " " ) ; ( 3 , p ) } None => { info ! ( " " ) ; let mut buf = vec ! [ 0 dec_info buffer_size ( ) ] ; reader . next_frame ( & mut buf ) ? ; ( reader_step , buf ) } } ; let mut palette = match config . include_defaults { true => VeraPalette :: blank_with_defaults ( id ) , false => VeraPalette :: blank ( id ) , } ; // if creating a new palette, pass through the image data adding all palette // entries until we're done or we can't anymore for i in ( 0 .. buf . len ( ) ) . step_by ( step ) { palette . add_entry ( config . direct_load , buf [ i ] , buf [ i + 1 ] , buf [ i + 2 ] ) ? ; } if config . sort { palette . sort ( ) ; } info ! ( " " ) ; Ok ( palette ) }
Derives a palette from the given png image
this will fail if the image > 254 distinct RGB or index values
Derives a palette from the given png image this will fail if the image > 254 distinct RGB or index values
id
&str
png_data
Vec<u8>
config
&VeraPaletteLoadConfig