Ooops
March 04, 2021, 12:28:24 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Graphics
»
[bb] Fast Flood Fill (ProPixel Code) by Snarty [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] Fast Flood Fill (ProPixel Code) by Snarty [ 1+ years ago ] (Read 450 times)
BlitzBot
Jr. Member
Posts: 1
[bb] Fast Flood Fill (ProPixel Code) by Snarty [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:39 AM »
Title :
Fast Flood Fill (ProPixel Code)
Author :
Snarty
Posted :
1+ years ago
Description :
As I missed the entry for flood fill I had to start from scratch, I've run this one against the other flood fill routine and found this way to be faster.
Updated: 18-11-02, Now Generically Coded.
Code :
Code: BlitzBasic
; Fill Routines
; Written By Paul Snart (Snarty)
; Oct 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
Fpx=ax
Fpy=ay
Repeat
Fp.Point=
First
Point
Lx=Fpx:Rx=Fpx+
1
HitL=
False
:HitR=
False
Hlt=-
1
:Hlb=-
1
Hrt=-
1
:Hrb=-
1
Repeat
If
Lx=>
0
And
HitL=
False
CColL=
ReadPixelFast
(
Lx,Fpy
)
If
CColL=BCol
WritePixelFast
Lx,Fpy,RCol
If
Fpy>
0
CColL=
ReadPixelFast
(
Lx,Fpy-
1
)
If
CColL=BCol
Hlt=Lx
Else
If
Hlt<>-
1
y=Fpy-
1
Fp.Point =
New
Point
Fpy=y:Fpx=Hlt
Hlt=-
1
Fp.Point =
First
Point
Entrys=Entrys+
1
EndIf
EndIf
EndIf
If
Fpy<ImH-
1
CColL=
ReadPixelFast
(
Lx,Fpy+
1
)
If
CColL=BCol
Hlb=Lx
Else
If
Hlb<>-
1
y=Fpy+
1
Fp.Point =
New
Point
Fpy=y:Fpx=Hlb
Hlb=-
1
Fp.Point =
First
Point
Entrys=Entrys+
1
EndIf
EndIf
EndIf
Lx=Lx-
1
Else
HitL=
True
If
Hlt<>-
1
y=Fpy-
1
Fp.Point =
New
Point
Fpy=y:Fpx=Hlt
Hlt=-
1
Fp.Point =
First
Point
Entrys=Entrys+
1
EndIf
If
Hlb<>-
1
y=Fpy+
1
Fp.Point =
New
Point
Fpy=y:Fpx=Hlb
Hlb=-
1
Fp.Point =
First
Point
Entrys=Entrys+
1
EndIf
EndIf
Else
HitL=
True
If
Hlt<>-
1
y=Fpy-
1
Fp.Point =
New
Point
Fpy=y:Fpx=Hlt
Hlt=-
1
Fp.Point =
First
Point
Entrys=Entrys+
1
EndIf
If
Hlb<>-
1
y=Fpy+
1
Fp.Point =
New
Point
Fpy=y:Fpx=Hlb
Hlb=-
1
Fp.Point =
First
Point
Entrys=Entrys+
1
EndIf
EndIf
If
Rx<=ImW-
1
And
HitR=
False
CColR=
ReadPixelFast
(
Rx,Fpy
)
If
CColR=BCol
WritePixelFast
Rx,Fpy,RCol
If
Fpy>
0
CColR=
ReadPixelFast
(
Rx,Fpy-
1
)
If
CColR=BCol
Hrt=Rx
Else
If
Hrt<>-
1
y=Fpy-
1
Fp.Point =
New
Point
Fpy=y:Fpx=Hrt
Hrt=-
1
Fp.Point =
First
Point
Entrys=Entrys+
1
EndIf
EndIf
EndIf
If
Fpy<ImH-
1
CColR=
ReadPixelFast
(
Rx,Fpy+
1
)
If
CColR=BCol
Hrb=Rx
Else
If
Hrb<>-
1
y=Fpy+
1
Fp.Point =
New
Point
Fpy=y:Fpx=Hrb
Hrb=-
1
Fp.Point =
First
Point
Entrys=Entrys+
1
EndIf
EndIf
EndIf
Rx=Rx+
1
Else
HitR=
True
If
Hrt<>-
1
y=Fpy-
1
Fp.Point =
New
Point
Fpy=y:Fpx=Hrt
Hrt=-
1
Fp.Point =
First
Point
Entrys=Entrys+
1
EndIf
If
Hrb<>-
1
y=Fpy+
1
Fp.Point =
New
Point
Fpy=y:Fpx=Hrb
Hrb=-
1
Fp.Point =
First
Point
Entrys=Entrys+
1
EndIf
EndIf
Else
HitR=
True
If
Hrt<>-
1
y=Fpy-
1
Fp.Point =
New
Point
Fpy=y:Fpx=Hrt
Hrt=-
1
Fp.Point =
First
Point
Entrys=Entrys+
1
EndIf
If
Hrb<>-
1
y=Fpy+
1
Fp.Point =
New
Point
Fpy=y:Fpx=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
Comments :
none...
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Graphics
»
[bb] Fast Flood Fill (ProPixel Code) by Snarty [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal