x13*_*13n 3 lisp gtk common-lisp gdk
我试图在Lisp中用(Gdk)pixbuf编写自己的put-pixel.当我终于意识到我如何操作CL中的C指针时,出现了新的障碍 - (gdk:pixbuf-get-pixels pb)返回负数.我的问题是:我能以某种方式将其转换为有效指针吗?我尝试使用cffi:convert-from-foreign和cffi:translate-from-foreign(它们之间有什么不同?)失败了.
以下是我的实际(不工作)代码:
(defun put-pixel (pixbuf x y r g b)
(let ((p (+ (gdk:pixbuf-get-pixels pixbuf) (* x (gdk:pixbuf-get-n-channels pixbuf)) (* y (gdk:pixbuf-get-rowstride pixbuf)))))
(setf (cffi:mem-aref p :unsigned-char 0) r)
(setf (cffi:mem-aref p :unsigned-char 1) g)
(setf (cffi:mem-aref p :unsigned-char 2) b)))
Run Code Online (Sandbox Code Playgroud)
CFFI:TRANSLATE-FROM-FOREIGN是一个通用函数.您可以使用CFFI:DEFINE-FOREIGN-TYPE定义自己的外部类型,然后向CFFI:TRANSLATE-FROM-FOREIGN添加一个方法,以指定从外部到Lisp值的转换应该如何工作.
CFFI:如果需要显式转换某些值,则应调用CONVERT-FROM-FOREIGN.它将在后台调用CFFI:TRANSLATE-FROM-FOREIGN,如果可能的话,它可能会执行一些编译时优化.
同样的事情适用于CFFI:CONVERT-TO-FOREIGN和CFFI:TRANSLATE-TO-FOREIGN.
| 归档时间: |
|
| 查看次数: |
205 次 |
| 最近记录: |