Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 314895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:14:30+00:00 2026-05-12T08:14:30+00:00

I have been using a floodfill algorithm of the stack-based non-recursive variety and it

  • 0

I have been using a floodfill algorithm of the stack-based non-recursive variety and it seems to work perfectly except for one annoying situation: if use a line to cut an image in half and then floodfill one half, it floods the whole image! This only happens, however, when I do not put ‘borders’ around the image. If i draw a rectangle that encapsulates the image (i.e put borders on the image) then it works fine. So obviously there is something wrong with the boundary finding aspect of the code, but i cannot for the life of me find the problem. Can someone with (hopefully) a keener eye than me spot the problem? it’s driving me crazy! (p.s the language is C)

/** scanfill algorithm **/
/* the stack */
#define stackSize 16777218
int stack[stackSize];
int stackPointer;

static bool
pop(int * x, int * y, int h) 
{ 
    if(stackPointer > 0) 
    { 
        int p = stack[stackPointer]; 
        *x = p / h; 
        *y = p % h; 
        stackPointer--; 
        return true; 
    }     
    else 
    { 
        return false;
    }    
}    

static bool
push(int x, int y, int h) 
{ 
    if(stackPointer < stackSize - 1) 
    { 
        stackPointer++; 
        stack[stackPointer] = h * x + y; 
        return true;
    }     
    else 
    { 
        return false;
    }    
}     

static void
emptyStack() 
{ 
    int x, y; 
    while(pop(&x, &y, 0)); 
}

void
scan_fill_do_action(int x, int y, texture_info * tex, VALUE hash_arg,
                sync sync_mode, bool primary, action_struct * payload)
{
    action_struct cur;
    rgba old_color;
    int y1;
    bool spanLeft, spanRight;

    if(!bound_by_rect(x, y, 0, 0, tex->width - 1, tex->height - 1)) return;

    draw_prologue(&cur, tex, 0, 0, 1024, 1024, &hash_arg, sync_mode, primary, &payload);

    old_color = get_pixel_color(tex, x, y);

    if(cmp_color(old_color, cur.color)) return;

    emptyStack();

    if(!push(x, y, tex->width)) return;

    while(pop(&x, &y, tex->width))
    {    
        y1 = y;
        while(y1 >= 0 && cmp_color(old_color, get_pixel_color(tex, x, y1))) y1--;
        y1++;
        spanLeft = spanRight = false;
        while(y1 < tex->height  && cmp_color(old_color, get_pixel_color(tex, x, y1)) )
            {
                set_pixel_color_with_style(payload, tex, x, y1);

                if(!spanLeft && x > 0 && cmp_color(old_color, get_pixel_color(tex, x - 1, y1))) 
                    {
                        if(!push(x - 1, y1, tex->width)) return;
                        spanLeft = true;
                    }
                else if(spanLeft && x > 0 && !cmp_color(old_color, get_pixel_color(tex, x - 1, y1)))
                    {
                        spanLeft = false;
                    }


                if(!spanRight && x < tex->width && cmp_color(old_color,
                                                                 get_pixel_color(tex, x + 1, y1))) 
                    {
                        if(!push(x + 1, y1, tex->width)) return;
                        spanRight = true;
                    }

                else if(spanRight && x < tex->width && !cmp_color(old_color,
                                                                      get_pixel_color(tex, x + 1, y1)))
                    {
                        spanRight = false;
                    } 
                y1++;
            }
    }
   draw_epilogue(&cur, tex, primary);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:14:30+00:00Added an answer on May 12, 2026 at 8:14 am

    I did only have a short glance at it, but it seems you have a boundary wrap at

    if(!spanRight && x < tex->width && ...
    

    ´and

    else if(spanRight && x < tex->width && ...
    

    The lines should read

       if(!spanRight && x < tex->width-1 && ...
       else if(spanRight && x < tex->width-1 && ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 173k
  • Answers 173k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The table will usually create and use a few cells… May 12, 2026 at 2:36 pm
  • Editorial Team
    Editorial Team added an answer You can't, not with vanilla Lucene. You said yourself that… May 12, 2026 at 2:36 pm
  • Editorial Team
    Editorial Team added an answer I don't believe this is handled directly for you. What… May 12, 2026 at 2:36 pm

Related Questions

I have been using a lot of position:relative; in my design, I just find
I have been using a reset CSS set of styles for quite some time
I have been using a class to play sounds using AVAudioPlayer. Since I want
I have been using a noscript tag to show a warning when users have

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.