-
chevron_right
WITH-QIMAGE-FROM-VECTOR
Michał "phoe" Herda · Sunday, 23 December, 2018 - 11:52
(This is a repost of an old blog post of mine from Teknik.)
I looked for a quick way of turning vectors of uint8
s into Qtools's QImages for purpose of displaying them.
This is a quick macro that I hacked up to do the job.
;;; (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)))))