fn trans_from_slice (&self, image_data: &[Color], width: u32, height: u32, cod: &str, a: f32, b:i32) -> Vec<Color> {
        let image_buffer = unsafe {
            slice::from_raw_parts(image_data.as_ptr() as *const u8, 4 * image_data.len())
        };
        let mut imgbuf : image::ImageBuffer<image::Rgba<u8>, _> = image::ImageBuffer::from_raw(width as u32, height as u32, image_buffer.to_vec()).unwrap();
        let vec_image_buffer:Vec<u8> = image::ImageBuffer::into_raw ( 
            match cod {
            
             "blur"            => image::imageops::blur(&imgbuf,a),
             "unsharpen"       => image::imageops::unsharpen(&imgbuf,a,10),
             "flip_vertical"   => image::imageops::flip_vertical(&imgbuf),
             "flip_horizontal" => image::imageops::flip_horizontal(&imgbuf),
             "rotate90"        => image::imageops::rotate90(&imgbuf),
             "rotate"          => self.rotate_center(&imgbuf, a as f32 * PI/180.0),
             "brighten"        => image::imageops::colorops::brighten(&imgbuf, 10),
             "darken"          => image::imageops::colorops::brighten(&imgbuf, -10),
             "contrast"        => image::imageops::colorops::contrast(&imgbuf, a),
             "invert"          => {image::imageops::colorops::invert(&mut imgbuf);
                                    imgbuf},
             "grayscale"       => self.gray2rgba(image::imageops::colorops::grayscale(&imgbuf),
                                            1.2,1.2,1.2),
             "resize"          => { 
                                    self.image.borrow_mut().clear();
                                    image::imageops::resize(&imgbuf,a as u32,b as u32,image::FilterType::Nearest)
                                    },
             "edge"            => {let kernel = [-1.0f32, -1.0, -1.0,
                                                 -1.0, 8.0, -1.0,
                                                 -1.0, -1.0, -1.0];
                                image::imageops::filter3x3(&imgbuf,&kernel);
                                imgbuf
                                },
                             _ => imgbuf,
         });
        
        //convert rgba u8 image buffer back into Color slice
        let flg = self.mask_flag.get();
        let mut i = 0 ;
        let mut r: u8 ;
        let mut g: u8 ;
        let mut b: u8 ;
        let mut a: u8 ;
        let mut new_slice = Vec::new();
        while i <= vec_image_buffer.len() - 4 {
            r = vec_image_buffer[i];
            g = vec_image_buffer[i+1];
            b = vec_image_buffer[i+2];
            a = vec_image_buffer[i+3];
            new_slice.push(Color::rgba(b, g, r, a)); //taking care of byte order
            i += 4;
        }
        new_slice
    }
/// apply some transformation to an image slice
apply some transformation to an image slice
apply some transformation to an image slice
fn trans_from_slice (&self, image_data: &[Color], width: u32, height: u32, cod: &str, a: f32, b:i32) -> Vec<Color> {
        let image_buffer = unsafe {
            slice::from_raw_parts(image_data.as_ptr() as *const u8, 4 * image_data.len())
        };
        let mut imgbuf : image::ImageBuffer<image::Rgba<u8>, _> = image::ImageBuffer::from_raw(width as u32, height as u32, image_buffer.to_vec()).unwrap();
        let vec_image_buffer:Vec<u8> = image::ImageBuffer::into_raw ( 
            match cod {
             "blur"            => image::imageops::blur(&imgbuf,a),
             "unsharpen"       => image::imageops::unsharpen(&imgbuf,a,10),
             "flip_vertical"   => image::imageops::flip_vertical(&imgbuf),
             "flip_horizontal" => image::imageops::flip_horizontal(&imgbuf),
             "rotate90"        => image::imageops::rotate90(&imgbuf),
             "rotate"          => self.rotate_center(&imgbuf, a as f32 * PI/180.0),
             "brighten"        => image::imageops::colorops::brighten(&imgbuf, 10),
             "darken"          => image::imageops::colorops::brighten(&imgbuf, -10),
             "contrast"        => image::imageops::colorops::contrast(&imgbuf, a),
             "invert"          => {image::imageops::colorops::invert(&mut imgbuf);
                                    imgbuf},
             "grayscale"       => self.gray2rgba(image::imageops::colorops::grayscale(&imgbuf),
                                            1.2,1.2,1.2),
             "resize"          => { 
                                    self.image.borrow_mut().clear();
                                    image::imageops::resize(&imgbuf,a as u32,b as u32,image::FilterType::Nearest)
                                    },
             "edge"            => {let kernel = [-1.0f32, -1.0, -1.0,
                                                 -1.0, 8.0, -1.0,
                                                 -1.0, -1.0, -1.0];
                                image::imageops::filter3x3(&imgbuf,&kernel);
                                imgbuf
                                },
                             _ => imgbuf,
         });
        //convert rgba u8 image buffer back into Color slice
        let flg = self.mask_flag.get();
        let mut i = 0 ;
        let mut r: u8 ;
        let mut g: u8 ;
        let mut b: u8 ;
        let mut a: u8 ;
        let mut new_slice = Vec::new();
        while i <= vec_image_buffer.len() - 4 {
            r = vec_image_buffer[i];
            g = vec_image_buffer[i+1];
            b = vec_image_buffer[i+2];
            a = vec_image_buffer[i+3];
            new_slice.push(Color::rgba(b, g, r, a)); //taking care of byte order
            i += 4;
        }
        new_slice
    }
fn trans_from_slice ( & self , image_data : & [ Color ] , width : u32 , height : u32 , cod : & str , a : f32 , b : i32 ) -> Vec < Color > { let image_buffer = unsafe { slice :: from_raw_parts ( image_data . as_ptr ( ) as * const u8 , 4 * image_data . len ( ) ) } ; let mut imgbuf : image :: ImageBuffer < image :: Rgba < u8 > , _ > = image :: ImageBuffer :: from_raw ( width as u32 , height as u32 , image_buffer . to_vec ( ) ) . unwrap ( ) ; let vec_image_buffer : Vec < u8 > = image :: ImageBuffer :: into_raw ( match cod { " " => image :: imageops :: blur ( & imgbuf , a ) , " " => image :: imageops :: unsharpen ( & imgbuf , a , 10 ) , " " => image :: imageops :: flip_vertical ( & imgbuf ) , " " => image :: imageops :: flip_horizontal ( & imgbuf ) , " " => image :: imageops :: rotate90 ( & imgbuf ) , " " => self . rotate_center ( & imgbuf , a as f32 * PI / 180.0 ) , " " => image :: imageops :: colorops :: brighten ( & imgbuf , 10 ) , " " => image :: imageops :: colorops :: brighten ( & imgbuf , - 10 ) , " " => image :: imageops :: colorops :: contrast ( & imgbuf , a ) , " " => { image :: imageops :: colorops :: invert ( & mut imgbuf ) ; imgbuf } , " " => self . gray2rgba ( image :: imageops :: colorops :: grayscale ( & imgbuf ) , 1.2 , 1.2 , 1.2 ) , " " => { self . image . borrow_mut ( ) . clear ( ) ; image :: imageops :: resize ( & imgbuf , a as u32 , b as u32 , image :: FilterType :: Nearest ) } , " " => { let kernel = [ - 1.0f32 , - 1.0 , - 1.0 , - 1.0 , 8.0 , - 1.0 , - 1.0 , - 1.0 , - 1.0 ] ; image :: imageops :: filter3x3 ( & imgbuf , & kernel ) ; imgbuf } , _ => imgbuf , } ) ; //convert rgba u8 image buffer back into Color slice let flg = self . mask_flag . get ( ) ; let mut i = 0 ; let mut r : u8 ; let mut g : u8 ; let mut b : u8 ; let mut a : u8 ; let mut new_slice = Vec :: new ( ) ; while i <= vec_image_buffer . len ( ) - 4 { r = vec_image_buffer [ i ] ; g = vec_image_buffer [ i + 1 ] ; b = vec_image_buffer [ i + 2 ] ; a = vec_image_buffer [ i + 3 ] ; new_slice . push ( Color :: rgba ( b , g , r , a ) ) ; //taking care of byte order i += 4 ; } new_slice }
apply some transformation to an image slice
apply some transformation to an image slice
&self
image_data
&[Color]
width
u32
height
u32
cod
&str
a
f32
b
i32
&self
image_data
&[Color]
width
u32
height
u32
cod
&str
a
f32
b
i32