[cffi-devel] How would i use a function with a callback parameter

f9cef2aa at yandex.ru f9cef2aa at yandex.ru
Sun Oct 27 07:09:09 UTC 2013


>here is my attempt but i have no idea how to define a function as a pointer and ive tried alot of  variations but is too long to post.  The defun change contrast compiles btw...i tried using make-pointer to make the change-contrast function a pointer but make-pointer wants it to be a real...so cant use foreign-alloc i dont think because the function needs to be converted to a pointer first to use that...any guidance is appreciated
>
>(defun change-contrast (&optional contrast img dest)
>(if (< contrast 10) (scale img dest (/ 1 (coerce (- 11 contrast) 'double-float)))
>    (if (>= contrast 10) (scale img dest (- contrast 9))))
>     (show-image "MyImage" dest))
>
>(defun display (filename)
>  "Open the image FILENAME and show it in a window."
>  (let* ((img (load-image filename 1))
>        (img-size (get-size img))
>       (dest (create-image img-size +ipl-depth-8u+ 3))
>       (contrast (cffi:foreign-alloc :int :initial-contents '(10))
>      (test "not sure what to do here"))) 
>    (named-window "MyWindow" 1)
>   (create-trackbar "conrast" "MyWindow" contrast 21 test)
> (princ (mem-ref contrast :int))
>  (change-contrast (mem-ref contrast :int) img dest)
>    (loop while (not (= (wait-key 0) 27)))
>    (release-image img)
>    (release-image dest)
>    (destroy-window "MyWindow")))

Have you read defcallback documentation? If no, read it and try to use
defcallback. If yes, what was your problem when using defcallback?






More information about the cffi-devel mailing list