The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: drjr on July 29, 2007, 02:06:51 AM

Title: Plotting pixels in masm
Post by: drjr on July 29, 2007, 02:06:51 AM
Could somone say me the best way to plot a lot of pixels using masm32 ?
I have used the following:
                                      INVOKE SetPixel,hdc,coox,cooy,rgbval

    But when there are very much pixels to plot this is no fast enough.                 


                                     Thanks for all.
Title: Re: Plotting pixels in masm
Post by: ramguru on July 30, 2007, 11:35:30 AM
I think there aren't many choices to choose from:
SetPixel(V)
or
SetDIBitsToDevice

I'm actually going to do some gfx with pixels very soon.
The drawback of SetDIBitsToDevice is that this API cannot work along with fonts, while with SetPixel you can do amazing things only a little bit slower.
Title: Re: Plotting pixels in masm
Post by: Tedd on July 30, 2007, 12:16:50 PM
SetPixel is the easiest, but it is quite slow for lots of pixels; if you're doing lines/rectangles/circles/polygons, there are functions which will do these faster.

Alternatively, it's a bit more work, but you can set up a memory DC, attach a DIB-section (basically, a bitmap) and then 'draw' directly in memory to this. Then you BitBlt the dc to your window dc to update the display.
Since this is still a DC, you should be able to still use all of the other complex functions the require a DC (e.g. font drawing.)

Create:
- bmpInfo = BITMAPINFO structure, fill in: width,height, 1 plane, 32 bits, BI_RGB compression, everything else to zero (make biHeight = -realHeight, so it's the 'right' way up - bitmaps are stored upside-down)
- myDC = CreateCompatibleDC(NULL)
- pMem DWORD ?   ;variable to hold pointer to start of bitmap data (the pixels!)
- myDib = CreateDIBSection(myDC,ADDR bmpInfo,DIB_RGB_COLORS,ADDR pMem,NULL,NULL)
- SelectObject(myDC,myDib)

Plot(px,py,col):
DWORD PTR [pMem + (py*width+px)*4] = col

Cleanup:
- DeleteObject(myDib)
- DeleteDC(myDC)
- GlobalFree(pMem)
Title: Re: Plotting pixels in masm
Post by: thomas_remkus on July 31, 2007, 03:26:19 AM
I would also recommend creating your own bitmap in memory, doing your draw functions (or 'setpix' functions) and then BitBlt back into the device.
Title: Re: Plotting pixels in masm
Post by: Tedd on July 31, 2007, 12:01:21 PM
That is what the dib-section is for
Sorry, I read your comment wrong ::)