pub fn convert_to(&self, format: PixelFormat) -> Image {
        let new_data = match self.format {
            PixelFormat::RGBA => {
                match format {
                    PixelFormat::RGBA => self.data.clone(),
                    PixelFormat::RGB => rgba_to_rgb(&self.data),
                    PixelFormat::GrayAlpha => rgba_to_grayalpha(&self.data),
                    PixelFormat::Gray => rgba_to_gray(&self.data),
                    PixelFormat::Alpha => rgba_to_alpha(&self.data),
                }
            }
            PixelFormat::RGB => {
                match format {
                    PixelFormat::RGBA => rgb_to_rgba(&self.data),
                    PixelFormat::RGB => self.data.clone(),
                    PixelFormat::GrayAlpha => rgb_to_grayalpha(&self.data),
                    PixelFormat::Gray => rgb_to_gray(&self.data),
                    PixelFormat::Alpha => rgb_to_alpha(&self.data),
                }
            }
            PixelFormat::GrayAlpha => {
                match format {
                    PixelFormat::RGBA => grayalpha_to_rgba(&self.data),
                    PixelFormat::RGB => grayalpha_to_rgb(&self.data),
                    PixelFormat::GrayAlpha => self.data.clone(),
                    PixelFormat::Gray => grayalpha_to_gray(&self.data),
                    PixelFormat::Alpha => grayalpha_to_alpha(&self.data),
                }
            }
            PixelFormat::Gray => {
                match format {
                    PixelFormat::RGBA => gray_to_rgba(&self.data),
                    PixelFormat::RGB => gray_to_rgb(&self.data),
                    PixelFormat::GrayAlpha => gray_to_grayalpha(&self.data),
                    PixelFormat::Gray => self.data.clone(),
                    PixelFormat::Alpha => gray_to_alpha(&self.data),
                }
            }
            PixelFormat::Alpha => {
                match format {
                    PixelFormat::RGBA => alpha_to_rgba(&self.data),
                    PixelFormat::RGB => alpha_to_rgb(&self.data),
                    PixelFormat::GrayAlpha => alpha_to_grayalpha(&self.data),
                    PixelFormat::Gray => alpha_to_gray(&self.data),
                    PixelFormat::Alpha => self.data.clone(),
                }
            }
        };
        Image {
            format: format,
            width: self.width,
            height: self.height,
            data: new_data,
        }
    }
/// Creates a copy of this image by converting to the specified pixel
/// format.  This operation always succeeds, but may lose information (e.g.
/// converting from RGBA to RGB will silently drop the alpha channel).  If
/// the source image is already in the requested format, this is equivalant
/// to simply calling `clone()`.
Creates a copy of this image by converting to the specified pixel
format.  This operation always succeeds, but may lose information .  If
the source image is already in the requested format, this is equivalant
to simply calling `clone()`.
Creates a copy of this image by converting to the specified pixel format . This operation always succeeds but may lose information . If the source image is already in the requested format this is equivalant to simply calling ` clone () ` .
pub fn convert_to(&self, format: PixelFormat) -> Image {
        let new_data = match self.format {
            PixelFormat::RGBA => {
                match format {
                    PixelFormat::RGBA => self.data.clone(),
                    PixelFormat::RGB => rgba_to_rgb(&self.data),
                    PixelFormat::GrayAlpha => rgba_to_grayalpha(&self.data),
                    PixelFormat::Gray => rgba_to_gray(&self.data),
                    PixelFormat::Alpha => rgba_to_alpha(&self.data),
                }
            }
            PixelFormat::RGB => {
                match format {
                    PixelFormat::RGBA => rgb_to_rgba(&self.data),
                    PixelFormat::RGB => self.data.clone(),
                    PixelFormat::GrayAlpha => rgb_to_grayalpha(&self.data),
                    PixelFormat::Gray => rgb_to_gray(&self.data),
                    PixelFormat::Alpha => rgb_to_alpha(&self.data),
                }
            }
            PixelFormat::GrayAlpha => {
                match format {
                    PixelFormat::RGBA => grayalpha_to_rgba(&self.data),
                    PixelFormat::RGB => grayalpha_to_rgb(&self.data),
                    PixelFormat::GrayAlpha => self.data.clone(),
                    PixelFormat::Gray => grayalpha_to_gray(&self.data),
                    PixelFormat::Alpha => grayalpha_to_alpha(&self.data),
                }
            }
            PixelFormat::Gray => {
                match format {
                    PixelFormat::RGBA => gray_to_rgba(&self.data),
                    PixelFormat::RGB => gray_to_rgb(&self.data),
                    PixelFormat::GrayAlpha => gray_to_grayalpha(&self.data),
                    PixelFormat::Gray => self.data.clone(),
                    PixelFormat::Alpha => gray_to_alpha(&self.data),
                }
            }
            PixelFormat::Alpha => {
                match format {
                    PixelFormat::RGBA => alpha_to_rgba(&self.data),
                    PixelFormat::RGB => alpha_to_rgb(&self.data),
                    PixelFormat::GrayAlpha => alpha_to_grayalpha(&self.data),
                    PixelFormat::Gray => alpha_to_gray(&self.data),
                    PixelFormat::Alpha => self.data.clone(),
                }
            }
        };
        Image {
            format: format,
            width: self.width,
            height: self.height,
            data: new_data,
        }
    }
pub fn convert_to ( & self , format : PixelFormat ) -> Image { let new_data = match self . format { PixelFormat :: RGBA => { match format { PixelFormat :: RGBA => self . data . clone ( ) , PixelFormat :: RGB => rgba_to_rgb ( & self . data ) , PixelFormat :: GrayAlpha => rgba_to_grayalpha ( & self . data ) , PixelFormat :: Gray => rgba_to_gray ( & self . data ) , PixelFormat :: Alpha => rgba_to_alpha ( & self . data ) , } } PixelFormat :: RGB => { match format { PixelFormat :: RGBA => rgb_to_rgba ( & self . data ) , PixelFormat :: RGB => self . data . clone ( ) , PixelFormat :: GrayAlpha => rgb_to_grayalpha ( & self . data ) , PixelFormat :: Gray => rgb_to_gray ( & self . data ) , PixelFormat :: Alpha => rgb_to_alpha ( & self . data ) , } } PixelFormat :: GrayAlpha => { match format { PixelFormat :: RGBA => grayalpha_to_rgba ( & self . data ) , PixelFormat :: RGB => grayalpha_to_rgb ( & self . data ) , PixelFormat :: GrayAlpha => self . data . clone ( ) , PixelFormat :: Gray => grayalpha_to_gray ( & self . data ) , PixelFormat :: Alpha => grayalpha_to_alpha ( & self . data ) , } } PixelFormat :: Gray => { match format { PixelFormat :: RGBA => gray_to_rgba ( & self . data ) , PixelFormat :: RGB => gray_to_rgb ( & self . data ) , PixelFormat :: GrayAlpha => gray_to_grayalpha ( & self . data ) , PixelFormat :: Gray => self . data . clone ( ) , PixelFormat :: Alpha => gray_to_alpha ( & self . data ) , } } PixelFormat :: Alpha => { match format { PixelFormat :: RGBA => alpha_to_rgba ( & self . data ) , PixelFormat :: RGB => alpha_to_rgb ( & self . data ) , PixelFormat :: GrayAlpha => alpha_to_grayalpha ( & self . data ) , PixelFormat :: Gray => alpha_to_gray ( & self . data ) , PixelFormat :: Alpha => self . data . clone ( ) , } } } ; Image { format : format , width : self . width , height : self . height , data : new_data , } }
Creates a copy of this image by converting to the specified pixel
format.
Creates a copy of this image by converting to the specified pixel format .
&self
format
PixelFormat
&self
format
PixelFormat