How do I approxmate C pointer dereferencing?

Joeish W joeish80829 at yahoo.com
Sat Oct 5 14:04:02 UTC 2013


in my library ive already written wrappers for these opencv functions 
create-camera-capture
query-frame
img-size
create-image

the struct related to create-image is IplImage and i have it defined like this






;; ;(cffi:foreign-type-size '(:struct ipl-image)) = 144
(cffi:defcstruct ipl-image
    (n-size :int)
    (id :int)
    (n-channels :int)
    (alpha-channel :int)
    (depth :int)
    (color-model :int) ;;Ignored by OpenCV - was :pointer, changed to :int so the struct values would match OpenCV's
    (channel-seq :int) ;;Ignored by OpenCV - was :pointer, changed to :int so the struct values would match OpenCV's
    (data-order :int)
    (origin :int)
    (align :int)
    (width :int)
    (height :int)
    (roi (:pointer (:struct ipl-roi)))
    (mask-roi :pointer)
    (image-id :pointer)
    (tile-info :pointer)
    (image-size :int)
    (image-data :string)
    (width-step :int)
    (border-mode :pointer)
    (border-const :pointer)
    (image-data-origin :string))






so when i call the above functions and then print the struct values with the below
code it looks like this






CL-OPENCV> (defparameter capture (create-camera-capture 0))
(defparameter frame (query-frame capture))
(defparameter img-size (get-size frame))
(defparameter img (create-image img-size +ipl-depth-8u+ 3))
IMG
CL-OPENCV> (cffi:with-foreign-slots ((n-size id n-channels 
                          alpha-channel depth color-model 
                          channel-seq data-order origin  
                          align width height roi 
                          mask-roi image-id tile-info 
                          image-size image-data width-step 
                          border-mode border-const image-data-origin) 

                          img (:struct ipl-image))
                          (format t "n-size = ~a~%id = ~a~%n-channels = ~a~%alpha-channel = ~a~%depth = ~a~%color-model = ~a~%channel-seq = ~a~%data-order = ~a~%origin = ~a~%align = ~a~%width = ~a~%height = ~a~%roi = ~a~%mask-roi = ~a~%image-id = ~a~%tile-info = ~a~%image-size = ~a~%image-data = ~a~%width-step = ~a~%border-mode = ~a~%border-const = ~a~%image-data-origin = ~a~%" 
                          n-size id n-channels 
                          alpha-channel depth color-model 
                          channel-seq data-order origin  
                          align width height roi 
                          mask-rOI image-id tile-info 
                          image-size image-data width-step 
                          border-mode border-const image-data-origin))
n-size = 144
id = 0
n-channels = 3
alpha-channel = 0
depth = 8
color-model = 4343634
channel-seq = 5392194
data-order = 0
origin = 0
align = 4
width = 640
height = 480
roi = #.(SB-SYS:INT-SAP #X00000000)
mask-roi = #.(SB-SYS:INT-SAP #X00000000)
image-id = #.(SB-SYS:INT-SAP #X00000000)
tile-info = #.(SB-SYS:INT-SAP #X00000000)
image-size = 921600
image-data = 
width-step = 1920
border-mode = #.(SB-SYS:INT-SAP #X00000000)
border-const = #.(SB-SYS:INT-SAP #X00000000)
image-data-origin = NIL
NIL





I'd rather not have to call  the with-foreign-slots function with all that code every time id like  to access slot values id rather do exactly like in c and call img->depth for example to access the IplImage  struct member depth....Is there a way i can have this exact functionality in lisp with the above struct or any other....if i did have to call (img depth) i guess that would be ok but id rather create  some sort of dereferencing  operator equivelant to do this as easy as in c....either way can someone show me how to dereference pointers in the tiniest way possible like in c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20131005/58b28711/attachment.html>


More information about the cffi-devel mailing list