Quote
"Jon Souter" <jon.sou...@gestetner.com> wrote:
>> Try the API call setpixel. I've been told it is a LOT faster than
>> setting the canvas pixels thingo. I just looked it up in the D1 help
>> (thats all we have at uni), and i beleve it still exists in D2. No idea
>> about D3.
>I've just tried using the SetPixel API function (under Delphi 2.01) and I
>can't get it to run any quicker than by adressing the Pixels[] collection
>of the canvas. Here's the simplistic code I've been using...
>Any idea how I can speed this little routine up?
>Best regards,
>Jon Souter
>Email: Jon.Sou...@Dial.Pipiex.Com
pipex.com I suspect...
Jon,
The secret here is not fancy tips and tricks but principle. Take a
step *back* for the moment :-).
Most of the Win API calls in this section are mainly used for drawing
windows controls, *not* for high speed graphics work. Example:
Let's say you've just uncovered a form and a button on it needs to
redraw.
Windows sends a message to the application, which takes it into the
message handler loop, does various things to it, and sends it to the
button. The Button object in delphi is just a wraparound of a few
windows API functions.. these windows API functions check for various
overlaps, window states, default colours, and a million and one other
things before anything gets drawn.
Each time you go for setpixel .... *for every single pixel* you try to
draw, you are calling windows, which checks the location and state of
*every single window* before drawing the pixel in order to make sure
it's not accidentally drawing it on top of someone elses application.
In this case it takes between 50,000 and 5,000,000 clock cycles just
to change a simple little pixel.
If you use a DIBSection, this is all changed. Windows doesn't
mollycoddle everything for you.... you just blast the data straight
into the DIBSection memory, and when *you* want to do it (like once
you've finished setting the memory values), you say to windows "Hey Mr
Operating System... I think you might like to update this window based
on this block of memory", which it will then do once for the image...
not once for every pixel!!!!
I had to fill out a 1024x768 display like this... using SetPixels it
took about 3 hours.... using a DIBSection, it took about 30
milliseconds.
MH.
***********************************************
Martin Harvey
By popular request, email addresses are now in plain text.
Uni email: mc...@hermes.cam.ac.uk
Home email: mc...@harvey27.demon.co.uk
Uni web pages: http://www-stu.pem.cam.ac.uk/~mch24/
***********************************************