News:

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

Main Menu

GetBitmapBitsEx

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

Previous topic - Next topic

guga

An extension of GetBitmapBits function.

This function works the same as GetBitmapBits, but it does not need to compute the total amount of pixels used. The amount of pixels must be precomputed/allocate by the user. So, this function "per se" is faster then the one existence in GDI, since it does not need to copy any buffer. Insetad copying and creting new memory to be allocated it uses the previously allocated user to hold the bits.

This is particulary usefull when loading huge images, such as HDR files.


; a variation of GetBitmapBits. The total amount of buffer must be previously computed
Proc GetBitmapBitsEx:
    Arguments @hbmp, @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

    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@lpvBits, OutBmpNfo, &DIB_PAL_COLORS ; obtain the image from HBITMAP
    call 'GDI32.DeleteDC' D@hdcImage
    mov eax &TRUE

EndP


For more info about the structures and other functions used on this, please see GetBitmapBits function

Example of usage:

        call 'GDI32.GetObjectA' D$esi+CIMAGE.m_hBmpDis, Size_Of_BITMAP, D@BITMAP
        move D$esi+CIMAGE.m_iHeightDis D@BITMAP.bmHeightDis
        move D$esi+CIMAGE.m_iWidthDis D@BITMAP.bmWidthDis
        xor eax eax
        mov edx D$esi+CIMAGE.m_iWidthDis | imul edx D$esi+CIMAGE.m_iHeightDis | shl edx 2 | mov D@TotalPixelSize edx
        mov D@MemPix 0 | lea eax D@MemPix
        call 'RosMem.VMemAlloc' eax, edx | mov D$esi+CIMAGE.m_ucpBitsDis eax

        call GetBitmapBitsEx D$esi+CIMAGE.m_hBmpDis, D$esi+CIMAGE.m_ucpBitsDis



Example of my new image viewer i´m trying to build
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