Skip to content

Instantly share code, notes, and snippets.

@phoe
Created September 18, 2017 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phoe/3807df6283fd04499adf70747a643cac to your computer and use it in GitHub Desktop.
Save phoe/3807df6283fd04499adf70747a643cac to your computer and use it in GitHub Desktop.
;;; (ql:quickload :qtools)
(defmacro with-qimage-from-vector ((image-var vector width height) &body body)
"Establishes a lexical environment, in which IMAGE-VAR is bound to a QImage
created from the ARGB contents of VECTOR, with width WIDTH and height HEIGHT."
(with-gensyms (length v)
`(let* ((,length (array-dimension ,vector 0))
(,v (make-static-vector ,length :initial-contents vector)))
(unwind-protect
(with-finalizing
((,image-var (q+:make-qimage
(static-vector-pointer ,v)
,width ,height
(q+:qimage.format_argb32))))
,@body)
(free-static-vector ,v)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment