Thread: floodfill algorithm

  1. #1
    Registered User Sunny's Avatar
    Join Date
    Nov 2001
    Posts
    101

    floodfill algorithm

    hi folks.

    I'm not very experienced when it comes to writing my own graphics routines and functions, and i'm not going to ask you guys to answer me point-blank ( Allthough that would be nice ).
    I'm writing some graphics routines in assembly with BC 3.1 compiler. Im sure at least one of you has fiddled with paint or any graphics program till now. And i'm sure you've noticed the "Bucket" tool or whatever you used to use to fill in a big area of the screen. Now, my question is if anyone knows that algorithm , and if it involves more than just plotting one pixel.
    I've been trying day & night to crack it .....

    This would certainly come in handy for us....


    Take care,
    Stef
    Yes...YES!!! I did it! Ha ha ha...I'm king of the world...No..No..please-wait-no...!!!!-- This program has performed an illegal operation AND WILL be shut down....Ack-Choking..help...ack..

  2. #2
    Unregistered
    Guest
    there is a standard floodfill algorithm which u can find in any C graphics book. its called floddfill algo and deals with plotting pixels of same intensity with a new color

  3. #3
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    A common filling algorithm is a recursive 4/8 connect one:

    Code:
    void fillFourConnect (int x, int y, int col)
    {
       int thisColour = *(0xA0000000L + x + (y * X_ROW_SIZE));
       // Get this pixel^
    
       *(0xA0000000L + x + (y * X_ROW_SIZE)) = col; // Change pixel.
    
       if (*(0xA0000000L + x + 1 + (y * X_ROW_SIZE)) == thisColour)
          fillFourConnect (x + 1, y, col);
    
       if (*(0xA0000000L + x - 1 + (y * X_ROW_SIZE)) == thisColour)
          fillFourConnect (x - 1, y, col);
    
       if (*(0xA0000000L + x + ((y + 1) * X_ROW_SIZE)) == thisColour)
          fillFourConnect (x, y + 1, col);
    
       if (*(0xA0000000L + x + ((y - 1) * X_ROW_SIZE)) == thisColour)
          fillFourConnect (x, y - 1, col);
    }
    *(0xA0000000L + x + ((y + 1) * X_ROW_SIZE))
    is just a low level way of accessing the video buffer, feel free to use any method you choose. This method only works in mode 0x13 (standard VGA) anyway.

    It's recursive (but easy) so it may put strain on your stack. Beware.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Implement of a Fast Time Series Evaluation Algorithm
    By BiGreat in forum C Programming
    Replies: 7
    Last Post: 12-04-2007, 02:30 AM
  2. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM