Page 1 of 1

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

Posted: Wed Feb 03, 2010 5:25 pm
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

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

Posted: Wed Feb 03, 2010 5:41 pm
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

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

Posted: Thu Feb 04, 2010 11:34 am
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

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

Posted: Sat Feb 06, 2010 2:15 am
by Rescator
Yeah, what the... How can that be faster? One would assume that CopyImage does that.. or? *looks at Fred*