The MASM Forum

Projects => Rarely Used Projects => GoAsm => Topic started by: shankle on June 19, 2018, 12:30:14 AM

Title: GetDIBits instruction
Post by: shankle on June 19, 2018, 12:30:14 AM
                 6-18-2018

    GetDIBits instruction
     Need to convert this "C" instruction to a GoASm format:

    GetDIbits(hdcWindow, hbmscreen, 0, (UINT)bmpScreen.bmHeight,
              lpbitmap,(BITMAPINFO *)&bi, DIB_RGB_COLORS)

     Not being a "C" programmer I am getting a compile time error
    at (BITMAPINFO *)&bi

    Here is my code:
       invoke GetDIBits,[hdcwindow],[hbmscreen],0,40,[lpbitmap],\
       addr bi.BITMAPINFO,DIB_PAL_COLORS

    Thanks for any help.
   
Title: Re: GetDIBits instruction
Post by: HSE on June 19, 2018, 02:10:27 AM
It's a little tricky.

local srcedibbmap : BITMAPINFOHEADER

  SetObject esi
   
    invoke BeginPaint, [esi].hWnd, addr PS
    mov hDC, eax
   
    ;counter_begin 1000, HIGH_PRIORITY_CLASS

invoke CreateCompatibleDC, hDC
mov memdc, eax

    invoke GetClientRect, [esi].hWnd,  addr [esi].total

invoke CreateCompatibleBitmap, hDC, [esi].total.right,  [esi].total.bottom
mov hbm , eax
invoke SelectObject, memdc, eax
mov hOld,eax

;paint into memoryDC
invoke SelectObject, memdc, [esi].BLUE_BRUSH

invoke PatBlt, memdc, 0, 0,[esi].total.right, [esi].total.bottom,PATCOPY
   
invoke SelectObject, memdc, [esi].hFntGUI
;mov hFontOld , eax

mov srcedibbmap.biSize , sizeof BITMAPINFOHEADER
m2m srcedibbmap.biWidth , [esi].total.right
fSlv srcedibbmap.biHeight = -1*[esi].total.bottom
mov srcedibbmap.biPlanes , 1
mov srcedibbmap.biBitCount , 32
mov srcedibbmap.biCompression , BI_RGB

mov eax , [esi].total.right
shl   eax , 2
mov ecx , [esi].total.bottom
mul ecx
invoke GlobalAlloc, GMEM_FIXED+GMEM_ZEROINIT, eax
mov [esi].array3D, eax
DbgApiError
invoke GetDIBits, memdc, hbm, 0, [esi].total.bottom, [esi].array3D, addr srcedibbmap, DIB_RGB_COLORS
Title: Re: GetDIBits instruction
Post by: BugCatcher on June 20, 2018, 01:47:08 AM
Try dropping the  "addr bi.BITMAPINFO"
to "addr bi". Make sure bi is a BITMAPINFO structure.
Title: Re: conversion
Post by: shankle on June 21, 2018, 06:53:43 AM
                 6-20-2018

    how to convert this "c" code to GoASM
   
   DWORD dwSizeofDIB = dwBmpSize + sizeof(BITMAPFILEHEADER) +\
        sizeof(BITMAPINFOHEADER)

;  this is my code - gives an error
BITMAPINFOHEADER STRUCT
   biSize        DD
   biWidth       DD
   biHeight      DD
   biPlanes      DW
   biBitCount    DW
   biCompression DD
   biSizeImage   DD
   biXPelsPerMeter DD
   biYPelsPerMeter DD
   biClrUsed       DD
   biClrImportant  DD
ENDS

BITMAPFILEHEADER STRUCT
   bfType DW
   bfSize DD
   bfReserved1 DW
   bfReserved2 DW
   bfOffBits DD
ENDS

dwBmpSize      dd  0
dwSizeofDIB    dd  0

    mov D[dwSizeofDIB],[D[dwBmpSize] + sizeof BITMAPFILEHEADER +\
       sizeof BITMAPINFOHEADER]

    Thanks for any help.
   
Title: Re: GetDIBits instruction
Post by: Yuri on June 21, 2018, 03:20:35 PM

mov eax,[dwBmpSize]
add eax,sizeof BITMAPFILEHEADER
add eax,sizeof BITMAPINFOHEADER
mov [dwSizeofDIB],eax
Title: Re: GetDIBits instruction
Post by: shankle on June 21, 2018, 08:47:53 PM
Thank you very much Yuri.
It sure helps to be familiar with C.
I'm not.
Title: Re: 3 writefile nightmares
Post by: shankle on June 22, 2018, 05:49:35 AM
                 6-21-2018

    how to convert this "c" code to GoASM

    DWORD dwBytesWritten = 0;
    WriteFile(hFile, (LPSTR)&bmfHeader, sizeof(BITMAPFILEHEADER),\
                     &dwBytesWritten, NULL);
    WriteFile(hFile, (LPSTR)&bi, sizeof(BITMAPINFOHEADER),\
                     &dwBytesWritten, NULL);
    WriteFile(hFile, (LPSTR)lpbitmap, dwBmpSize, &dwBytesWritten, NULL);
;........................................................


;   I haven't coded the above.
    I have used WriteFile many times but have never converted writefile
   from C to GoAasm

    dwBmpSize      dd  0
    dwBytesWritten dd  0
    lpbitmap       db 140 DUP ' ' ; have no idea if this size is correct
    LOCAL  ps:PAINTSTRUCT,pt:POINT,RR:RECT,pBmp,bm:BITMAP
    LOCAL  bi:BITMAPINFOHEADER,bmfHeader:BITMAPFILEHEADER

; coded this way because GoAsm says the fields are not filled in yet????
    mov eax,((200 * 32 + 31) / 32) * 4 * 40  ; might not be correct
;?  any attempt too convert this code gives an error at compile time....
;?  DWORD dwBmpSize = ((bmpScreen.bmWidth * bi.biBitCount + 31) / 32) * 4 *\
;?                    bmpScreen.bmHeight;
    mov [dwBmpSize],eax

BITMAPINFOHEADER STRUCT
   biSize        DD
   biWidth       DD
   biHeight      DD
   biPlanes      DW
   biBitCount    DW
   biCompression DD
   biSizeImage   DD
   biXPelsPerMeter DD
   biYPelsPerMeter DD
   biClrUsed       DD
   biClrImportant  DD
ENDS

BITMAPFILEHEADER STRUCT
   bfType DW
   bfSize DD
   bfReserved1 DW
   bfReserved2 DW
   bfOffBits DD
ENDS

    Thanks for any help.
   
Title: Re: GetDIBits instruction
Post by: Yuri on June 22, 2018, 07:09:47 PM

invoke WriteFile, [hFile], addr bmfHeader, sizeof BITMAPFILEHEADER, \
                    addr dwBytesWritten, 0
invoke WriteFile, [hFile], addr bi, sizeof BITMAPINFOHEADER, \
                    addr dwBytesWritten, 0
invoke WriteFile, [hFile], addr bitmap, [dwBmpSize], addr dwBytesWritten, 0
Title: general conversion
Post by: shankle on June 25, 2018, 08:09:43 AM
            6-23-2018
   
    HDC hdcScreen;
    HDC hdcWindow;
    HDC hdcMemDC = NULL;
    HBITMAP hbmScreen = NULL;
    BITMAP bmpScreen
   

HDC                dq  0
hbmScreen      dq  0
hdcMemDC       dq  0
hdcWindow      dq  0
bmpScreen      dq  0

Thanks for any help.
Title: Re: GetDIBits instruction
Post by: Yuri on June 25, 2018, 05:21:12 PM
BITMAP is a structure.

BITMAP STRUCT
bmType DD
bmWidth DD
bmHeight DD
bmWidthBytes DD
bmPlanes DW
bmBitsPixel DW
bmBits PTR
ENDS
Title: Re: GetDIBits instruction
Post by: zedd151 on June 25, 2018, 05:31:30 PM
Vortex has a nice example of how to fill in the BitmapInfoHeader structure:

http://masm32.com/board/index.php?topic=7185.msg77638#msg77638 (http://masm32.com/board/index.php?topic=7185.msg77638#msg77638)

It's 64 bit code, but it should give you a reasonable feel for where the values are coming from and where they belong in the structure.

Hope this helps.

edit to add:
From MSDN:

https://msdn.microsoft.com/en-us/library/windows/desktop/dd144879(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/windows/desktop/dd144879(v=vs.85).aspx)

...
Title: Re: GetDIBits instruction
Post by: shankle on June 26, 2018, 02:17:32 AM
What I need to do is what a 3rd party program does called "Faststone Capture" but it
is way to slow for my needs. I want to capture a small portion of a game screen and
compare it to each of the 52 cards to find a match then record it into a window in my
program. I don't know if Vortex's program does this or not. I have been playing with
a Microsoft program called "Capture an image" but so far without much luck.
The "C" thing and I don't get along very well.
AND if I am correct I don't want a bitmap but the same thing I see in the game screen.
Maybe this explanation will help you to guide me to where I can read what I want to
do.
Thanks for all your help.
GoAsm, 64-bit, windows 7 pro 64-bit