Flood Fill Example In C

This flood fill code is adapted from a Tetris clone called "Tetanus On Drugs" by Damian Yerrick. It's licensed under the GNU Lesser General Public License (in addition to the GNU FDL that covers all of Wikipedia) and comes with ABSOLUTELY NO WARRANTY.
   #define BOARD_WIDTH  10   #define BOARD_HEIGHT 20      typedef struct MAP   {     unsigned char bBOARD_HEIGHTBOARD_WIDTH;   } MAP;      static void flood_loop(MAP *map, int x, int y,                          unsigned int dst_c, unsigned  int src_c)   {     int fillL, fillR, i;     int in_line = 1;     //unsigned char c = src_c, fillC = dst_c;       /* find left side, filling along the way */     fillL = fillR = x;     while( in_line )     {       map->byfillL = dst_c;       fillL--;       in_line = (fillL < 0) ? 0 : (map->byfillL == src_c);     }     fillL++;       /* find right side, filling along the way */     in_line = 1;     while( in_line )     {       map->byfillR = dst_c;       fillR++;       in_line = (fillR > BOARD_WIDTH-1) ? 0 : (map->byfillR == src_c);     }     fillR--;       /* search top and bottom */     for(i = fillL; i <= fillR; i++)     {       if( y > 0 && map->b- 1i == src_c )           flood_loop(map, i, y - 1, dst_c, src_c);       if( y < BOARD_HEIGHT && map->b+ 1i == src_c )           flood_loop(map, i, y + 1, dst_c, src_c);     }   }      void flood_fill(MAP *map, int x, int y, unsigned int c)   {     flood_loop(map, x, y, c, map->byx);     map->byx = c;  /* some buggy optimizers needed this line */   }   
This is the same algorithm adapted by Claudio Santana for the Java programming language:
   int checkPixel(int[] oldPix, int[] newPix)   {     return (newPix0 == oldPix0 &&     newPix1 == oldPix1	&&     newPix2 == oldPix2  &&     newPix3 == oldPix3 ? 1:0);   }     void floodLoop(WritableRaster raster, int x, int y, int[] fill, int[] old)   {     int fillL, fillR,i;     int in_line=1;     int[] aux =	{255,255,255,255};       // find left side, filling along the way     fillL = fillR = x;     while(in_line!=0)     {       int[] p = raster.getPixel(fillL,y,aux);       raster.setPixel(fillL,y,fill);       fillL--;       in_line = (fillL < 0) ? 0 : checkPixel(raster.getPixel(fillL,y,aux),old);     }     fillL++;       // find right side, filling along the way     in_line = 1;     while (in_line!=0)     {       raster.setPixel(fillR,y,fill);       fillR++;       in_line = (fillR > d.width-1) ? 0 : checkPixel(raster.getPixel(fillR,y,aux),old);     }     fillR--;       // look up and down     for( i=fillL; i<=fillR; i++ )     {       if ( y>0 && checkPixel(raster.getPixel(i,y-1,aux),old)!=0 )         floodLoop(raster,i,y-1,fill,old);       if ( y   }

 

<< PreviousWord BrowserNext >>
fucking ml
full disclosure
feminist theology
fsk
fictional guidebook
freeware
flat earth
persian language
farsi
frances abington
firewire
finite field
franchising
feynman diagram
food writing
futurama
final fantasy 3
francesco sforza
folk dance
fyodor dostoevsky
faith healing
furry
fritz lang
food and drug administration
field extension
flood fill
francis of assisi
frottage
first council of constantinople
fourth council of constantinople
friedrich hayek
gun
fred reed
fred brooks
factoid
figured bass
fashion
fourier transform
fat man
false claims act
u.s. false claims law (in depth)
fantastic four
filtration
follies