Hi everyone,
The response to this thread has left me breathless!
After several days of intense research and programming I've written a working FloodFill routine! It was more complicated than I'd hoped, having to use the Lock/Unlock Bitmap technique. My routine is v.e.r.y s.l.o.w ( I did my best ) and I'm afraid on a complex image it might run out of room for it's queue. For whatever it's worth, some of the code might be of use to someone, so here it is.
This 1st part is the Loop that calls the Line painting routine as many times as necessary to complete the Fill.
Do While Qp > 0
pix = theQ(Qp)
pY = CInt(Fix(pix / (BMP.Width * 3)))
NewLinearFill(bm_bytes)
Loop
And here is the Main routine
Private Sub NewLinearFill(ByVal bm_bytes As BitmapBytesRGB24)
savepix = pix
savepix2 = pix
'Paint 1st pixel
bm_bytes.ImageBytes(pix) = R
bm_bytes.ImageBytes(pix + 1) = G
bm_bytes.ImageBytes(pix + 2) = B
'1st pixel done so remove it from the queue
Qp -= 1
'This boolean array is used with a tolerance type Fill
'Every painted pixel must be entered as True
'Bool((pY * BMP.Width) + pX) = True
upflag = False
dnflag = False
Do 'Loop for painting right
If pY > 0 Then 'Safe to look up
pix -= BMP.Width * 3
If (bm_bytes.ImageBytes(pix) = oldR) And _
(bm_bytes.ImageBytes(pix + 1) = oldG) And _
(bm_bytes.ImageBytes(pix + 2) = oldB) Then
If Not upflag Then
'Add to queue
Qp += 1
theQ(Qp) = pix
upflag = True
End If
Else : upflag = False
End If
pix = savepix2
End If
If pY < BMP.Height - 1 Then 'Safe to look down
pix += BMP.Width * 3
If (bm_bytes.ImageBytes(pix) = oldR) And _
(bm_bytes.ImageBytes(pix + 1) = oldG) And _
(bm_bytes.ImageBytes(pix + 2) = oldB) Then
If Not dnflag Then
'Add to queue
Qp += 1
theQ(Qp) = pix
dnflag = True
End If
Else : dnflag = False
End If
pix = savepix2
End If
'Move to the right
'1st check if touching far right edge
If pix > (pY * (BMP.Width * 3)) + ((BMP.Width * 3) - 6) Then
'Edge so vamanosse
Exit Do
End If
'Check right
If (bm_bytes.ImageBytes(pix + 3) <> oldR) And _
(bm_bytes.ImageBytes(pix + 4) <> oldG) And _
(bm_bytes.ImageBytes(pix + 5) <> oldB) Then
'Not Valid so Exit!
Exit Do
End If
'Increment and Paint
pix += 3
savepix2 = pix
bm_bytes.ImageBytes(pix) = R
bm_bytes.ImageBytes(pix + 1) = G
bm_bytes.ImageBytes(pix + 2) = B
Loop
'Back to where we first came in
pix = savepix
savepix2 = pix
upflag = False
dnflag = False
Do 'Loop for painting left
If pY > 0 Then 'Safe to look up
pix -= BMP.Width * 3
If (bm_bytes.ImageBytes(pix) = oldR) And _
(bm_bytes.ImageBytes(pix + 1) = oldG) And _
(bm_bytes.ImageBytes(pix + 2) = oldB) Then
'because we're painting to the left
'we have to swap the queue value for
'this scan line for the pix to the left
If theQ(Qp) = pix + 3 Then
theQ(Qp) = pix
Else
Qp += 1
theQ(Qp) = pix
End If
End If
pix = savepix2
End If
If pY < BMP.Height - 1 Then 'Safe to look down
pix += BMP.Width * 3
If (bm_bytes.ImageBytes(pix) = oldR) And _
(bm_bytes.ImageBytes(pix + 1) = oldG) And _
(bm_bytes.ImageBytes(pix + 2) = oldB) Then
'because we're painting to the left
'we have to swap the queue value for
'this scan line for the pix to the left
If theQ(Qp) = pix + 3 Then
theQ(Qp) = pix
Else
Qp += 1
theQ(Qp) = pix
End If
End If
pix = savepix2
End If
'1st check if touching far left edge
If pix = (pY * (BMP.Width * 3)) Then
'Edge so vamanosse
Exit Do
End If
'Check left
If (bm_bytes.ImageBytes(pix - 3) <> oldR) And _
(bm_bytes.ImageBytes(pix - 2) <> oldG) And _
(bm_bytes.ImageBytes(pix - 1) <> oldB) Then
'Not Valid so Exit!
Exit Do
End If
'Decrement and Paint
pix -= 3
savepix2 = pix
bm_bytes.ImageBytes(pix) = R
bm_bytes.ImageBytes(pix + 1) = G
bm_bytes.ImageBytes(pix + 2) = B
Loop
End Sub