[Openmcl-devel] iSight weirdness recap

Ron Garret ron at awun.net
Wed Jan 30 13:08:46 PST 2008


Here's the current state of affairs w.r.t. my iSight project:

1. Setting the max rendering frame rate seems to prevent the system  
from seizing up.  I've gone as high as 15 FPS so far.

2. Programmatically miniaturizing and deminiaturizing the window does  
not suffice to kick-start the rendering process.  It has to be done  
manually.  (I suspect this is because the mouse click event breaks  
some logjam in the Lisp processes, but I don't really understand  
what's going on behind the scenes here.)

3.  The snapshotImage method works to capture frames from the QCView  
except that:
3a.  Every now and then the captured image ends up being upside down (!)
3b.  Every now and then, capturing an image makes the render process  
hang (though thankfully not the whole machine).  No messages are  
generated on the console when this happens.  The only way I've found  
to recover it to close the window containing the QCView and regenerate  
it.

Finally, because this demo requires a Quartz composition, I decided to  
dig into the Quartz Composer docs and discovered that Quartz is really  
quite an amazingly powerful gadget (at least when it works).  If you  
haven't taken the time to explore Quartz and Quartz Composer I highly  
recommend it.

Demo code follows.

rg

---

(objc:load-framework "Quartz" :quartz)

(defun nsstr (s) (make-instance 'gui::ns-lisp-string :string s))

(defparameter +standard-window-style-mask+
   (logior #$NSTitledWindowMask
           #$NSClosableWindowMask
           #$NSMiniaturizableWindowMask
           #$NSResizableWindowMask))

(defun make-window (x y &optional (title "Untitled"))
   (bind (w (make-instance 'ns:ns-window
              :with-content-rect (ns:make-ns-rect 0 0 x y)
              :style-mask +standard-window-style-mask+
              :backing #$NSBackingStoreBuffered
              :defer t))
     (#/setContentView: w (make-instance 'ns:ns-view))
     (#/setTitle: w (nsstr title))
     (#/center w)
     (#/orderFront: w nil)
     w))

(defmacro with-focused-view (view &body forms)
   `(when (#/lockFocusIfCanDraw ,view)
      (unwind-protect
	  (progn , at forms)
        (#/unlockFocus ,view)
        (#/flushGraphics (#/currentContext ns:ns-graphics-context))
        (#/flushWindow (#/window ,view)))))

(defun draw-image (image view &optional (x 0) (y 0))
   (let ((alpha (float 1.0 ns:+cgfloat-zero+)))
     (with-focused-view view
        (ns:with-ns-rect (z 0 0 0 0)
           (#/drawAtPoint:fromRect:operation:fraction:
            image (ns:make-ns-point x y)
            z
            #$NSCompositeCopy
            alpha)))))

(setf w (make-window 300 200))
(setf qcv (make-instance 'ns:q-c-view
             :with-frame (ns:make-ns-rect 0 0 300 200)))
(#/loadCompositionFromFile: qcv #@"Cam.qtz")   ; Fix this for your  
local install
(#/setContentView: w qcv)
(#/setAutostartsRendering: qcv t)
(#/setMaxRenderingFrameRate: qcv 15.0)
(sleep 0.1)
(#/startRendering qcv)
(#/miniaturize: w nil)
(#/deminiaturize: w nil)
; A manual min/demin cycle at this point will kickstart the rendering

(setf w1 (make-window 300 200))
(defun snap ()
   (draw-image (setf img (#/snapshotImage qcv)) (#/contentView w1))
   (values))

; Danger, Will Robinson!  Make sure all your files are saved before  
you try this!
(loop (snap) (sleep 0.1))




More information about the Openmcl-devel mailing list