pub fn load_font_image(data: &[u8], format: ImageFormat) -> Result<FontData> {
    let font_image =
        image::load_from_memory_with_format(data, format).map_err(|_| Error::BadFont)?;
    let dimensions = font_image.dimensions();
    let font_rgba = font_image.to_rgba8();
    let font_data = font_rgba.as_bytes();
    let data_u32: &[u32] = cast_slice(font_data);
    let char_width = dimensions.0 / 16;
    let char_height = dimensions.1 / 16;
    if char_width == 0 || char_height == 0 {
        return Err(Error::BadFont);
    }

    Ok(FontData {
        width: char_width,
        height: char_height,
        data: Vec::from(data_u32),
    })
}
/// Load a font from a given image in a byte array and generate a FontData
/// structure.
///
/// # Arguments
///
/// * __data__ - byte array that contains the image data.  You can use the
///   `include_bytes!` macro to generate this from a file at compile time.
/// * __format__ - The image::ImageFormat enum that declares the file format the
///   image data is in.
///
/// # Notes
///
/// This function will assume that the image contains 256 characters in a 16x16
/// grid of equally sized cells.
Load a font from a given image in a byte array and generate a FontData
structure.
Load a font from a given image in a byte array and generate a FontData structure .
pub fn load_font_image(data: &[u8], format: ImageFormat) -> Result<FontData> {
    let font_image =
        image::load_from_memory_with_format(data, format).map_err(|_| Error::BadFont)?;
    let dimensions = font_image.dimensions();
    let font_rgba = font_image.to_rgba8();
    let font_data = font_rgba.as_bytes();
    let data_u32: &[u32] = cast_slice(font_data);
    let char_width = dimensions.0 / 16;
    let char_height = dimensions.1 / 16;
    if char_width == 0 || char_height == 0 {
        return Err(Error::BadFont);
    }
    Ok(FontData {
        width: char_width,
        height: char_height,
        data: Vec::from(data_u32),
    })
}
pub fn load_font_image ( data : & [ u8 ] , format : ImageFormat ) -> Result < FontData > { let font_image = image :: load_from_memory_with_format ( data , format ) . map_err ( | _ | Error :: BadFont ) ? ; let dimensions = font_image . dimensions ( ) ; let font_rgba = font_image . to_rgba8 ( ) ; let font_data = font_rgba . as_bytes ( ) ; let data_u32 : & [ u32 ] = cast_slice ( font_data ) ; let char_width = dimensions . 0 / 16 ; let char_height = dimensions . 1 / 16 ; if char_width == 0 || char_height == 0 { return Err ( Error :: BadFont ) ; } Ok ( FontData { width : char_width , height : char_height , data : Vec :: from ( data_u32 ) , } ) }
Load a font from a given image in a byte array and generate a FontData
structure.
Load a font from a given image in a byte array and generate a FontData structure .
data
&[u8]
format
ImageFormat
data
&[u8]
format
ImageFormat
notes
This function will assume that the image contains 256 characters in a 16x16
grid of equally sized cells.
This function will assume that the image contains 256 characters in a 16x16 grid of equally sized cells .