I tried to write my own pixel on (Gdk) pixbuf in Lisp. When I finally understood how I can work with C-pointers in CL, a new obstacle appeared - (gdk: pixbuf-get-pixels pb) returns me a negative number. My question is: can I somehow convert it to a valid pointer? My attempts to use cffi: convert-from-foreign and cffi: translate-from-foreign (what's the difference between them anyway?) Failed.
Below is my actual (not working) code:
(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)))
source
share