pub fn try_from<R: Read>(
        image_decoder: png::Decoder<R>,
    ) -> Result<(Self, Option<Self>), Error> {
        // Load image
        let mut image_reader = image_decoder.read_info().unwrap();
        // Allocate the output buffer.
        let mut buf = vec![0; image_reader.output_buffer_size()];
        // Read the next frame. An APNG might contain multiple frames.
        let info = image_reader.next_frame(&mut buf).unwrap();
        // Grab the bytes of the image.
        let image_data = Vec::from(&buf[..info.buffer_size()]);

        let mut color_type = info.color_type;
        let (image_color_data, alpha_data) = match info.color_type {
            ColorType::Rgba => {
                color_type = ColorType::Rgb;
                (
                    Self::rgba_to_rgb(&image_data),
                    Some(Self::rgba_to_a(&image_data)),
                )
            }
            ColorType::GrayscaleAlpha => {
                // TODO split alpha channel
                color_type = ColorType::Grayscale;
                (
                    Self::grayscale_alpha_to_grayscale(&image_data),
                    Some(Self::grayscale_alpha_to_grayscale(&image_data)),
                )
            }
            _ => (image_data, None),
        };

        Ok((
            Self {
                width: info.width,
                height: info.height,
                color_space: color_type,
                bits_per_component: info.bit_depth,
                image_data: image_color_data,
                interpolate: false,
                s_mask: None, // This should be filled in later
            },
            alpha_data.map(|alpha_data| Self {
                width: info.width,
                height: info.height,
                color_space: ColorType::Grayscale,
                bits_per_component: info.bit_depth,
                image_data: alpha_data,
                interpolate: false,
                s_mask: None,
            }),
        ))
    }
// TODO: remove `unwrap`s
/// Returns 1 or 2 images. The first is the color images.
/// The second is (if present) the mask/alpha channel of the image.
remove `unwrap`s
Returns 1 or 2 images. The first is the color images.
The second is (if present) the mask/alpha channel of the image.
remove ` unwrap ` s Returns 1 or 2 images . The first is the color images . The second is ( if present ) the mask / alpha channel of the image .
pub fn try_from<R: Read>(
        image_decoder: png::Decoder<R>,
    ) -> Result<(Self, Option<Self>), Error> {
        // Load image
        let mut image_reader = image_decoder.read_info().unwrap();
        // Allocate the output buffer.
        let mut buf = vec![0; image_reader.output_buffer_size()];
        // Read the next frame. An APNG might contain multiple frames.
        let info = image_reader.next_frame(&mut buf).unwrap();
        // Grab the bytes of the image.
        let image_data = Vec::from(&buf[..info.buffer_size()]);
        let mut color_type = info.color_type;
        let (image_color_data, alpha_data) = match info.color_type {
            ColorType::Rgba => {
                color_type = ColorType::Rgb;
                (
                    Self::rgba_to_rgb(&image_data),
                    Some(Self::rgba_to_a(&image_data)),
                )
            }
            ColorType::GrayscaleAlpha => {
                // TODO split alpha channel
                color_type = ColorType::Grayscale;
                (
                    Self::grayscale_alpha_to_grayscale(&image_data),
                    Some(Self::grayscale_alpha_to_grayscale(&image_data)),
                )
            }
            _ => (image_data, None),
        };
        Ok((
            Self {
                width: info.width,
                height: info.height,
                color_space: color_type,
                bits_per_component: info.bit_depth,
                image_data: image_color_data,
                interpolate: false,
                s_mask: None, // This should be filled in later
            },
            alpha_data.map(|alpha_data| Self {
                width: info.width,
                height: info.height,
                color_space: ColorType::Grayscale,
                bits_per_component: info.bit_depth,
                image_data: alpha_data,
                interpolate: false,
                s_mask: None,
            }),
        ))
    }
pub fn try_from < R : Read > ( image_decoder : png :: Decoder < R > , ) -> Result < ( Self , Option < Self > ) , Error > { // Load image let mut image_reader = image_decoder . read_info ( ) . unwrap ( ) ; // Allocate the output buffer. let mut buf = vec ! [ 0 image_reader output_buffer_size ( ) ] ; // Read the next frame. An APNG might contain multiple frames. let info = image_reader . next_frame ( & mut buf ) . unwrap ( ) ; // Grab the bytes of the image. let image_data = Vec :: from ( & buf [ .. info . buffer_size ( ) ] ) ; let mut color_type = info . color_type ; let ( image_color_data , alpha_data ) = match info . color_type { ColorType :: Rgba => { color_type = ColorType :: Rgb ; ( Self :: rgba_to_rgb ( & image_data ) , Some ( Self :: rgba_to_a ( & image_data ) ) , ) } ColorType :: GrayscaleAlpha => { // TODO split alpha channel color_type = ColorType :: Grayscale ; ( Self :: grayscale_alpha_to_grayscale ( & image_data ) , Some ( Self :: grayscale_alpha_to_grayscale ( & image_data ) ) , ) } _ => ( image_data , None ) , } ; Ok ( ( Self { width : info . width , height : info . height , color_space : color_type , bits_per_component : info . bit_depth , image_data : image_color_data , interpolate : false , s_mask : None , // This should be filled in later } , alpha_data . map ( | alpha_data | Self { width : info . width , height : info . height , color_space : ColorType :: Grayscale , bits_per_component : info . bit_depth , image_data : alpha_data , interpolate : false , s_mask : None , } ) , ) ) }
TODO: remove `unwrap`s
Returns 1 or 2 images.
TODO : remove ` unwrap ` s Returns 1 or 2 images .
image_decoder
png::Decoder<R>