Author Topic: GetDIBits instruction  (Read 483 times)

shankle

  • Member
  • ****
  • Posts: 783
GetDIBits instruction
« 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.
    

HSE

  • Member
  • ****
  • Posts: 711
  • <AMD>< 7-32>
Re: GetDIBits instruction
« Reply #1 on: June 19, 2018, 02:10:27 AM »
It's a little tricky.

Code: [Select]
local srcedibbmap : BITMAPINFOHEADER
Code: [Select]
  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

BugCatcher

  • Regular Member
  • *
  • Posts: 42
Re: GetDIBits instruction
« Reply #2 on: June 20, 2018, 01:47:08 AM »
Try dropping the  "addr bi.BITMAPINFO"
to "addr bi". Make sure bi is a BITMAPINFO structure.

shankle

  • Member
  • ****
  • Posts: 783
Re: conversion
« Reply #3 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.
    

Yuri

  • Member
  • **
  • Posts: 168
Re: GetDIBits instruction
« Reply #4 on: June 21, 2018, 03:20:35 PM »
Code: [Select]
mov eax,[dwBmpSize]
add eax,sizeof BITMAPFILEHEADER
add eax,sizeof BITMAPINFOHEADER
mov [dwSizeofDIB],eax

shankle

  • Member
  • ****
  • Posts: 783
Re: GetDIBits instruction
« Reply #5 on: June 21, 2018, 08:47:53 PM »
Thank you very much Yuri.
It sure helps to be familiar with C.
I'm not.

shankle

  • Member
  • ****
  • Posts: 783
Re: 3 writefile nightmares
« Reply #6 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.
    

Yuri

  • Member
  • **
  • Posts: 168
Re: GetDIBits instruction
« Reply #7 on: June 22, 2018, 07:09:47 PM »
Code: [Select]
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

shankle

  • Member
  • ****
  • Posts: 783
general conversion
« Reply #8 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.

Yuri

  • Member
  • **
  • Posts: 168
Re: GetDIBits instruction
« Reply #9 on: June 25, 2018, 05:21:12 PM »
BITMAP is a structure.
Code: [Select]
BITMAP STRUCT
bmType DD
bmWidth DD
bmHeight DD
bmWidthBytes DD
bmPlanes DW
bmBitsPixel DW
bmBits PTR
ENDS

zedd151

  • Member
  • ****
  • Posts: 706
Re: GetDIBits instruction
« Reply #10 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
 
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
 
...

shankle

  • Member
  • ****
  • Posts: 783
Re: GetDIBits instruction
« Reply #11 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