BitBlt_() and the new 2D Lib (PB4.4x)

Everything else that doesn't fall into one of the other PB categories.
dige
Addict
Addict
Posts: 1432
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

BitBlt_() and the new 2D Lib (PB4.4x)

Post by dige »

I use a nice API code, to copy images faster than
PB's CopyImage().

But I've got some IMA Errors since PB4.40 and
unfortunately I was'nt able to find a reproducable
way..
So I ask myself, is this way of copy still valid?

What do you think?

Code: Select all

Procedure.l CopyImageEx( SourceID.l, DestID.l ) ; Result: DestID, -1 = Failed
  Protected success.b, ImgID.i
    
  If IsImage( SourceID )
    bmp.l = ImageID(SourceID)
    w.l   = ImageWidth(SourceID)
    h.l   = ImageHeight(SourceID)
    d.l   = ImageDepth(SourceID)
    
    DC.l  = CreateCompatibleDC_(#Null)
    
    If Not DC : ProcedureReturn -1 : EndIf
    
    NewImgID = CreateImage( DestID, w, h, d)
    
    If DestID = #PB_Any : DestID = NewImgID : EndIf
    
    If IsImage(DestID)
      If SelectObject_(DC, bmp)
        tdc = StartDrawing( ImageOutput(DestID) )
          If tdc
            BitBlt_(tdc,0,0,w,h,DC,0,0,#SRCCOPY)
          StopDrawing()
          success = #True
        EndIf
      EndIf
    EndIf  
    DeleteDC_(DC)
  EndIf
  
  If Not success
    DestID = -1
  EndIf
  
  ProcedureReturn DestID
EndProcedure

CreateImage(0, 100, 100, 1)
CreateImage(1, 100, 100, 2)
CreateImage(2, 100, 100, 4)
CreateImage(3, 100, 100, 8)
CreateImage(4, 100, 100, 16)
CreateImage(5, 100, 100, 24)
CreateImage(6, 100, 100, 32)
CreateImage(7, 100, 100)
CreateImage(8, 100, 100, #PB_Image_DisplayFormat)

For n = 0 To 8
  Debug Str(ImageDepth(n)) + "Bit, Result: " + Str(CopyImageEx(n, #PB_Any))
Next
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: BitBlt_() and the new 2D Lib (PB4.4x)

Post by Trond »

But I've got some IMA Errors since PB4.40 and
unfortunately I was'nt able to find a reproducable
way..
So I ask myself, is this way of copy still valid?
I get an error with 4.31 as well.

How is this for you? It's twice as fast as CopyImage().

Code: Select all

Procedure CopyImageSprint(Image1, Image2)
  ProcedureReturn GrabImage(Image1, Image2, 0, 0, ImageWidth(Image1), ImageHeight(Image1))
EndProcedure
dige
Addict
Addict
Posts: 1432
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: BitBlt_() and the new 2D Lib (PB4.4x)

Post by dige »

Trond wrote: How is this for you? It's twice as fast as CopyImage().

Code: Select all

Procedure CopyImageSprint(Image1, Image2)
  ProcedureReturn GrabImage(Image1, Image2, 0, 0, ImageWidth(Image1), ImageHeight(Image1))
EndProcedure
@Trond, what the .... ?!?! :shock: thats much more faster than CopyImage and the API one - great!!!
Thank you very much. :D
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Re: BitBlt_() and the new 2D Lib (PB4.4x)

Post by Rescator »

Yeah, what the... How can that be faster? One would assume that CopyImage does that.. or? *looks at Fred*
Post Reply