// Translate the color values to 8-bit RGB, but scaled down by a
// factor of 1/`ratio`. Each pixel value will be calculated by
// averaging a `ratio` by `ratio` square of pixels.
Translate the color values to 8-bit RGB, but scaled down by a
factor of 1/`ratio`. Each pixel value will be calculated by
averaging a `ratio` by `ratio` square of pixels.
Translate the color values to 8 - bit RGB but scaled down by a factor of 1 / ` ratio ` . Each pixel value will be calculated by averaging a ` ratio ` by ` ratio ` square of pixels .
fn to_rgb8_scaled(&self, ratio: usize) -> (usize, usize, Vec<u8>) {
        let pix_lines = self.dims.ypix / ratio;
        let pix_cols = self.dims.xpix / ratio;
        let n_pix = pix_lines * pix_cols;
        let mut rgb8_data: Vec<u8> = Vec::with_capacity(n_pix * 3);
        let mut palette: [RGB; SCALE_PALETTE_SIZE] = [RGB::BLACK; SCALE_PALETTE_SIZE];
        for yi in 0..pix_lines {
            let base_offs = yi * self.dims.xpix * ratio;
            for xi in 0..pix_cols {
                let offs = base_offs + (xi * ratio);
                let mut pp = 0usize;
                for y in 0..ratio {
                    let po = offs + (self.dims.xpix * y);
                    for x in 0..ratio {
                        palette[pp] = self.data[po + x];
                        pp += 1;
                    }
                }
                let avg_p = RGB::average(&palette[0..pp]);
                for b in avg_p.to_rgb8().iter() {
                    rgb8_data.push(*b);
                }
            }
        }
        (pix_cols, pix_lines, rgb8_data)
    }
fn to_rgb8_scaled ( & self , ratio : usize ) -> ( usize , usize , Vec < u8 > ) { let pix_lines = self . dims . ypix / ratio ; let pix_cols = self . dims . xpix / ratio ; let n_pix = pix_lines * pix_cols ; let mut rgb8_data : Vec < u8 > = Vec :: with_capacity ( n_pix * 3 ) ; let mut palette : [ RGB ; SCALE_PALETTE_SIZE ] = [ RGB :: BLACK ; SCALE_PALETTE_SIZE ] ; for yi in 0 .. pix_lines { let base_offs = yi * self . dims . xpix * ratio ; for xi in 0 .. pix_cols { let offs = base_offs + ( xi * ratio ) ; let mut pp = 0usize ; for y in 0 .. ratio { let po = offs + ( self . dims . xpix * y ) ; for x in 0 .. ratio { palette [ pp ] = self . data [ po + x ] ; pp += 1 ; } } let avg_p = RGB :: average ( & palette [ 0 .. pp ] ) ; for b in avg_p . to_rgb8 ( ) . iter ( ) { rgb8_data . push ( * b ) ; } } } ( pix_cols , pix_lines , rgb8_data ) }
Translate the color values to 8-bit RGB, but scaled down by a
factor of 1/`ratio`.
Translate the color values to 8 - bit RGB but scaled down by a factor of 1 / ` ratio ` .
&self
ratio
usize