BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"Fast Flood Fill (ProPixel Code)"
, by snarty
Now fully generic, you can flood fill an area on any image in memory.
Code
; Fill Algorithm ; Written By Paul Snart ; Copyright Pacific Software ; Written October 2001 ; RCol = RGB Color to Fill with ; Ax = X Start on Image to Fill ; Ay = Y Start on Image to Fill ; Image = Image to fill on Type Point Field x Field y End Type Function FloodFill(RCol,ax,ay,Image) timeit=MilliSecs() temp=CreateImage(1,1):SetBuffer ImageBuffer(temp) LockBuffer:WritePixelFast 0,0,RCol RCol=ReadPixelFast(0,0) UnlockBuffer:FreeImage Temp SetBuffer ImageBuffer(Image):LockBuffer BCol=ReadPixelFast(ax,ay) ImW=ImageWidth(Image) ImH=ImageHeight(Image) If BCol<>RCol Hlt=-1:Hlb=-1 Hrt=-1:Hrb=-1 Entrys=1 Fp.Point = New Point Fp\x=ax Fp\y=ay Repeat Fp.Point=First Point Lx=Fp\x:Rx=Fp\x+1 HitL=False:HitR=False Hlt=-1:Hlb=-1 Hrt=-1:Hrb=-1 Repeat If Lx=>0 And HitL=False CColL=ReadPixelFast(Lx,Fp\y) If CColL=BCol WritePixelFast Lx,Fp\y,RCol If Fp\y>0 CColL=ReadPixelFast(Lx,Fp\y-1) If CColL=BCol Hlt=Lx Else If Hlt<>-1 y=Fp\y-1 Fp.Point = New Point Fp\y=y:Fp\x=Hlt Hlt=-1 Fp.Point = First Point Entrys=Entrys+1 EndIf EndIf EndIf If Fp\y
-1 y=Fp\y+1 Fp.Point = New Point Fp\y=y:Fp\x=Hlb Hlb=-1 Fp.Point = First Point Entrys=Entrys+1 EndIf EndIf EndIf Lx=Lx-1 Else HitL=True If Hlt<>-1 y=Fp\y-1 Fp.Point = New Point Fp\y=y:Fp\x=Hlt Hlt=-1 Fp.Point = First Point Entrys=Entrys+1 EndIf If Hlb<>-1 y=Fp\y+1 Fp.Point = New Point Fp\y=y:Fp\x=Hlb Hlb=-1 Fp.Point = First Point Entrys=Entrys+1 EndIf EndIf Else HitL=True If Hlt<>-1 y=Fp\y-1 Fp.Point = New Point Fp\y=y:Fp\x=Hlt Hlt=-1 Fp.Point = First Point Entrys=Entrys+1 EndIf If Hlb<>-1 y=Fp\y+1 Fp.Point = New Point Fp\y=y:Fp\x=Hlb Hlb=-1 Fp.Point = First Point Entrys=Entrys+1 EndIf EndIf If Rx<=ImW-1 And HitR=False CColR=ReadPixelFast(Rx,Fp\y) If CColR=BCol WritePixelFast Rx,Fp\y,RCol If Fp\y>0 CColR=ReadPixelFast(Rx,Fp\y-1) If CColR=BCol Hrt=Rx Else If Hrt<>-1 y=Fp\y-1 Fp.Point = New Point Fp\y=y:Fp\x=Hrt Hrt=-1 Fp.Point = First Point Entrys=Entrys+1 EndIf EndIf EndIf If Fp\y
-1 y=Fp\y+1 Fp.Point = New Point Fp\y=y:Fp\x=Hrb Hrb=-1 Fp.Point = First Point Entrys=Entrys+1 EndIf EndIf EndIf Rx=Rx+1 Else HitR=True If Hrt<>-1 y=Fp\y-1 Fp.Point = New Point Fp\y=y:Fp\x=Hrt Hrt=-1 Fp.Point = First Point Entrys=Entrys+1 EndIf If Hrb<>-1 y=Fp\y+1 Fp.Point = New Point Fp\y=y:Fp\x=Hrb Hrb=-1 Fp.Point = First Point Entrys=Entrys+1 EndIf EndIf Else HitR=True If Hrt<>-1 y=Fp\y-1 Fp.Point = New Point Fp\y=y:Fp\x=Hrt Hrt=-1 Fp.Point = First Point Entrys=Entrys+1 EndIf If Hrb<>-1 y=Fp\y+1 Fp.Point = New Point Fp\y=y:Fp\x=Hrb Hrb=-1 Fp.Point = First Point Entrys=Entrys+1 EndIf EndIf Until (HitR=True And HitL=True) Or KeyHit(1) Fp.Point=First Point Delete Fp Entrys=Entrys-1 Until Entrys=False Or KeyHit(1) EndIf UnlockBuffer SetBuffer BackBuffer() mhit=False DebugLog (Float(MilliSecs()-TimeIt)/1000)+" seconds" End Function
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations