The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: msmith on July 22, 2006, 04:55:51 AM

Title: Setting Pixels in Memory DC
Post by: msmith on July 22, 2006, 04:55:51 AM
I am currently manipulating the data of a bitmap inside a memory DC.

How can you obtain the memory address of the data so that it can be tested and set directly without GetPixel and SetPixel?
Title: Re: Setting Pixels in Memory DC
Post by: msmith on July 22, 2006, 06:50:50 AM
I noticed that several sites on Google say that SetPixelV is faster than SetPixel. Some say it is mush faster while other say slightly faster.

At any rate, I also noticed that most advise against this method to create transparent bitmaps because it is slow, but I like it because of the flexibility it offers (you can set individual pixels, not just transparency). Also, I have a test program with 25 controls using this method an see no perceptable delay.

I have changed to SetPixelV because even Microsoft claims it is faster.
Title: Re: Setting Pixels in Memory DC
Post by: zooba on July 22, 2006, 07:01:46 AM
GetBitmapBits is probably the function you're after. However, it does copy the bitmap into more memory, rather than letting you use it in place. SetBitmapBits can put it back. I haven't used these for anything performance-intensive, so I can't comment on their efficiency.

Cheers,

Zooba :U
Title: Re: Setting Pixels in Memory DC
Post by: MichaelW on July 22, 2006, 10:20:50 AM
According to  MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_87eb.asp) GetBitmapBits and SetBitmapBits are obsolete functions "provided only for compatibility with 16-bit versions of Windows", and should be replaced with GetDIBits and SetDIBits.  The attachment is a quick and dirty test to determine if the newer functions (Get... only) are faster. If I did everything correctly, and I'm not at all sure that I did, then the newer functions are much faster (~3.2:1 on my Windows 2000 SP4 system), despite doing more than the older functions. I started out trying to do this from a console app, but I could not make GetDIBits work with the desktop DC.

The newer cycle count macros that I used produce very repeatable results on local code that runs in less than a few thousand cycles, but I'm getting a substantial run to run variation here, I think either because I'm timing API calls, or because I'm doing it in a callback.

EDIT: Ignore this post, my test was not valid for several (stupid) reasons, and when I fix the problems GetDIBits is slower than GetBitmapBits (~10:8).



[attachment deleted by admin]
Title: Re: Setting Pixels in Memory DC
Post by: Darrel on July 22, 2006, 12:32:50 PM
I use CreateDIBSection, this creates a bitmap with direct access to all the pixels.

Regards,

Darrel
Title: Re: Setting Pixels in Memory DC
Post by: msmith on July 23, 2006, 09:20:14 PM
GetObject does what I want.

Thanks to all for the suggestions.

Mike