The MASM Forum

General => The Campus => Topic started by: masitecno on May 31, 2012, 12:47:34 PM

Title: CreateDIBitmap
Post by: masitecno on May 31, 2012, 12:47:34 PM
Hi everybody.

Do you know how to create a bitmap using CreateDIBitmap?
I have tried to find the right documentation but i can't find it.

Thanks.
Title: Re: CreateDIBitmap
Post by: dedndave on May 31, 2012, 01:08:32 PM
there are a few examples out there
Jose Roca has some good ones for both GDI and GDI+
i have been learning a lot from his site...

http://www.jose.it-berater.org/smfforum/index.php?topic=4252.0 (http://www.jose.it-berater.org/smfforum/index.php?topic=4252.0)
Title: Re: CreateDIBitmap
Post by: masitecno on May 31, 2012, 01:17:31 PM
Thanks Dave but that example is in vb6 i think.

And I am working with assembler. Masm32.

Anyway I am reading it.

Thanks.

Do you have more links or an example like that but with asm?
Title: Re: CreateDIBitmap
Post by: dedndave on May 31, 2012, 01:53:52 PM
what are you trying to do with it ?
Title: Re: CreateDIBitmap
Post by: masitecno on May 31, 2012, 02:01:43 PM
Well

I need to create a DIB because i need to manipulate the bits.

I need a procedure that create a DIB to set the initial bitmap (768x576) in a window (1024x768).
Another procedure that takes the bitmap and start scrolling left all the image discarding always the first vertical line.
Then another procedure that receives data from commport and generate a new line to continue the scroll.

I have a procedure that creates a matrix then it scroll it left (only numbers) so i need to create a dib based on that matrix or maybe a procedure that translates that value to a pixel color through a color pallette.

That's what I've been trying to do last 3 months.

Title: Re: CreateDIBitmap
Post by: dedndave on May 31, 2012, 02:02:15 PM
from newest to oldest:
http://www.movsd.com/board/index.php?topic=16458.msg136404#msg136404 (http://www.movsd.com/board/index.php?topic=16458.msg136404#msg136404)
http://www.movsd.com/board/index.php?topic=16267.msg134453#msg134453 (http://www.movsd.com/board/index.php?topic=16267.msg134453#msg134453)
http://www.movsd.com/board/index.php?topic=10499.msg76942#msg76942 (http://www.movsd.com/board/index.php?topic=10499.msg76942#msg76942)
http://www.movsd.com/board/index.php?topic=5809.msg43106#msg43106 (http://www.movsd.com/board/index.php?topic=5809.msg43106#msg43106)
http://www.movsd.com/board/index.php?topic=2802.msg21839#msg21839 (http://www.movsd.com/board/index.php?topic=2802.msg21839#msg21839)

Title: Re: CreateDIBitmap
Post by: dedndave on May 31, 2012, 02:04:04 PM
sounds like something we used to do with ultrasound - called "M-Mode"   :P

however - i don't think you actually need to create a bitmap at all
you can simply paint the vertical line, then move it in the DC
Title: Re: CreateDIBitmap
Post by: dedndave on May 31, 2012, 02:09:28 PM
here's a pic with a radial scan at the top - and M-Mode at the bottom (heart-beat)

(http://www.medison.ru/uzi/img/p248.jpg)
Title: Re: CreateDIBitmap
Post by: masitecno on May 31, 2012, 02:09:50 PM
It's something like that.

It's related to pressure measurements but it has to be almost real time graphics.

I need the DIB because there are some algorithms applied to the data matrix that must show changes to the screen.

Well that's what i think.

Maybe I'm wrong
Title: Re: CreateDIBitmap
Post by: masitecno on May 31, 2012, 02:11:54 PM
The section under the echo is what i need only that i need with full color mode.

So you call it M-Mode?

Is there theory where I could learn how to implement it?

References, example codes, anything can help me.
Title: Re: CreateDIBitmap
Post by: dedndave on May 31, 2012, 02:15:54 PM
well - that was implemented with some rather sophisticated scan conversion hardware   :P

i take it you are applying some sort of time-gain compensation
that is the data manipulation you are talking about ?

you should be able to follow some of those code examples by Erol (Vortex)
he always writes nice stuff   :t
Title: Re: CreateDIBitmap
Post by: dedndave on May 31, 2012, 02:23:32 PM
i am just learning how to use GDI and GDI+, myself   :biggrin:

but - a good way to learn is to be given a problem to solve
so, i enjoy a good challenge - lol

i haven't done much yet with CreateDIBSection or CreateDIBitmap
so, i can't really be as helpful as i'd like
however, i can follow a few examples and read the documentation and sort it out (usually)
Title: Re: CreateDIBitmap
Post by: masitecno on May 31, 2012, 02:24:41 PM
No, The data manipulation is required for analysis and diagnose algorithms.

Something like this: http://www.sciencedirect.com/science/article/pii/S0889855308000812
Title: Re: CreateDIBitmap
Post by: dedndave on May 31, 2012, 02:30:24 PM
so - you may create a bitmap that is wider than the display ?
do you save the data to file ?

i am trying to figure out what you're up to so i can figure out what you're after - lol

i have no serial port input device, but i can simulate it with some sort of generator code
Title: Re: CreateDIBitmap
Post by: masitecno on May 31, 2012, 02:31:50 PM
I've read:

http://www.mvps.org/user32/gditutorial.html
http://www.nadtec.to/books/anim/anim_article.htm  (but it seems to be old, i don't know)
http://www.winprog.org/tutorial/message_loop.html
http://www.madwizard.org/programming/tutorials/mosaic/11
http://www.differentpla.net/content/2004/04/direct-access-to-a-bitmap-using-getdibits-and-setdibits
Title: Re: CreateDIBitmap
Post by: masitecno on May 31, 2012, 02:34:49 PM

Well is like a process:

1. A data comes in
2. I save it to file
3. <<operations>>
4. I translate data to colors
5. I send it to screen

Operations can be zoom, change color pallete, draw a line or something like that.

Title: Re: CreateDIBitmap
Post by: dedndave on May 31, 2012, 02:39:38 PM
you have been busy   :biggrin:

yah - that one is old - as far as implementation goes
however - much of the bitmap format stuff still applies

so you are going for something like this:

(http://ars.els-cdn.com/content/image/1-s2.0-S0889855308000812-gr2.jpg)

based on pressure changes...

(http://www.brunswickgastro.com/images/eso_mot.jpg)
Title: Re: CreateDIBitmap
Post by: masitecno on May 31, 2012, 02:40:37 PM
But what I need now is to simulate the scrolling (rotation) to the left like the miller example you gave me but using a DIBitmap.

That's what i need to do now.

Hope you can help me a little or guide me.
Title: Re: CreateDIBitmap
Post by: dedndave on May 31, 2012, 02:42:18 PM
i will see what i can come up with

i will just generate some random pixels as data - for now - lol
but - before i do - i want to finish up another project
Title: Re: CreateDIBitmap
Post by: masitecno on May 31, 2012, 02:42:28 PM
It's something like that!

yeah that's right...


I've tested other technologies but, i think there's nothing like assembler.
Am I on the right way? or should I take another way?
Title: Re: CreateDIBitmap
Post by: dedndave on May 31, 2012, 02:44:46 PM
i don't see why not
but then, i am biased - i like assembler   :P

as for data processing - you may eventually want to delve into SSE
so - assembler lends itself well for that type of data crunching
Title: Re: CreateDIBitmap
Post by: dedndave on May 31, 2012, 02:47:44 PM
i recall seeing an oscilloscope library someplace
it may have what you need already written   :t

let me see if i can find it...
Title: Re: CreateDIBitmap
Post by: dedndave on May 31, 2012, 02:49:35 PM
http://www.oscilloscope-lib.com/ (http://www.oscilloscope-lib.com/)

(http://www.oscilloscope-lib.com/index_files/image002.jpg)

probably not quite what you need
although - it may be helpful as a guideline
Title: Re: CreateDIBitmap
Post by: dedndave on June 01, 2012, 12:01:59 AM
i have been doing some reading this morning - out of curiosity   :biggrin:

i think the function we want to use is CreateDIBSection
it even allows for file-mapped memory - although, we don't have to use that to get started
Title: Re: CreateDIBitmap
Post by: dedndave on June 07, 2012, 12:10:26 AM
masitecno - are you still out there ?   :P
Title: Re: CreateDIBitmap
Post by: Zen on June 07, 2012, 03:15:56 AM
MASITECNO,
EDGAR has a terrific graphics library available for free his website. He uses the DIB functions almost exclusively. This is production-quality code. Website: Donkey's Stable (http://www.quickersoft.com/donkey/index.html)
Look at this page: Libraries (http://www.quickersoft.com/donkey/libs.htm). Scroll down the page to: Graphics.Lib
Note: This library only functions with 32bit DIB sections. All the source code is supplied in the zip file.

The important issue here is to realize what the difference between a Bitmap and a DIB (Device Independent Bitmap) is. Bitmaps, MSDN (http://msdn.microsoft.com/en-us/library/dd183377(v=vs.85)),...and,...CreateDIBSection Function, MSDN (http://msdn.microsoft.com/en-us/library/dd183494(v=vs.85)). Essentially, a DIB is a Bitmap loaded into memory (without the Bitmap File format headers), so that you can access the pixel bit data with: GetDIBits Function, MSDN (http://msdn.microsoft.com/en-us/library/dd144879(v=vs.85).aspx),...and,...SetDIBits Function, MSDN (http://msdn.microsoft.com/en-us/library/dd162973(v=vs.85).aspx)
Title: Re: CreateDIBitmap
Post by: dedndave on June 07, 2012, 09:53:15 AM
Quote from: Weird Zen on June 07, 2012, 03:15:56 AMThe important issue here is to realize what the difference between a Bitmap and a DIB (Device Independent Bitmap) is.

... and a DDB (Device Dependant Bitmap)
that's why i think CreateDIBSection is the right function, rather than CreateDIBitmap
Title: Re: CreateDIBitmap
Post by: wjr on June 08, 2012, 05:35:50 AM
I did something like this with my Mandelbrot Set program M with vertical and/or horizontal auto-scrolling. The following outlines how I set things up for the bitmap:

RegisterClassEx with style CS_OWNDC

for WM_CREATE:
GetDC giving your [hcdMain] for the main window
CreateCompatibleDC giving your [hdcMem]
CreateDIBSection giving your [hBitmap] and [pBits] for use later with your translate data to colors
SelectObject [hBitmap] into [hdcMem]

for WM_PAINT:
BitBlt to SRCCOPY from [hdcMem] into [hdcMain].

for WM_CLOSE:
DeleteDC [hdcMem]
DeleteObject [hBitmap]
Title: Re: CreateDIBitmap
Post by: dedndave on June 08, 2012, 06:06:04 AM
hi Wayne
yes - i think that's the way to go
i have just never had a need to do it

at this point, i am wondering if we have lost the original poster, though   :redface:

it would be cool to make a rotatable 3-D display of the result
the doctors that use the software would probably find it easier to use in diagnosis
i can figure out the rotation, but i don't know how to figure out which surfaces to display/hide
Title: Re: CreateDIBitmap
Post by: xiahan on June 08, 2012, 09:22:02 AM
my little bitmap process program,
hope to give you  a little of manuplating bitmap  :biggrin:

ps:push Alt+left arrow/right arrow to change tansparency
Title: Re: CreateDIBitmap
Post by: masitecno on June 09, 2012, 08:04:05 AM
I wasn't available this week because of health problems.

Sorry.

I'm back so, we will keep on working.
Thanks everyone.
Title: Re: CreateDIBitmap
Post by: masitecno on June 09, 2012, 09:27:32 AM

Thanks for the recomendation, I'm reading chapter 14 it talks about the independent bitmap.

http://read.pudn.com/downloads66/ebook/238647/Programming%20Windows%20Fifth%20Edition.pdf

Thanks DenDave I will move to DIBSection and make an example.


Title: Re: CreateDIBitmap
Post by: dedndave on June 09, 2012, 12:39:51 PM
welcome back - hope you're feeling better   :t

i am almost done with my other little project   :P
Title: Re: CreateDIBitmap
Post by: Farabi on June 10, 2012, 06:55:41 AM
Use this


fLayer struct
DC dword 0
bmp dword 0
fLayer ends

fNewLayer proc uses esi edi lpLayerStruct:dword,_width:dword,height:dword

mov esi,lpLayerStruct
invoke CreateCompatibleDC,0
.if eax==0
invoke MessageBox,0,0,0,0
.endif
mov [esi].fLayer.DC,eax

;invoke CreateIndependantBitmap,eax,_width,height
invoke CreateBitmap,_width,height,1,32,0
invoke ConvertToDIB32,eax

mov [esi].fLayer.bmp,eax
invoke SelectObject,[esi].fLayer.DC,[esi].fLayer.bmp
invoke DeleteObject,eax


ret
fNewLayer endp


By using "invoke GetObject,fLayer.bmp,sizeof BITMAP,addr BM" you can get the memory of the layer and manipulate the pixel directly, but you will need donkey graphic library for that. I uploaded it on attachment.
Title: Re: CreateDIBitmap
Post by: masitecno on June 12, 2012, 06:49:40 AM
Thanks Farabi...

I made everything possible to run the code you gave me, it did run  :t but i have a question.


    invoke CreateCompatibleDC,hDC
    mov fLayerStruct.DC, eax
   
    invoke SelectObject,memDC,hBmp
    mov fLayerStruct.bmp, eax

    invoke fNewLayer, pfLayerStruct, width1, height

    invoke GetObject,fLayerStruct.bmp,sizeof BITMAP,addr BM


Wich variable should I use to manipulate the pixels?
- BM
- eax
- fLayerStruct



Thank you.
Title: Re: CreateDIBitmap
Post by: dedndave on June 13, 2012, 02:23:43 AM
after playing with CreateDIBSection a little bit...
that function will do the job, but i think SetDIBitsToDevice may be more appropriate
i have other things to do, at the moment, but i want to play with it a little
Title: Re: CreateDIBitmap
Post by: masitecno on June 14, 2012, 08:03:10 AM



.data
        CommandLine   dd 0
        hWnd          dd 0
        hInstance     dd 0
        hIcon         dd 0
        hBmp          dd 0
        hBmpBack      dd 0
        szDisplayName db "Captura",0
        theBitmap     HBITMAP       0 
        bmiStruct     BITMAPINFO    {} 
        pbmiStruct    dd bmiStruct     
        bmhStruct     BITMAPINFOHEADER  {} 
        pbmhStruct    dd bmhStruct     
        ppvbits       dd 0

    invoke CreateCompatibleDC,hDC
    mov memDC, eax
   
    invoke SelectObject,memDC,hBmp
    mov hOld, eax

    ;**********************************************************************
    mov bmhStruct.biSize,  40               
    mov bmhStruct.biWidth, 16               ;width
    mov bmhStruct.biHeight, 8               ;height
    mov bmhStruct.biPlanes, 1               ;The number of planes for the target device. This value must be set to 1
    mov bmhStruct.biBitCount, 24            ;bits (0, 1, 2, 4, 8, 16, 24, 32)
    mov bmhStruct.biCompression, BI_RGB     ;BI_RGB, BI_RLE8, BI_RLE4, BI_BITFIELDS, BI_JPEG, BI_PNG
    mov bmhStruct.biSizeImage, 512          ;The size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps.
    mov bmhStruct.biXPelsPerMeter, 1000000  ;not really important
    mov bmhStruct.biYPelsPerMeter, 1000000  ;...
    mov bmhStruct.biClrUsed, 0              ;The number of color indexes in the color table that are actually used by the bitmap.
                                            ;If this value is zero, the bitmap uses the maximum number of colors corresponding to the value
                                            ;of the biBitCount member for the compression mode specified by biCompression.
    mov bmhStruct.biClrImportant, 0         ;The number of color indexes that are required for displaying the bitmap. If this value is zero, all colors are required.

    ;**********************************************************************
    ;
    lea eax, pbmhStruct                   
    mov bmiStruct.bmiHeader,  al     
   
    invoke CreateDIBSection, memDC, pbmiStruct, DIB_RGB_COLORS, ADDR ppvbits, 0, 0
    mov hDibSect, eax



I think i have made a Dibsection but now i don't know how to manipulate the bits, i have the pointer to the bits in ppvbits and a handler to de DIB in hDibSect.
Can anyone tell me if am i right? and if i am, how can i do the manipulation of the bits?
Thanks.
Title: Re: CreateDIBitmap
Post by: dedndave on June 14, 2012, 01:25:40 PM
well - my understanding is that you can only have one bitmap selected into a DC at a time
so - you want to create a second compatible DC and select the DIB section into that
then, you can use BitBlt to copy the image into that DC, if desired

i am playing with a little routine that does something along those lines
it is used to calculate the average color value of an image
once the DIB section is selected into memDC2, i copy the image into it and read the pixel values
the pvBits is an address to the first scan line pixel data
well - that is the game plan, at least   :P
Title: Re: CreateDIBitmap
Post by: masitecno on June 14, 2012, 01:58:44 PM
I am trying to build a DIBitmap to learn how to use the GDI functions I need.

It has been hard for me because there are things i don't know about assembler.

I learn something everyday and i feel one of these days will work.

I appreciate your comments and company throught this hard journey.

Title: Re: CreateDIBitmap
Post by: MichaelW on June 14, 2012, 03:37:48 PM
Quote from: dedndave on June 14, 2012, 01:25:40 PM
my understanding is that you can only have one bitmap selected into a DC at a time

An application cannot select a bitmap into more than one DC at a time.

Title: Re: CreateDIBitmap
Post by: Farabi on June 14, 2012, 05:05:29 PM
Quote from: masitecno on June 12, 2012, 06:49:40 AM
Thanks Farabi...

I made everything possible to run the code you gave me, it did run  :t but i have a question.


    invoke CreateCompatibleDC,hDC
    mov fLayerStruct.DC, eax
   
    invoke SelectObject,memDC,hBmp
    mov fLayerStruct.bmp, eax

    invoke fNewLayer, pfLayerStruct, width1, height

    invoke GetObject,fLayerStruct.bmp,sizeof BITMAP,addr BM


Wich variable should I use to manipulate the pixels?
- BM
- eax
- fLayerStruct



Thank you.

Use the BM and find the member named "bmBits". To manipulate a pixel you can use this method

mov edx,BM.bmBits
mov eax,Pixel_you_want_to_place
mov ecx,Coordinate_you_want_to_place
mov [edx+ecx*4],eax


Dead Simple. Or you can see the .inc file and look any function you might need.

After youre done, blit it to the main DC.


invoke BitBlt,MainDC,0,0,640,480,MyLayer.DC,0,0,SRCCOPY
Title: Re: CreateDIBitmap
Post by: Farabi on June 14, 2012, 05:09:00 PM
Quote from: masitecno on June 12, 2012, 06:49:40 AM
Thanks Farabi...

I made everything possible to run the code you gave me, it did run  :t but i have a question.


    invoke CreateCompatibleDC,hDC
    mov fLayerStruct.DC, eax
   
    invoke SelectObject,memDC,hBmp
    mov fLayerStruct.bmp, eax

    invoke fNewLayer, pfLayerStruct, width1, height

    invoke GetObject,fLayerStruct.bmp,sizeof BITMAP,addr BM


Wich variable should I use to manipulate the pixels?
- BM
- eax
- fLayerStruct



Thank you.

Hi, to create a new layer by using the "fNewLayer" function is only like this


.data

MyLayer fLayer <0>

.code

.uMsg==WM_CREATE
invoke fNewLayer,addr MyLayer ,640,480


And the DC and BMP member will be automatically allocated by the function.

This demo might be usefull http://ompldr.org/vY2wwcg/SW_Graphic.rar
Title: Re: CreateDIBitmap
Post by: masitecno on June 15, 2012, 04:41:01 PM
Again, thanks! Farabi

But know it only displays a one pixel monochromatic bitpam.

Im trying to figure out what am i doing wrong.

Thanks!!
Title: Re: CreateDIBitmap
Post by: masitecno on June 16, 2012, 02:11:38 PM
I have builted a program that creates a DIBSection but when i Blit it, it only shows 1 bit.

Could you please review animate.asm and tell me what is the mistake? what is wrong?

I think BM turns into a one pixel monochromatic bitmap but i don't know how to solve it.

thanks!!
Title: Re: CreateDIBitmap
Post by: dedndave on June 16, 2012, 11:52:16 PM
perhaps Farabi can help - i am not familiar with that method
but - it looks strange that you select an uninitialized BITMAP structure into a DC
Title: Re: CreateDIBitmap
Post by: qWord on June 17, 2012, 12:23:08 AM
Hi masitecno,

Your animation technique not correct: you are implementing a delay while handling the WM_PAINT message. This means that the window can process any message until the animation is finished. A better method is to use a timer (SetTimer) and draw to a memory DC while handling the WM_TIMER-message. This DC is copied to the screen while handling WM_PAINT.
For manipulating the bits, I would use GDI+, because its interface is IMO much simpler for that purpose...

regards, qWord
Title: Re: CreateDIBitmap
Post by: dedndave on June 22, 2012, 10:09:48 PM
here is something to get us started
probably several ways to improve it   :P

i just took my MDI template, and added a few routines
Title: Re: CreateDIBitmap
Post by: dedndave on August 26, 2012, 02:37:37 PM
my first attempt at showing some swallows
needs a little work, but still exciting   :eusa_dance:

(http://img805.imageshack.us/img805/3742/demo1e.png)
Title: Re: CreateDIBitmap
Post by: CodeDog on September 11, 2012, 12:51:38 PM
Here is code to create a 32bpp dib section.

; ==============================================================================
; Creates a 32bpp DIB section, returns 0 on failure, otherwise eax contains handle of dib
; and the variable pointed to by ppvBits will point to the bits data of the DIB section.
; dc should be returned by GetDC so that it can create a compatible DIB section..
; Use SelectObject to select handle of dib into a dc when you need to use it
; Use ppvBits to operate on the bits data.
; Use DeleteObject and the handle of the dib to free it when done
; Remember to select the old object into the dc too when done.
; if w and h are null, it will use the current screen dimensions
ALIGN 16
NewDib32 PROC dc:HDC, ppvBits:PTR DWORD, w:DWORD, h:DWORD
LOCAL bminfo:BITMAPINFO

; Fill in bitmapinfo
xor edx, edx
mov eax, w
mov ecx, h
mov bminfo.bmiHeader.biSize, SIZEOF BITMAPINFOHEADER
mov bminfo.bmiHeader.biPlanes, 1
mov bminfo.bmiHeader.biBitCount, 32
mov bminfo.bmiHeader.biCompression, BI_RGB
neg ecx ; create top down dib, not bottom up (make height signed)
mov bminfo.bmiHeader.biSizeImage, edx
mov bminfo.bmiHeader.biXPelsPerMeter, edx
mov bminfo.bmiHeader.biYPelsPerMeter, edx
mov bminfo.bmiHeader.biClrUsed, edx
mov bminfo.bmiHeader.biClrImportant, edx
.IF eax==0 && ecx==0
INVOKE GetSystemMetrics, SM_CYSCREEN
neg eax
push eax
INVOKE GetSystemMetrics, SM_CXSCREEN
pop ecx
.ENDIF
mov bminfo.bmiHeader.biWidth, eax
mov bminfo.bmiHeader.biHeight, ecx
INVOKE CreateDIBSection, dc, ADDR bminfo, DIB_RGB_COLORS, ppvBits, NULL, 0
ret
NewDib32 ENDP

Title: Re: CreateDIBitmap
Post by: CodeDog on October 06, 2012, 10:04:17 AM
Quote from: dedndave on August 26, 2012, 02:37:37 PM
my first attempt at showing some swallows
needs a little work, but still exciting   :eusa_dance:

Here is a fire demo i've made using dib sections.  :eusa_dance:

(http://i.imgur.com/o0Cyf.png)

Title: Re: CreateDIBitmap
Post by: CodeDog on October 08, 2012, 03:10:22 AM
Playing around with sine and cosine. Not very useful but funny output.

(http://i.imgur.com/L0jFR.png)