pub fn from_data(format: PixelFormat,
                     width: u32,
                     height: u32,
                     data: Vec<u8>)
                     -> io::Result<Image> {
        let data_bits = format.bits_per_pixel() * width * height;
        let data_bytes = ((data_bits + 7) / 8) as usize;
        if data.len() == data_bytes {
            Ok(Image {
                format: format,
                width: width,
                height: height,
                data: data.into_boxed_slice(),
            })
        } else {
            let msg = format!("incorrect pixel data array length for \
                               speicifed format and dimensions ({} instead \
                               of {})",
                              data.len(),
                              data_bytes);
            Err(io::Error::new(io::ErrorKind::InvalidInput, msg))
        }
    }
/// Creates a new image using the given pixel data.  Returns an error if
/// the data array is not the correct length.
Creates a new image using the given pixel data.  Returns an error if
the data array is not the correct length.
Creates a new image using the given pixel data . Returns an error if the data array is not the correct length .
pub fn from_data(format: PixelFormat,
                     width: u32,
                     height: u32,
                     data: Vec<u8>)
                     -> io::Result<Image> {
        let data_bits = format.bits_per_pixel() * width * height;
        let data_bytes = ((data_bits + 7) / 8) as usize;
        if data.len() == data_bytes {
            Ok(Image {
                format: format,
                width: width,
                height: height,
                data: data.into_boxed_slice(),
            })
        } else {
            let msg = format!("incorrect pixel data array length for \
                               speicifed format and dimensions ({} instead \
                               of {})",
                              data.len(),
                              data_bytes);
            Err(io::Error::new(io::ErrorKind::InvalidInput, msg))
        }
    }
pub fn from_data ( format : PixelFormat , width : u32 , height : u32 , data : Vec < u8 > ) -> io :: Result < Image > { let data_bits = format . bits_per_pixel ( ) * width * height ; let data_bytes = ( ( data_bits + 7 ) / 8 ) as usize ; if data . len ( ) == data_bytes { Ok ( Image { format : format , width : width , height : height , data : data . into_boxed_slice ( ) , } ) } else { let msg = format ! ( " \
 \
 " data len ( ) data_bytes ) ; Err ( io :: Error :: new ( io :: ErrorKind :: InvalidInput , msg ) ) } }
Creates a new image using the given pixel data.
Creates a new image using the given pixel data .
format
PixelFormat
width
u32
height
u32
data
Vec<u8>
format
PixelFormat
width
u32
height
u32
data
Vec<u8>