fn rgb_to_gray(rgb: &[u8]) -> Box<[u8]> {
    assert_eq!(rgb.len() % 3, 0);
    let num_pixels = rgb.len() / 3;
    let mut gray = Vec::with_capacity(num_pixels);
    for i in 0..num_pixels {
        let red = u32::from(rgb[3 * i]);
        let green = u32::from(rgb[3 * i + 1]);
        let blue = u32::from(rgb[3 * i + 2]);
        gray.push(((red + green + blue) / 3) as u8);
    }
    gray.into_boxed_slice()
}
/// Converts RGB image data into grayscale.
Converts RGB image data into grayscale.
Converts RGB image data into grayscale .
fn rgb_to_gray(rgb: &[u8]) -> Box<[u8]> {
    assert_eq!(rgb.len() % 3, 0);
    let num_pixels = rgb.len() / 3;
    let mut gray = Vec::with_capacity(num_pixels);
    for i in 0..num_pixels {
        let red = u32::from(rgb[3 * i]);
        let green = u32::from(rgb[3 * i + 1]);
        let blue = u32::from(rgb[3 * i + 2]);
        gray.push(((red + green + blue) / 3) as u8);
    }
    gray.into_boxed_slice()
}
fn rgb_to_gray ( rgb : & [ u8 ] ) -> Box < [ u8 ] > { assert_eq ! ( rgb len ( ) 3 0 ) ; let num_pixels = rgb . len ( ) / 3 ; let mut gray = Vec :: with_capacity ( num_pixels ) ; for i in 0 .. num_pixels { let red = u32 :: from ( rgb [ 3 * i ] ) ; let green = u32 :: from ( rgb [ 3 * i + 1 ] ) ; let blue = u32 :: from ( rgb [ 3 * i + 2 ] ) ; gray . push ( ( ( red + green + blue ) / 3 ) as u8 ) ; } gray . into_boxed_slice ( ) }
Converts RGB image data into grayscale.
Converts RGB image data into grayscale .
rgb
&[u8]
rgb
&[u8]