1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
void FloodFill(Point s, ALLEGRO_COLOR newClr)
{
ALLEGRO_COLOR oldClr = al_get_pixel(aBMP,s.X,s.Y);
if (oldClr.r == newClr.r &&
oldClr.g == newClr.g &&
oldClr.b == newClr.b &&
oldClr.a == newClr.a) { return; }
stack<Point> ptsCollection;
ptsCollection.push(s);
al_draw_pixel(s.X,s.Y,newClr);
while (!ptsCollection.empty())
{
Point nPt = ptsCollection.top();
ptsCollection.pop();
if (nPt.X > 0) ProcessPoint(ptsCollection, nPt.X-1, nPt.Y, oldClr, newClr);
if (nPt.Y > 0) ProcessPoint(ptsCollection, nPt.X, nPt.Y-1, oldClr, newClr);
if (nPt.X < al_get_bitmap_width(aBMP)-1) ProcessPoint(ptsCollection, nPt.X+1, nPt.Y, oldClr, newClr);
if (nPt.Y < al_get_bitmap_height(aBMP)-1) ProcessPoint(ptsCollection, nPt.X,nPt.Y+1, oldClr, newClr);
}
}
void ProcessPoint(stack<Point> pts, int X, int Y, ALLEGRO_COLOR oClr, ALLEGRO_COLOR nClr)
{
ALLEGRO_COLOR tempClr = al_get_pixel(aBMP,X,Y);
if (tempClr.r == oClr.r &&
tempClr.g == oClr.g &&
tempClr.b == oClr.b &&
tempClr.a == oClr.a)
{
pts.push(Point(X,Y));
al_draw_pixel(X,Y,nClr);
}
}
|