News:

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

Create LOGPALETTE method

Started by CObject, July 20, 2005, 12:06:11 PM

Previous topic - Next topic

CObject

Hi All
This part of code create logpalette.
I find out that using 'bswap' is good decision.
What do you think ?


    invoke GetDC,NULL
    mov hDC,eax
   
    invoke GetObject,g_hBmpClock,sizeof(DIBSECTION), addr dbs
    mov eax,dbs.dsBmih.biClrUsed
   
    cmp eax,0
    jne @F
    mov eax,1
    mov cl,byte ptr dbs.dsBmih.biBitCount
    shl eax,cl
@@: mov nColors,eax

    .if eax>256
        invoke CreateHalftonePalette,hDC
        mov g_hPalette,eax
    .else
        mov edx,sizeof(RGBQUAD)
        mul edx

        invoke GlobalAlloc,GMEM_FIXED,eax
        mov pRGB,eax
        invoke CreateCompatibleDC,hDC
        mov hMemDC,eax
        invoke SelectObject,eax,g_hBmpClock
        mov hOldBitmap,eax
        invoke GetDIBColorTable,hMemDC,0,nColors,pRGB
        mov edx,sizeof(PALETTEENTRY)
        mov eax,nColors
        mul edx
        add eax,sizeof(LOGPALETTE)
        invoke GlobalAlloc,GMEM_FIXED,eax
        mov pLP,eax
        mov ecx,nColors
        mov (LOGPALETTE ptr [eax]).palVersion,300h
        mov (LOGPALETTE ptr [eax]).palNumEntries,cx
        mov ebx,pRGB

@@:     mov edx,[ebx]  ; Create colours for LOGPALETTE !!!
        bswap edx           ; Critical part
        shr edx,8
        mov (LOGPALETTE ptr [eax]).palPalEntry,edx
        add ebx,sizeof(RGBQUAD)
        add eax,sizeof(PALETTEENTRY)
        dec ecx
        jnz @B

        invoke CreatePalette,pLP
        mov g_hPalette,eax
        invoke SelectObject,hMemDC,hOldBitmap
        invoke DeleteDC,hMemDC
        invoke GlobalFree,pLP
        invoke GlobalFree,pRGB
    .endif
 
    invoke ReleaseDC,NULL,hDC