PDA

View Full Version : CreateDIBSection vs. Bitmap.Scanline



Harry Hunt
07-05-2004, 02:38 PM
Hi!
I'm a bit confused here and hope that somebody can tell me what's going on :shock:

Now this is not game-related but since I got a bunch of really helpful answers here in the past, I'll post it anyways.

A few years ago while working at a contract programmer I was given the assignment to write an image editor. So I did, but being a passionate Delphi programmer who's always hoping to reuse some of his code some time, I decided to write an Image-Editor component that does everything a good image editor needs to be capable off.
All in all a big project with many thousand lines of code. Back then I didn't have much time to work on it so I wrote it all with standard GDI calls and for pixel-access I used ScanLine which was fast enough for what I needed.

Since I in fact reused that component in a few other programs, I recently decided to write a new image editor and to make it faster than the original program. So since pixel-access seemed to be the bottleneck of my component, I decided to move from working with TBitmaps and the Scanline property to CreateDIBSection and to my own pixel-plotting routine written in assembler. I played around with it for quite some time and thought I had made it as fast as it could possibly be.
So the other day I wrote a little test program to compare the performance of my pixel plotting routines with Bitmap.ScanLine and ScanLine actually outperformed my highly optimized assembler stuff.

So does anybody have an explanation for this?
I always thought CreateDIBSection was as fast as it gets (not counting APIs like DirectX or OpenGL).

EDIT: To give you some numbers:
My CreateDIBSection/assembler pixel plotting routine plots 1 million pixels in 60 msecs on an athlon 1000 Mhz with 512 MB RAM
ScanLine does 1 million in ten msecs less