#include once "fbgfx.bi"
#undef fb_GfxPaint
sub fb_GfxPaint alias "fb_GfxPaint" _
( _
byval target as any ptr, _
byval fx as single, _
byval fy as single, _
byval _color as uinteger, _
byval border_color as uinteger, _
byref pattern as string, _
byval mode as integer, _
byval flags as integer _
)
#define STK_INIT 1024
#define STK_STEP 1024
dim as integer ptr stk = any
dim as integer stk_p = 0
dim as integer stk_s = STK_INIT
dim as any ptr p = any
dim as integer w = any
dim as integer h = any
dim as integer bpp = any
dim as integer pitch = any
dim as integer x = fx
dim as integer y = fy
if target = 0 then
p = screenptr
screeninfo w, h, , bpp, pitch
else
p = target + sizeof( fb.image )
w = cast( fb.image ptr, target )->width
h = cast( fb.image ptr, target )->height
bpp = cast( fb.image ptr, target )->bpp
pitch = cast( fb.image ptr, target )->pitch
end if
if (x < 0) or (y < 0) or (x >= w) or (y >= h) then exit sub
dim as uinteger fc = cast( uinteger ptr, p + (y * pitch) )[x]
if fc = _color then exit sub
if target = 0 then
screenlock
end if
stk = allocate( stk_s * sizeof( integer ) )
stk[stk_p+0] = x
stk[stk_p+1] = y
stk_p += 2
while stk_p
dim as integer onA = 0
dim as integer onB = 0
stk_p -= 2
x = stk[stk_p+0]
y = stk[stk_p+1]
dim as uinteger ptr row = cast( uinteger ptr, p + (y * pitch) )
while x
if row[x-1] <> fc then exit while
x -= 1
wend
while x < w
if row[x] <> fc then exit while
row[x] = _color
if y > 0 then ' can look above
dim as uinteger ptr arow = cast( any ptr, row ) - pitch
if arow[x] = fc then
if onA = 0 then
if stk_p >= stk_s then
stk_s += STK_STEP
stk = reallocate( stk, stk_s * sizeof( integer ) )
end if
stk[stk_p+0] = x
stk[stk_p+1] = y - 1
stk_p += 2
end if
onA = -1
else
onA = 0
end if
end if
if y < (h - 1) then ' can look below
dim as uinteger ptr brow = cast( any ptr, row ) + pitch
if brow[x] = fc then
if onB = 0 then
if stk_p >= stk_s then
stk_s += STK_STEP
stk = reallocate( stk, stk_s * sizeof( integer ) )
end if
stk[stk_p+0] = x
stk[stk_p+1] = y + 1
stk_p += 2
end if
onB = -1
else
onB = 0
end if
end if
x += 1
wend
wend
if target = 0 then
screenunlock
end if
deallocate( stk )
end sub
#define scr_wid 800
#define scr_hei 600
sub yetiflood _
( _
byval x as integer, _
byval y as integer, _
byval c as uinteger _
)
if (cast( uinteger, x ) >= cast( uinteger, scr_wid )) _
or (cast( uinteger, y ) >= cast( uinteger, scr_hei )) then exit sub
#define stack_size 8192
static stack(0 to stack_size - 1) as integer
dim stack_pos as integer = stack_size
dim as uinteger ptr screen_p = screenptr( )
dim as uinteger fc = screen_p[(y * scr_wid) + x]
'if fc = c then exit sub
screenlock
stack_pos -= 2
stack(stack_pos+0) = x
stack(stack_pos+1) = y
while stack_pos < stack_size
x = stack(stack_pos+0)
y = stack(stack_pos+1)
stack_pos += 2
dim as uinteger ptr p = @screen_p[y * scr_wid]
dim as integer on_lineA = 0
dim as integer on_lineB = 0
dim as integer ya = y - 1
dim as integer yb = y + 1
dim as integer ya_good = (ya < scr_hei) and (ya >= 0)
dim as integer yb_good = (yb < scr_hei) and (yb >= 0)
dim as uinteger ptr ya_p = @p[-scr_wid]
dim as uinteger ptr yb_p = @p[scr_wid]
while x > 0
if p[x - 1] <> fc then exit while
x -= 1
wend
while x < scr_wid
if p[x] <> fc then exit while
p[x] = c
if ya_good then
if ya_p[x] = fc then
if on_lineA = 0 then
stack_pos -= 2
stack(stack_pos+0) = x
stack(stack_pos+1) = ya
on_lineA = 1
end if
else
on_lineA = 0
end if
end if
if yb_good then
if yb_p[x] = fc then
if on_lineB = 0 then
stack_pos -= 2
stack(stack_pos+0) = x
stack(stack_pos+1) = yb
on_lineB = 1
end if
else
on_lineB = 0
end if
end if
x += 1
wend
wend
screenunlock
end sub
screenres scr_wid,scr_hei,32
for i as integer = 1 to 50
dim as integer rx = int(rnd*Scr_Wid)
dim as integer ry = int(rnd*Scr_Hei)
dim as integer rad = rnd*100
dim as uinteger rcol = 255'rnd*1677215
circle(rx,ry),rad,rcol
yetiflood( rx, ry, rcol )
'paint (rx, ry), rcol
next
sleep