News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

GetBitmapBits

Started by guga, September 16, 2013, 03:23:47 AM

Previous topic - Next topic

guga

This is a variation of GetBitmapBits function. The parameters and functionality are the same ones as in GDI file


; BITMAPINFO structure
; necessary to obtain the pixels of the bitmap
[OutBmpNfo:
OutBmpNfo.bmiHeader.biSize: D$ len
OutBmpNfo.bmiHeader.biWidth: D$ 0
OutBmpNfo.bmiHeader.biHeight: D$ 0
OutBmpNfo.bmiHeader.biPlanes: W$ 0
OutBmpNfo.bmiHeader.biBitCount: W$ 0
OutBmpNfo.bmiHeader.biCompression: D$ 0
OutBmpNfo.bmiHeader.biSizeImage: D$ 0
OutBmpNfo.bmiHeader.biXPelsPerMeter: D$ 0
OutBmpNfo.bmiHeader.biYPelsPerMeter: D$ 0
OutBmpNfo.bmiHeader.biClrUsed: D$ 0
OutBmpNfo.bmiHeader.biClrImportant: D$ 0
OutBmpNfo.bmiColors.rgbBlue: B$ 0
OutBmpNfo.bmiColors.rgbGreen: B$ 0
OutBmpNfo.bmiColors.rgbRed: B$ 0
OutBmpNfo.bmiColors.rgbReserved: B$ 0]

[Size_of_BITMAPINFO 44]

Proc GetBitmapBits:
    Arguments @hbmp, @cbBuffer, @lpvBits
    Local @byPixel, @hdcImage, @MemData
    Structure @BITMAP 24, @BITMAP.bmTypeDis 0, @BITMAP.bmWidthDis 4, @BITMAP.bmHeightDis 8, @BITMAP.bmWidthBytesDis 12, @BITMAP.bmPlanesDis 16,
              @BITMAP.bmBitsPixelDis 18, @BITMAP.bmBitsDis 20
    Uses ebx, esi, edi, ecx, edx

    ; Allocate the necessary amount of memory to hold the BitMapBits
    lea eax D@MemData | mov D@MemData 0
    call 'RosMem.VMemAlloc' eax, D@cbBuffer | mov D@byPixel eax
    If eax = &NULL
        ; Not enough memory
        xor eax eax
        ExitP
    End_If

    call 'RosMem.ZeroMemory' OutBmpNfo, Size_Of_BITMAP
    call 'GDI32.GetObjectA' D@hbmp, Size_Of_BITMAP, D@BITMAP ; get informations about the bitmap
    On eax = 0, ExitP ; On error, exit

    ;A bit of information is necessary for GetDIBits to work. So starty filling only what is needed.
    mov D$OutBmpNfo.bmiHeader.biSize Size_of_BITMAPINFO
    move D$OutBmpNfo.bmiHeader.biWidth D@BITMAP.bmWidthDis

    move D$OutBmpNfo.bmiHeader.biHeight D@BITMAP.bmHeightDis

    mov W$OutBmpNfo.bmiHeader.biPlanes 1
    mov eax D@BITMAP.bmBitsPixelDis
    mov W$OutBmpNfo.bmiHeader.biBitCount ax
    mov D$OutBmpNfo.bmiHeader.biCompression &BI_RGB ; compression (no)

    call 'GDI32.CreateCompatibleDC' &NULL | mov D@hdcImage eax
    call 'GDI32.GetDIBits' eax, D@hbmp, 0, D$OutBmpNfo.bmiHeader.biHeight, D@byPixel, OutBmpNfo, &DIB_PAL_COLORS ; obtain the image from HBITMAP
    call 'GDI32.DeleteDC' D@hdcImage

    call 'RosMem.memcpy' D@lpvBits, D@byPixel, D@cbBuffer
    ; release the allocated memory
    call 'RosMem.VMemFree' D@byPixel
    mov eax &TRUE

EndP


Note: the function VMemAlloc/VmemFree are only a customized virtualmemory allocation/deallocation inside RosAsm, that i made in the form of a dll (I´m trying to rebuild RosAsm with separated tools) instead forcing it to be on a huge monoblock file.

This function i wrote it as:

Proc VMemAlloc::
    Arguments @pMem, @MemSize
    Local @Result

    mov D@Result 0
    pushad
        VirtualAlloc D@pMem, D@MemSize
        mov D@Result eax
    popad

    mov eax D@Result

EndP



Proc VMemFree::
    Arguments @pMem
    Local @Result

    mov D@Result 0
    pushad
        VirtualFree D@pMem
        If eax = 0
            mov D@Result &FALSE
        Else
            mov D@Result &TRUE
        End_If
    popad

    mov eax D@Result

EndP


VirtualAlloc and VirtualFree are the internal macros in RosAsm to handle Virtual Memory. You can find them in the last updated version
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com