//不能帮你做了,给你几个有用的函数自己看着办吧
struct stack
{
int x;
int y;
struct stack * next;
} mystack,*top;
void stackinit()
{
mystack.next=NULL;
top=&mystack;
}
void push(int x,int y)
{
struct stack *p=(struct stack*)malloc(sizeof(struct stack));
p->x=x;
p->y=y;
p->next=top->next;
top->next=p;
}
int pop(int *x,int *y)
{
struct stack *p=top->next;
if(p==NULL)
return 0;
*x=p->x;
*y=p->y;
top->next=top->next->next;
free(p);
return 1;
}
void floodfill4(int x,int y,int border,int color)
{
int x0,xr,xl,flag,xnextspan;
stackinit();
push(x,y); /*将种子像素x,y压入堆栈*/
while(pop(&x,&y)!=0)
{
putpixel(x,y,color);
x0=x+1;
while((getpixel(x0,y)!=border)&&(x0<=getmaxx())) /*填充右方像素*/
{
putpixel(x0,y,color);
x0=x0+1;
}
xr=x0-1;
/*最右边像素*/
x0=x-1;
while((getpixel(x0,y)!=border)&&(x0>0)) /*填充左方像素*/
{
putpixel(x0,y,color);
x0=x0-1;
}
xl=x0+1;
/*最左边像素*/
/*检查上一条扫描线,若存在非边界且未填充的像素,则选取代表各连续区间的种子像素入栈*/
if(y<getmaxy())
{
x0=xl;
y=y+1;
while(x0<=xr)
{
flag=0;
while((getpixel(x0,y)!=border)&&(getpixel(x0,y)!=color)&&(x0<xr))
{
if(flag==0)flag=1;
x0++;
}
if(flag==1)
{
if((x0==xr)&&(getpixel(x0,y)!=border)&&(getpixel(x0,y)!=color))
push(x0,y);
else
push(x0-1,y);
flag=0;
}
xnextspan=x0;
while(((getpixel(x0,y)==border)||(getpixel(x0,y)==color))&&(x0<xr))
x0++;
if(xnextspan==x0)x0++;
}/*while(x0<=xr)*/
}
/*检查下一条扫描线*/
if(y>1)
{
x0=xl;
y=y-2;
while(x0<=xr)
{
flag=0;
while((getpixel(x0,y)!=border)&&(getpixel(x0,y)!=color)&&(x0<xr))
{
if(flag==0)flag=1;
x0++;
}
if(flag==1)
{
if((x0==xr)&&(getpixel(x0,y)!=border)&&(getpixel(x0,y)!=color))
push(x0,y);
else
push(x0-1,y);
flag=0;
}
xnextspan=x0;
while(((getpixel(x0,y)==border)||(getpixel(x0,y)==color))&&(x0<xr))
x0++;
if(xnextspan==x0)x0++;
}/*while(x0<=xr)*/
}
}/*while像素栈非空*/
}