It is currently Sat Dec 14, 2019 10:35 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: CustomFilterCallback() custom parameter! (Windows x64)
PostPosted: Wed May 08, 2019 8:13 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 577
Since PureBasic does not allow custom parameters (i hope this gets added eventually).
Here is some hackish way to add a additional custom parameter to the not so CustomFilterCallback()

Code for x64 (needs a test image):
Code:
EnableExplicit

UseJPEGImageDecoder()

Procedure.i FilterImageCallback(X.i,Y.i,ColorSrc.i,ColorDst.i)
  Protected *parameter
  !mov rax,[rsp + 150h]                                ;<- locate the image structure
  !mov rax,[rax + 20h]                                 ;<- extract the custom parameter
  !mov qword[p.p_parameter],rax
  Debug *parameter
  ProcedureReturn ColorSrc
EndProcedure

Procedure.i FilterImage(*Buffer,Path.s = #Null$)
  Protected image.i
  Protected backup.i
  Protected *parameter.Integer
  If *Buffer
    image = CatchImage(#PB_Any,*Buffer)
  Else
    If Path
      image = LoadImage(#PB_Any,Path)
    EndIf
  EndIf
  If IsImage(image)
    *parameter = image + $20                          ;<- pointer to the image structure (vacant spot afaik)
    backup = *parameter\i                             ;<- make a backup just to be safe
    If StartDrawing(ImageOutput(image))
      DrawingMode(#PB_2DDrawing_CustomFilter)
      *parameter\i = 123456789                        ;<- set the custom parameter
      CustomFilterCallback(@FilterImageCallback())
      Box(0,0,1,1)                                    ;<- process one pixel
      StopDrawing()
    Else
      FreeImage(image)
      image = #Null
    EndIf
    *parameter\i = backup                             ;<- restore the image structure
  EndIf
  ProcedureReturn image
EndProcedure

FilterImage(#Null,"test.jpg")

End


Top
 Profile  
Reply with quote  
 Post subject: Re: CustomFilterCallback() custom parameter! (Windows x64)
PostPosted: Wed May 08, 2019 9:06 am 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2068
Location: Germany
Callbacks are always called by the external function. Where is the additional parameter to come from?

I use a shared variable to pass my own parameters to the callback...

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: CustomFilterCallback() custom parameter! (Windows x64)
PostPosted: Wed May 08, 2019 3:42 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 577
mk-soft wrote:
Callbacks are always called by the external function. Where is the additional parameter to come from?

I use a shared variable to pass my own parameters to the callback...


The same way you provide the function address?!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye