fn flood_fill_scanline( &self, x:i32, y:i32, new_color: u32, old_color:u32) {
        if old_color == new_color {
            return;
        }
        if self.pixcol(x,y).data  != old_color  {
            return;
        }
        
        let w = self.width() as i32;
        let h = self.height() as i32;
        
        //draw current scanline from start position to the right
        let mut x1 = x;
        
        while x1 < w && self.pixcol(x1,y).data  == old_color  {
            self.pixel(x1,y,Color{data:new_color});
            x1 +=1;
        } 
        //get resulted color because of transparency and use this for comparison 
        let res_color = self.pixcol(x,y).data;
        
        //draw current scanline from start position to the left
        x1 = x -1;
        
        while x1 >= 0 && self.pixcol(x1,y).data  == old_color  {
            self.pixel(x1,y,Color{data:new_color});
            x1 += -1;
          }
        
        //test for new scanlines above
        x1 = x;
        
        while x1 < w && self.pixcol(x1,y).data  == res_color  { 
            if y > 0 && self.pixcol(x1,y-1).data  == old_color  {
              self.flood_fill_scanline(x1, y - 1, new_color, old_color);
            }
            x1 += 1;
          }
        x1 = x - 1;
        while x1 >= 0 && self.pixcol(x1,y).data == res_color {
            if y > 0 && self.pixcol(x1,y - 1).data  == old_color  {
              self.flood_fill_scanline(x1, y - 1, new_color, old_color);
            }
            x1 += -1;
          }
         
         //test for new scanlines below
        x1 = x;
        while x1 < w && self.pixcol(x1,y).data == res_color  {
            //println!("Test below {} {} ", self.pixcol(x1,y).data,old_color);
            if y < (h - 1) && self.pixcol(x1,y + 1).data == old_color {
                self.flood_fill_scanline(x1, y + 1, new_color, old_color);
            }
            x1 +=1;
        }
        x1 = x - 1;
        while x1 >= 0 && self.pixcol(x1,y).data == res_color {
            if y < (h - 1) && self.pixcol(x1,y + 1).data == old_color {
                self.flood_fill_scanline(x1, y + 1, new_color, old_color);
            }
            x1 += -1;
        }
    }
///stack friendly and fast floodfill algorithm that works with transparency too 
stack friendly and fast floodfill algorithm that works with transparency too
stack friendly and fast floodfill algorithm that works with transparency too
fn flood_fill_scanline( &self, x:i32, y:i32, new_color: u32, old_color:u32) {
        if old_color == new_color {
            return;
        }
        if self.pixcol(x,y).data  != old_color  {
            return;
        }
        let w = self.width() as i32;
        let h = self.height() as i32;
        //draw current scanline from start position to the right
        let mut x1 = x;
        while x1 < w && self.pixcol(x1,y).data  == old_color  {
            self.pixel(x1,y,Color{data:new_color});
            x1 +=1;
        } 
        //get resulted color because of transparency and use this for comparison 
        let res_color = self.pixcol(x,y).data;
        //draw current scanline from start position to the left
        x1 = x -1;
        while x1 >= 0 && self.pixcol(x1,y).data  == old_color  {
            self.pixel(x1,y,Color{data:new_color});
            x1 += -1;
          }
        //test for new scanlines above
        x1 = x;
        while x1 < w && self.pixcol(x1,y).data  == res_color  { 
            if y > 0 && self.pixcol(x1,y-1).data  == old_color  {
              self.flood_fill_scanline(x1, y - 1, new_color, old_color);
            }
            x1 += 1;
          }
        x1 = x - 1;
        while x1 >= 0 && self.pixcol(x1,y).data == res_color {
            if y > 0 && self.pixcol(x1,y - 1).data  == old_color  {
              self.flood_fill_scanline(x1, y - 1, new_color, old_color);
            }
            x1 += -1;
          }
         //test for new scanlines below
        x1 = x;
        while x1 < w && self.pixcol(x1,y).data == res_color  {
            //println!("Test below {} {} ", self.pixcol(x1,y).data,old_color);
            if y < (h - 1) && self.pixcol(x1,y + 1).data == old_color {
                self.flood_fill_scanline(x1, y + 1, new_color, old_color);
            }
            x1 +=1;
        }
        x1 = x - 1;
        while x1 >= 0 && self.pixcol(x1,y).data == res_color {
            if y < (h - 1) && self.pixcol(x1,y + 1).data == old_color {
                self.flood_fill_scanline(x1, y + 1, new_color, old_color);
            }
            x1 += -1;
        }
    }
fn flood_fill_scanline ( & self , x : i32 , y : i32 , new_color : u32 , old_color : u32 ) { if old_color == new_color { return ; } if self . pixcol ( x , y ) . data != old_color { return ; } let w = self . width ( ) as i32 ; let h = self . height ( ) as i32 ; //draw current scanline from start position to the right let mut x1 = x ; while x1 < w && self . pixcol ( x1 , y ) . data == old_color { self . pixel ( x1 , y , Color { data : new_color } ) ; x1 += 1 ; } //get resulted color because of transparency and use this for comparison  let res_color = self . pixcol ( x , y ) . data ; //draw current scanline from start position to the left x1 = x - 1 ; while x1 >= 0 && self . pixcol ( x1 , y ) . data == old_color { self . pixel ( x1 , y , Color { data : new_color } ) ; x1 += - 1 ; } //test for new scanlines above x1 = x ; while x1 < w && self . pixcol ( x1 , y ) . data == res_color { if y > 0 && self . pixcol ( x1 , y - 1 ) . data == old_color { self . flood_fill_scanline ( x1 , y - 1 , new_color , old_color ) ; } x1 += 1 ; } x1 = x - 1 ; while x1 >= 0 && self . pixcol ( x1 , y ) . data == res_color { if y > 0 && self . pixcol ( x1 , y - 1 ) . data == old_color { self . flood_fill_scanline ( x1 , y - 1 , new_color , old_color ) ; } x1 += - 1 ; } //test for new scanlines below x1 = x ; while x1 < w && self . pixcol ( x1 , y ) . data == res_color { //println!("Test below {} {} ", self.pixcol(x1,y).data,old_color); if y < ( h - 1 ) && self . pixcol ( x1 , y + 1 ) . data == old_color { self . flood_fill_scanline ( x1 , y + 1 , new_color , old_color ) ; } x1 += 1 ; } x1 = x - 1 ; while x1 >= 0 && self . pixcol ( x1 , y ) . data == res_color { if y < ( h - 1 ) && self . pixcol ( x1 , y + 1 ) . data == old_color { self . flood_fill_scanline ( x1 , y + 1 , new_color , old_color ) ; } x1 += - 1 ; } }
stack friendly and fast floodfill algorithm that works with transparency too
stack friendly and fast floodfill algorithm that works with transparency too
&self
x
i32
y
i32
new_color
u32
old_color
u32
&self
x
i32
y
i32
new_color
u32
old_color
u32