pub fn from_encoding_config(
        data: &[u8],
        mut config: TextureOptions,
    ) -> Result<Self, TextureError> {
        let image = image::load_from_memory(data)?;

        config.width = image.width();
        config.height = image.height();
        config.source_format = TextureSourceFormat::RGBA;

        let image = match config.source_type {
            TextureSourceType::U8 => TextureData::U8(image.into_rgba8().into_raw()),
            TextureSourceType::U16 => TextureData::U16(image.into_rgba16().into_raw()),
            _ => {
                return Err(TextureError::BadDecodeFormat {
                    ty: config.source_type,
                })
            }
        };

        Ok(Texture { image, config })
    }
/// Loads an encoded image file, tries to detect what sort of file it is, for
/// details of the detection see [`image`]'s file detection.  This will
/// ignore the [`TextureOptions::width`], [`TextureOptions::height`] and
/// [`TextureOptions::source_format`] options provided and instead derives
/// them from the provided image data.
Loads an encoded image file, tries to detect what sort of file it is, for
details of the detection see [`image`]'s file detection.
Loads an encoded image file tries to detect what sort of file it is for details of the detection see [ ` image ` ] ' s file detection .
pub fn from_encoding_config(
        data: &[u8],
        mut config: TextureOptions,
    ) -> Result<Self, TextureError> {
        let image = image::load_from_memory(data)?;
        config.width = image.width();
        config.height = image.height();
        config.source_format = TextureSourceFormat::RGBA;
        let image = match config.source_type {
            TextureSourceType::U8 => TextureData::U8(image.into_rgba8().into_raw()),
            TextureSourceType::U16 => TextureData::U16(image.into_rgba16().into_raw()),
            _ => {
                return Err(TextureError::BadDecodeFormat {
                    ty: config.source_type,
                })
            }
        };
        Ok(Texture { image, config })
    }
pub fn from_encoding_config ( data : & [ u8 ] , mut config : TextureOptions , ) -> Result < Self , TextureError > { let image = image :: load_from_memory ( data ) ? ; config . width = image . width ( ) ; config . height = image . height ( ) ; config . source_format = TextureSourceFormat :: RGBA ; let image = match config . source_type { TextureSourceType :: U8 => TextureData :: U8 ( image . into_rgba8 ( ) . into_raw ( ) ) , TextureSourceType :: U16 => TextureData :: U16 ( image . into_rgba16 ( ) . into_raw ( ) ) , _ => { return Err ( TextureError :: BadDecodeFormat { ty : config . source_type , } ) } } ; Ok ( Texture { image , config } ) }
Loads an encoded image file, tries to detect what sort of file it is, for
details of the detection see [`image`]'s file detection.
Loads an encoded image file tries to detect what sort of file it is for details of the detection see [ ` image ` ] ' s file detection .
data
&[u8]
config
TextureOptions
data
&[u8]
config
TextureOptions