Pixel Plotting - Slow
Miscellaneous Forums/General Discussion/Pixel Plotting - Slow
How is the bucket fill tool in MS Paint/photoshop done so fast (instantly)?
They surely must be using a different technique than pixel plotting, as Blitz' is so slow?
GDI calls, most likely.
you may also do the maths in an array and then simply copy an entire block to an image (eg. bitblit), that's much faster.
In blitzplus it is possible to draw the entire screen (800x600) quite quickly using the lockedpitch/lockedpixels/lockedformat commands along with poking directly into the backbuffer.
Well i did a little test. BlitzMax is about 11 times faster using the plot command than Blitz3D.
640,480 res
2700MS ish in B3D
250MS ish in Max
But thats still abit to slow. It would be intresting to know how people have done it, who have made paint programs in B3D
just curious, is this any faster? Leave the Scale at 1,1 and the w and h parameters at 1,1 to have the same affect as plot
Function ScaleDrawRect(x:Double,y:Double,w:Double,h:Double)
Local sx:Float,sy:Float
GetScale(sx,sy)
If sx*x>GraphicsWidth() Or sy*y>GraphicsHeight() Then Return
DrawRect(sx*x,sy*y,w,h)
End Function
or just try DrawRect(x,y,1,1) instead of plot
No, I did actually try the draw rect thing, and if I can rmember correctly, it was the same speed.
What I didn't try was making a 1 pixel image (as I hear image are much faster), and using that to fill with.
I am not too great in BMax to do that any time within the next day, so if someone else wants to try it, i would be intrested in the results.
I wouldn't use plot/rects/images to fill the image, just use WritePixelFast. I don't know if bmax has that command, though, if that's what you're using.
Well I tried using writepixelfast in B3D (I am sorta using both atm), and although it was faster, it certainly wasn't 'instant bucket fill' speed
Depeneding on how you are detecting the edges of the fill area you could use DrawLine or DrawPoly.
I don't think you'll get an 'instant' fill using blitz - depending on machine speed and fill area, of course.
Does it have to be instant? As long as it's not unbearably slow, surely that'll do?
Anyway, there're a few fill alogos in the archives, including the one Snarty uses in ProPixel, I believe.
Crazy. You had instant bucket fill back on old 8mhz 286/386 systems. Why is it so damn slow on modern systems?
Simple: The level of abstraction.
The system spends more time going through calls to functions than it does doing the function :(
(Oh, and most cards today are designed for 3D. Why they stopped direct access to pixels at high speed i'll never know!)
Well there are plenty of tools that can do Bucket fill, MS Paint being one of them...
Might be faster to draw whole rows using a single line rather than individual pixels. A line requires 2 vertexes whereas each individual pixel would require 2 vertexes per pixel. If not lines, which are possibly slower than quads given that there is more math involved. You could use DrawRect to draw your rows. If you can turn your flooded area into actual rectangles, spanning multiple rows, that'd be even faster.
Well there are plenty of tools that can do Bucket fill, MS Paint being one of them...
I never said it was impossible, just more complex than It needed to be.
Writepixel is a lot quicker in Bmax than B3D so might be worth giving it a go. I used Snarty's fill routine and it's pretty quick. There are a number of floodfill algos on these forums, old BlitzCoder and a few on the web. The faster ones appear to use the 'line' (or Drawline) functions.
I'd go with DrawRect rather than DrawLine. I think it will be quicker even though it's a one-pixel-high rectangle.
I can confirm that drawrect is better than drawline.
Even using some of the fastest cards on the market games that rely heavily on 2D processing are unplayable these days.
I think this is mostly due to abstraction and the fact cards are all optimised for 3D these days and not 2D. It's shame because there are some games, (like Timeshock) which are unplayble on my modern powerful system that worked just fine on a P2 300 with a Rage 128.
Drawrect is pretty fast, but it's still slow as hell compared to MSPAINT's floodfill which always seems practically instant to me, no matter how big or complex the shape.
Darkheart
Haha, yes. Probably the non bloatiest bit about windows.
That feature was fast even in Windows3.1
Surely a sign that even MS can program something efficiently if they can only be bothered to do so.
Thats just GDI. (I think?)
MS program something? hmm.. that's one of the select few thing..
they probably bought the code involved, and patented it..
(like they've done with most other software they claim their own work.) hehe