News:

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

BITMAP Compression

Started by georgek01, April 19, 2007, 03:21:12 PM

Previous topic - Next topic

georgek01

Hello!

I'm using the following code to create a BITMAP. When the biCompression member for BITMAPINFOHEADER is set to BI_RGB, all works fine. However, I would like the BITMAP to be compressed, so I change the member to BI_RLE8 - the procedure then fails when CreateDIBSection is invoked.

What other memebers do I have to change for the BITMAP to be created with compression?


local bmpinfo:BITMAPINFO

    invoke GetDC,0
    mov hdc,eax
    .IF (eax==NULL)
        invoke MessageBox, 0, addr szNoDC, NULL, 0
        jmp ExitFunc
    .ENDIF

    invoke GetDeviceCaps, hdc, BITSPIXEL
    mov dwBPP,eax
    .IF (eax<=8)
        invoke GetDeviceCaps, hdc, NUMCOLORS
        mov dwNumColors,eax
    .ELSE
        mov dwNumColors,0
    .ENDIF

    invoke GetDeviceCaps, hdc, LOGPIXELSY
    mov pixelHeight,eax

    invoke CreateCompatibleDC,hdc
    mov memdc,eax
    .IF (eax==NULL)
        invoke DeleteDC, hdc
        invoke MessageBox, 0, addr szNoMemDC, NULL, 0
        jmp ExitFunc
    .ENDIF

invoke ReleaseDC,0,hdc
invoke DeleteDC,hdc

    mov bmpinfo.bmiHeader.biSize,sizeof BITMAPINFOHEADER
    mov eax,dwWidth
    mov bmpinfo.bmiHeader.biWidth,eax
    mov eax,dwHeight
    mov bmpinfo.bmiHeader.biHeight,eax
    mov bmpinfo.bmiHeader.biPlanes,1
    mov ax,word ptr [dwBPP]
    mov bmpinfo.bmiHeader.biBitCount,ax
    mov bmpinfo.bmiHeader.biCompression,BI_RLE8 ;BI_RGB
    mov bmpinfo.bmiHeader.biSizeImage,0
    mov bmpinfo.bmiHeader.biXPelsPerMeter,0
    mov bmpinfo.bmiHeader.biYPelsPerMeter,0
    mov eax,dwNumColors
    mov bmpinfo.bmiHeader.biClrUsed,eax
    mov bmpinfo.bmiHeader.biClrImportant,eax

    invoke CreateDIBSection,memdc,addr bmpinfo,DIB_RGB_COLORS,addr pBits, NULL, 0
    mov hBitmap,eax
    .IF (eax==NULL)
        invoke DeleteDC, hdc
        invoke DeleteDC, memdc
        invoke MessageBox, 0, addr szNoBMP, NULL, 0
        jmp ExitFunc
    .ENDIF
       
    invoke SelectObject, memdc, hBitmap
    .IF (eax==NULL) || (eax==GDI_ERROR)
        invoke DeleteDC, hdc
        invoke DeleteDC, memdc
        invoke MessageBox, 0, addr szNoObj, NULL, 0
        jmp ExitFunc
    .ENDIF


Assistance will be greatly appreciated!

Regards,
George
What we have to learn to do, we learn by doing.

- ARISTOTLE (384-322 BC)

MichaelW

On most systems the call to GetDeviceCaps, hdc, BITSPIXEL will return 32, and BI_RLE8 is only for bitmaps with 8 bpp.
eschew obfuscation

zooba

Also, a DIB is always 32bpp. The BI_RLE8 value is probably only relevant for file loading/saving.

Cheers,

Zooba :U

georgek01

What we have to learn to do, we learn by doing.

- ARISTOTLE (384-322 BC)