News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Plotting pixels in masm

Started by drjr, July 29, 2007, 02:06:51 AM

Previous topic - Next topic

drjr

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.

ramguru

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.

Tedd

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)
No snowflake in an avalanche feels responsible.

thomas_remkus

I would also recommend creating your own bitmap in memory, doing your draw functions (or 'setpix' functions) and then BitBlt back into the device.

Tedd

#4
That is what the dib-section is for
Sorry, I read your comment wrong ::)
No snowflake in an avalanche feels responsible.