Skip to content

Commit

Permalink
Remove unused floodfill
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed Sep 22, 2020
1 parent 4ac1cf3 commit e1f9eaa
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 211 deletions.
3 changes: 0 additions & 3 deletions SGE/include/SGE/sge_surface.h
Expand Up @@ -77,8 +77,6 @@ extern "C"
Uint32* ctab, int start, int stop);
DECLSPEC void sge_SetupRainbowPalette(SDL_Surface* Surface, Uint32* ctab, int intensity, int start, int stop);
DECLSPEC void sge_SetupBWPalette(SDL_Surface* Surface, Uint32* ctab, int start, int stop);

DECLSPEC void sge_FloodFill(SDL_Surface* dst, Sint16 x, Sint16 y, Uint32 color);
#ifdef _SGE_C
}
#endif
Expand All @@ -89,5 +87,4 @@ DECLSPEC void sge_PutPixel(SDL_Surface* surface, Sint16 x, Sint16 y, Uint8 R, Ui
DECLSPEC void _PutPixelAlpha(SDL_Surface* surface, Sint16 x, Sint16 y, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha);
DECLSPEC void sge_PutPixelAlpha(SDL_Surface* surface, Sint16 x, Sint16 y, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha);
DECLSPEC void sge_ClearSurface(SDL_Surface* Surface, Uint8 R, Uint8 G, Uint8 B);
DECLSPEC void sge_FloodFill(SDL_Surface* dst, Sint16 x, Sint16 y, Uint8 R, Uint8 G, Uint8 B);
#endif /* sge_C_ONLY */
208 changes: 0 additions & 208 deletions SGE/sge_surface.cpp
Expand Up @@ -725,211 +725,3 @@ void sge_SetupBWPalette(SDL_Surface* Surface, Uint32* ctab, int start, int stop)
{
sge_Fader(Surface, 0, 0, 0, 255, 255, 255, ctab, start, stop);
}

/**********************************************************************************/
/** Color filling functions **/
/**********************************************************************************/

//==================================================================================
// sge_FloodFill: Fast non-recursive flood fill
//
// Algorithm originally written by
// Paul Heckbert, 13 Sept 1982, 28 Jan 1987
//==================================================================================
/* horizontal segment of scan line y */
struct seg
{
Sint16 y, xl, xr, dy;
};

#define MAX 1000 /* max depth of stack */

//-V:PUSH:782
#define PUSH(Y, XL, XR, DY) \
{ \
if(sp < stack.end() && (Y) + (DY) >= sge_clip_ymin(dst) && (Y) + (DY) <= sge_clip_ymax(dst)) \
{ \
sp->y = Y; \
sp->xl = XL; \
sp->xr = XR; \
sp->dy = DY; \
sp++; \
} \
}

#define POP(Y, XL, XR, DY) \
{ \
sp--; \
(DY) = sp->dy; \
(Y) = sp->y + sp->dy; \
(XL) = sp->xl; \
(XR) = sp->xr; \
}

/*
* set the pixel at (x,y) and all of its 4-connected neighbors
* with the same pixel value to the new pixel color.
* A 4-connected neighbor is a pixel above, below, left, or right of a pixel.
*/
// First a generic (slow) version and then 8/16/32 bpp versions
static void _FloodFillX(SDL_Surface* dst, Sint16 x, Sint16 y, Uint32 color)
{
Sint16 l, x1, x2, dy;
Uint32 oc; /* old pixel color */
std::array<seg, MAX> stack;
auto* sp = stack.begin(); /* stack of filled segments */

if(x < sge_clip_xmin(dst) || x > sge_clip_xmax(dst) || y < sge_clip_ymin(dst) || y > sge_clip_ymax(dst))
return;

oc = sge_GetPixel(dst, x, y); /* read color at seed point */

if(oc == color)
return;

PUSH(y, x, x, 1); /* needed in some cases */
PUSH(y + 1, x, x, -1); /* seed segment (popped 1st) */

while(sp > stack.begin())
{
/* pop segment off stack and fill a neighboring scan line */
POP(y, x1, x2, dy);

/*
* segment of scan line y-dy for x1<=x<=x2 was previously filled,
* now explore adjacent pixels in scan line y
*/
for(x = x1; x >= sge_clip_xmin(dst); x--)
{
if(sge_GetPixel(dst, x, y) != oc)
break;

_PutPixel(dst, x, y, color);
}

if(x >= x1)
goto skip;

l = x + 1;
if(l < x1)
PUSH(y, l, x1 - 1, -dy); /* leak on left? */

x = x1 + 1;

do
{
for(; x <= sge_clip_xmax(dst); x++)
{
if(sge_GetPixel(dst, x, y) != oc)
break;

_PutPixel(dst, x, y, color);
}

PUSH(y, l, x - 1, dy);

if(x > x2 + 1)
PUSH(y, x2 + 1, x - 1, -dy); /* leak on right? */
skip:
for(x++; x <= x2; x++)
if(sge_GetPixel(dst, x, y) == oc)
break;

l = x;
} while(x <= x2);
}
}

template<typename T>
void DO_FILL(SDL_Surface* dst, Sint16 x, Sint16 y, Uint32 color)
{
Sint16 l, x1, x2, dy;
Uint32 oc; /* old pixel color */
std::array<seg, MAX> stack;
auto* sp = stack.begin(); /* stack of filled segments */
Uint16 pitch = dst->pitch / dst->format->BytesPerPixel;
auto* row = (T*)dst->pixels + y * pitch;
auto* pixel = row + x;

if(x < sge_clip_xmin(dst) || x > sge_clip_xmax(dst) || y < sge_clip_ymin(dst) || y > sge_clip_ymax(dst))
return;

oc = *pixel; /* read color at seed point */

if(oc == color)
return;

PUSH(y, x, x, 1); /* needed in some cases */
PUSH(y + 1, x, x, -1); /* seed segment (popped 1st) */

while(sp > stack.begin())
{ /* pop segment off stack and fill a neighboring scan line */
POP(y, x1, x2, dy);
row = (T*)dst->pixels + y * pitch;
pixel = row + x1;
/* */
/* segment of scan line y-dy for x1<=x<=x2 was previously filled, */
/* now explore adjacent pixels in scan line y */
/* */
for(x = x1; x >= sge_clip_xmin(dst) && *pixel == oc; x--, pixel--)
*pixel = color;

if(x >= x1)
goto label;

l = x + 1;
if(l < x1)
PUSH(y, l, x1 - 1, -dy); /* leak on left? */

x = x1 + 1;
pixel = row + x;

do
{
for(; x <= sge_clip_xmax(dst) && *pixel == oc; x++, pixel++)
*pixel = color;

PUSH(y, l, x - 1, dy);

if(x > x2 + 1)
PUSH(y, x2 + 1, x - 1, -dy); /* leak on right? */

label:
pixel++;

for(x++; x <= x2 && *pixel != oc; pixel++)
x++;

l = x;
} while(x <= x2);
}
}

// Wrapper function
void sge_FloodFill(SDL_Surface* dst, Sint16 x, Sint16 y, Uint32 color)
{
if(_sge_lock && SDL_MUSTLOCK(dst))
if(SDL_LockSurface(dst) < 0)
return;

switch(dst->format->BytesPerPixel)
{
case 1: /* Assuming 8-bpp */ DO_FILL<Uint8>(dst, x, y, color); break;

case 2: /* Probably 15-bpp or 16-bpp */ DO_FILL<Uint16>(dst, x, y, color); break;

case 3: /* Slow 24-bpp mode, usually not used */ _FloodFillX(dst, x, y, color); break;

case 4: /* Probably 32-bpp */ DO_FILL<Uint32>(dst, x, y, color); break;
}

if(_sge_lock && SDL_MUSTLOCK(dst))
{
SDL_UnlockSurface(dst);
}
}

void sge_FloodFill(SDL_Surface* dst, Sint16 x, Sint16 y, Uint8 R, Uint8 G, Uint8 B)
{
sge_FloodFill(dst, x, y, SDL_MapRGB(dst->format, R, G, B));
}

0 comments on commit e1f9eaa

Please sign in to comment.