For speed comparison:
Notice that this is considerably slower than the built-in PAINT routine. This also has to keep track of blending and alpha and match original colors and other stuff as well, so it's designed more for versatility than speed. For a photoshop type paint fill, I imagine this would be fine. As a fill routine for a game or something that's going to be called repeatedly in a loop, I'd think you'd want to find something more efficient.
I'm not certain exactly certain what you might need it for, but it's the first example of an alpha-blending fill that I think I've seen on the forums here. If anyone has something comparable, I'd love to see it myself, just to study different techniques and ideas behind how to do something like this quickly and efficiently.
Code: (Select All)
Screen _NewImage(800, 800, 32)
Circle (400, 400), 400, _RGB32(255, 255, 255) 'white circle
t# = Timer
For i = 1 To 100
Paint (400, 400), _RGB32(Rnd * 256, Rnd * 256, Rnd * 256), _RGB32(255, 255, 255)
Next
t1# = Timer
For i = 1 To 100
Fill 400, 400, _RGB32(Rnd * 256, Rnd * 256, Rnd * 256)
Next
t2# = Timer
Print Using "###.### second Paint"; t1# - t#
Print Using "###.### second Fill"; t2# - t1#
Sub Fill (x, y, Kolor As _Unsigned Long)
Dim As _Unsigned Long OC, BC
OC = Point(x, y) 'original color
If _Alpha32(Kolor) <> 255 Or _Alpha32(OC) <> 255 Then 'we're going to blend
PSet (x, y), Kolor
BC = Point(x, y) 'blended color
End If
Filler x, y, Kolor, OC, BC
End Sub
Sub Filler (x, y, Kolor As _Unsigned Long, OC As _Unsigned Long, BC As _Unsigned Long)
Dim l, r, i
If Kolor = OC Or Kolor = BC Then Exit Sub
l = x: r = x 'find left/right to fill
Do Until l = 0
If Point(l - 1, y) = BC Then Exit Do
If Point(l - 1, y) = OC Then l = l - 1 Else Exit Do
Loop 'find the left boundry
Do Until r = _Width - 1
If Point(r + 1, y) = BC Then Exit Do
If Point(r + 1, y) = OC Then r = r + 1 Else Exit Do
Loop 'find the right boundry
Line (l, y)-(r, y), Kolor, BF
For i = l To r
If Point(i, y + 1) = BC Then _Continue
If Point(i, y + 1) = OC Then Filler i, y + 1, Kolor, OC, BC
Next
For i = l To r
If Point(i, y - 1) = BC Then _Continue
If Point(i, y - 1) = OC Or Point(l - 1, y) = BC Then Filler i, y - 1, Kolor, OC, BC
Next
End Sub ' Fill
Notice that this is considerably slower than the built-in PAINT routine. This also has to keep track of blending and alpha and match original colors and other stuff as well, so it's designed more for versatility than speed. For a photoshop type paint fill, I imagine this would be fine. As a fill routine for a game or something that's going to be called repeatedly in a loop, I'd think you'd want to find something more efficient.
I'm not certain exactly certain what you might need it for, but it's the first example of an alpha-blending fill that I think I've seen on the forums here. If anyone has something comparable, I'd love to see it myself, just to study different techniques and ideas behind how to do something like this quickly and efficiently.

