News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

CreateDIBitmap

Started by masitecno, May 31, 2012, 12:47:34 PM

Previous topic - Next topic

masitecno

I wasn't available this week because of health problems.

Sorry.

I'm back so, we will keep on working.
Thanks everyone.

masitecno


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.



dedndave

welcome back - hope you're feeling better   :t

i am almost done with my other little project   :P

Farabi

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.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

masitecno

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.

dedndave

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

masitecno




.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.

dedndave

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

masitecno

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.


MichaelW

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.

Well Microsoft, here's another nice mess you've gotten us into.

Farabi

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
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Farabi

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
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

masitecno

Again, thanks! Farabi

But know it only displays a one pixel monochromatic bitpam.

Im trying to figure out what am i doing wrong.

Thanks!!

masitecno

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!!

dedndave

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