Liberty BASIC Community Forum
« bitblt ? »

Welcome Guest. Please Login or Register.
Jan 22nd, 2018, 5:50pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: bitblt ?  (Read 212 times)
bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 936
xx bitblt ?
« Thread started on: Aug 19th, 2017, 08:17am »

fount in a old vb6 book
i m not sure how to use it

the rap value's were not listed

Code:
end
sub BitBlt hdestdc,dx,dy,width,height,srcdc,sx,sy,rap
  calldll #gdi32 , "BitBlt"_
    hdestdc as long _
    dx as long _
    dy as long _
    width as long _
    height as long _
    hsrcdc as long _
    sx as long _
    sy as long _
    rap as long _
    ret as long
end sub
 
User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5618
xx Re: bitblt ?
« Reply #1 on: Aug 19th, 2017, 09:20am »

There are several examples of how to use bitblt and other blitter calls on the LBPE.
User IP Logged

benjamin805
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 419
xx Re: bitblt ?
« Reply #2 on: Aug 27th, 2017, 9:09pm »

This program I made using BitBlt and PatBlt. Maybe it can help you out.

Code:
'BMP rotation example
'
'Updated code Nov 26, 2012
'Cleaned up the code
'Fixed some bugs
'
'This example shows how to
'rotate a bitmap image
'in memory and display in a graphic
'box.
'some source code converted from
'http://www.ucancode.net/Visual_C_MFC_Example/Rotate-bitmap-dib-image-file-vc-example.htm
'toFloat code used from
'http://www.b6sw.com/forum/content.php?mode=hints&t=223


'w= new bitmap width
'h= new bitmap height
'for this example I just used the whole window width and height.

'rotateX=x point on new bmp to rotate image on
'rotateY=y point on new bmp to rotate image on
'These values can be changed to rotate the image on
'different points


'setup window
    nomainwin

    WindowWidth=400
    WindowHeight=400

    UpperLeftX=100
    UpperLeftY=100

    open "Rotate Bitmap Example" for graphics_nsb as #g
    #g,"trapclose [exit]";

    'get graphic window handle and dc
    hWnd=hwnd(#g)
    hDC=GetDC(hWnd)

    pi=3.14159265

    'load bmp
    filedialog "Load BMP","*.bmp",loadBMP$
        if loadBMP$<>"" then
            loadbmp "bmp",loadBMP$
            null=GetBMPInfo("bmp")
            bitmapHwnd=hbmp("bmp") 'get bmp handle


            'set new bitmap size using window width & height
            w=WindowWidth
            h=WindowHeight

            xPos=int((WindowWidth-w)/2)
            yPos=int((WindowHeight-h)/2)

            angle=0 'start angle

            'setup workspace for rotation
            sourceDC=CreateCompatibleDC(hDC)
            destDC=CreateCompatibleDC(hDC)

            'setup fill color for bitmap
            PixCol=16777215
            nbrush=CreateSolidBrush(PixCol)
            oldBrush=SelectObject(destDC,nbrush)
            'make new bmp image
            newBitmap=CreateCompatibleBitmap(hDC,w,h)


            timer 40, [rotate]
        end if
    wait


[rotate]   'rotate sprite

    scan
   
     'convert degree to radians
     radians=(2*pi*angle)/360

     'set cosine and sine values using our converted degree
     cosine=cos(radians)
     sine=sin(radians)


    'put new bitmap into dest dc
     hbmOldDest=SelectObject(destDC,newBitmap)

   '  null=ExtFloodFill(destDC,0,0,0,1)
    null=PatBlt(destDC,0,0,w,h,_PATCOPY)

    'put bmp into source dc
     hbmOldSource=SelectObject(sourceDC,bitmapHwnd)


    'set graphcis mode of destdc to allow rotation
     null=SetGraphicsMode(destDC,2)



    'setup rotation struct
     struct xform,_
     eM11 as ulong,_
     eM12 as ulong,_
     eM21 as ulong,_
     eM22 as ulong,_
     eDx as ulong,_
     eDy as ulong

    'fill rotation values
     xform.eM11.struct=toFloat(cosine)
     xform.eM12.struct=toFloat(sine)
     xform.eM21.struct=toFloat(-1*sine)
     xform.eM22.struct=toFloat(cosine)

     'set x y point on the new bmp you want to rotate source image on
     rotateX= int(BITMAP.bmWidth.struct/2)+int((w-BITMAP.bmWidth.struct)/2)
     rotateY= int(BITMAP.bmHeight.struct/2)+int((h-BITMAP.bmHeight.struct)/2)


     xform.eDx.struct=toFloat(rotateX-cosine*rotateX+sine*rotateY)
     xform.eDy.struct=toFloat(rotateY-cosine*rotateY-sine*rotateX)

     'rotate bitmap
     r=SetWorldTransform(destDC,xform)



     'put our source bitmap into our dest dc
     null=BitBlt(destDC,int((w-BITMAP.bmWidth.struct)/2),int((h-BITMAP.bmHeight.struct)/2),w,h,sourceDC, 0 ,0 , _SRCCOPY)

     'set graphcis mode of destdc to allow rotation
     null=SetGraphicsMode(destDC,1)


     'release new rotated bitmap
     null=SelectObject(destDC,hbmOldDest)


     'put rotated bitmap into sourceDC
     hbmOldSource=SelectObject(sourceDC,newBitmap)

     'draw rotated bitmap onto screen into our dest dc
     null=BitBlt(hDC,xPos,yPos,w,h,sourceDC,0 ,0 , _SRCCOPY)


     null=SelectObject(sourceDC,hbmOldSource)

     angle=angle+2

     wait



    [exit]
   timer 0

   null=DeleteObject(newBitmap)
   'clean up
   'release source bitmap from dc
   null=SelectObject(sourceDC,hbmOldSource)'release
   null=SelectObject(destDC,oldBrush)
   null=DeleteObject(nbrush)
   null=DeleteDC(sourcDC)
   null=DeleteDC(destDC)
   close #g
   end



'--------------functions----------------------------------------

Function GetBMPInfo(bmp$)

    bitmapHwnd=hbmp(bmp$) 'get bmp handle

    'create struct for bmp info
    struct BITMAP,_
    bmType As long,_
    bmWidth As long,_
    bmHeight As long,_
    bmWidthBytes As long,_
    bmPlanes As word,_
    bmBitsPixel As word,_
    bmBits As long

    structSize=Len(BITMAP.struct)'get the size of the struct:

    CallDLL #gdi32, "GetObjectA",_
    bitmapHwnd As ulong,_   'handle of bitmap
    structSize As long,_      'size of struct
    BITMAP As struct,_   'name of struct
    GetBMPInfo As long

End Function

Function GetPixel(hdc,xpos,ypos)
    CallDll #gdi32,"GetPixel",_
    hdc as Ulong,_
    xpos as long,_
    ypos as long,_
    GetPixel as Ulong
End Function


Function SetWorldTransform(hdc,xform)
    CallDLL #gdi32, "SetWorldTransform",_
        hdc As ULong,_
        xform As struct,_
        SetWorldTransform As Long
End Function

Function SetGraphicsMode(hdc,iMode)
CallDll #gdi32,"SetGraphicsMode",_
    hdc as Ulong,_
    iMode as ulong,_
    SetGraphicsMode as long
End Function

Function GetDC(handle)
    CallDLL #user32, "GetDC", _
        handle As Ulong, _
        GetDC as Ulong
End Function

Function ReleaseDC(handle, hDC)
    CallDLL #user32, "ReleaseDC", _
        handle As Ulong, _
        hDC As Ulong, _
        ReleaseDC As Long
End Function

Function DeleteDC(hDC)
    CallDLL #gdi32, "DeleteDC", _
        hDC as Ulong, _
        result as Boolean
End Function

Function CreateCompatibleDC(hDC)
    CallDLL #gdi32, "CreateCompatibleDC", _
        hDC as Ulong, _
        CreateCompatibleDC as Ulong
End Function

Function CreateCompatibleBitmap(hDC, wMem, hMem)
    CallDLL #gdi32, "CreateCompatibleBitmap", _
        hDC as Ulong, _
        wMem as Long, _
        hMem as Long, _
        CreateCompatibleBitmap as Ulong
End Function

Function SelectObject(hDC, hPic)
    CallDLL #gdi32, "SelectObject", _
        hDC as Ulong, _
        hPic as Ulong, _
        SelectObject as Ulong
End Function

Function BitBlt(hdcDest, xDest, yDest, wDest, hDest, hdcSource, xSource, ySource, ROP)
    CallDLL #gdi32, "BitBlt", _
        hdcDest as Ulong, _
        xDest as Long, _
        yDest as Long, _
        wDest as Long, _
        hDest as Long, _
        hdcSource as Ulong, _
        xSource as Long, _
        ySource as Long, _
        ROP as Ulong, _
        result as Boolean
End Function

Function toFloat( R8 )
  Open "oleaut32" For DLL As #oleaut32
'-- Converts a 64-bit Double to a 32-bit number.
    Struct local1, R4 As ULong
    CallDLL #oleaut32, "VarR4FromR8", _
        R8 As Double, local1 As Struct, _
        ret As Long
    toFloat = local1.R4.struct
    close #oleaut32
End Function


Function DeleteObject(objHandle)
    CallDll #gdi32,"DeleteObject",_
        objHandle as Ulong,_
        DeleteObject as long
End Function

Function PatBlt(hdc,nx,ny,nw,nh,style)
    CallDll #gdi32,"PatBlt",_
      hdc as Ulong,_
      nx as long,_
      ny as long,_
      nw as long,_
      nh as long,_
      style as ulong,_
      PatBlt as boolean
End Function

Function CreateSolidBrush(bcolor)
    CallDll #gdi32,"CreateSolidBrush",_
        bcolor as long,_
        CreateSolidBrush as Ulong
End Function
 
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls