home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / lisp / mcl / 1610 < prev    next >
Encoding:
Text File  |  1992-11-17  |  5.3 KB  |  108 lines

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!darwin.sura.net!wupost!usc!elroy.jpl.nasa.gov!ames!data.nas.nasa.gov!taligent!apple!cambridge.apple.com!ferrante@world.std.com
  2. From: ferrante@world.std.com (Richard D Ferrante)
  3. Newsgroups: comp.lang.lisp.mcl
  4. Subject: displaying data & faq
  5. Message-ID: <199211171248.AA10442@world.std.com>
  6. Date: 17 Nov 92 12:48:23 GMT
  7. Sender: info-mcl-request@cambridge.apple.com
  8. Lines: 97
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10.  
  11. From a few weeks ago I noticed some questions about displaying data
  12. and determining monitor settings I've been on vaction so didn't
  13. respond. Since this a recurring question I'd thought I'd post the
  14. following code which was developed with the help of others on the net.
  15.  
  16. Note the code is a hack designed for my own specific needs, it is not
  17. general purpose specifically it expects an 8-bit grayscale monitor and
  18. positive fixnum scale factors.  All zooming is simple pixel replication.
  19.  
  20.  
  21. (defun first-monitor-depth-and-colorp ()
  22.   (let ((first-monitor (#_GetDeviceList))
  23.         (thePixMapHdl nil)
  24.         (Depth 0)
  25.         colorp)
  26.     (with-dereferenced-handles ((aGDevicePtr first-monitor))
  27.       (setf thePixMapHdl (rref first-monitor GDevice.gdPMap))
  28.       (setf Depth (rref thePixMapHdl PixMap.pixelSize))
  29.       (setq colorp (#_testdeviceattribute first-monitor 0)))
  30.     (values Depth colorp)))
  31.  
  32. (defmethod to-pixmap ((im image) (w window) &optional (preset-scale nil))
  33.   
  34.   (let ((pixmap (rref (wptr w) CGrafPort.portPixMap))
  35.         top left right bottom 
  36.         (screen-width *screen-width*)
  37.         scale-factor
  38.         (required-depth 8)
  39.         (required-colorp nil)
  40.         colorp depth
  41.         )
  42.     (multiple-value-setq (depth colorp) (first-monitor-depth-and-colorp))
  43.     (cond
  44.      ((or (/= depth required-depth) (nequal required-colorp colorp))
  45.       (#_sysbeep 5)
  46.       (format t "~% Wrong monitor attributes depth ~a must be ~a" depth required-depth)
  47.       (format t "~%                          color ~a must be ~a" colorp required-colorp))
  48.      (t 
  49.       (multiple-value-bind (upper-left bottom-right) (view-corners w)
  50.         (declare (ignore upper-left))
  51.         (multiple-value-bind (position) (view-position w)
  52.           (setq top (point-v position))
  53.           (setq left (point-h position))
  54.           (setq right (+ left (point-h bottom-right)))
  55.           (setq bottom (+ top (point-v bottom-right)))))
  56.       (with-slots (max-i max-j data-array) im
  57.         (cond (preset-scale
  58.                (setq scale-factor (truncate preset-scale)))
  59.               (t (setq scale-factor (min (truncate (- right left) max-i) (truncate (- bottom top) max-j))))
  60.               )
  61.         (cond ((= scale-factor 1)
  62.                (loop for i fixnum from 0 below max-i
  63.                      for row-count fixnum from top                  
  64.                      do
  65.                      (loop for j fixnum from 0 below max-j
  66.                            for col-count fixnum from left
  67.                            do
  68.                            (%put-byte pixmap (aref data-array i j)  (+ (* row-count screen-width) col-count)))))
  69.               ((> scale-factor 1) ;empirically determined value for which the copy-bits overhead is worth it, probably varies by machine
  70.                
  71.                
  72.                (with-macptrs ((view-bm (rref (wptr w) :grafport.portBits)))
  73.                  (loop for i fixnum from 0 below max-i
  74.                        for row-count fixnum from (+ top (* (- scale-factor 1) max-i))
  75.                        do
  76.                        (loop for j fixnum from 0 below max-j
  77.                              for col-count fixnum from (+ left (* (- scale-factor 1) max-j));left 
  78.                              do
  79.                              (%put-byte pixmap (aref data-array i j)  (+ (* row-count screen-width) col-count))))
  80.                  (rlet ((r1 :rect
  81.                             :topleft (make-point (* (- scale-factor 1) max-i) (* (- scale-factor 1) max-j))
  82.                             :bottomright (make-point (- (* scale-factor  max-i) 1) (- (* scale-factor max-j ) 1)))
  83.                         (r2 :rect
  84.                             :topleft (make-point 0 0)
  85.                             :bottomright (make-point (- (* scale-factor  max-i) 1) (- (* scale-factor max-j ) 1))
  86.                             ))
  87.                    (copy-bits view-bm view-bm r1 r2)
  88. ))) 
  89.               (t
  90.                (loop for i fixnum from 0 below max-i
  91.                      for row-count fixnum from top by scale-factor 
  92.                      with value
  93.                      do
  94.                      (loop for j fixnum from 0 below max-j
  95.                            for col-count fixnum from left by scale-factor
  96.                            do
  97.                            (setq value (aref data-array i j))
  98.                            (loop for window-offset from (+ (* row-count screen-width) col-count) by screen-width
  99.                                  for window-row from 0 below scale-factor
  100.                                  do
  101.                                  (loop for window-col from 0 below scale-factor
  102.                                        do
  103.                                        (%put-byte pixmap value (+ window-offset window-col))
  104.                                        )))))))
  105.       (when (typep w 'image-display-window)
  106.         (setf (slot-value w 'image-being-displayed) im)
  107.         (setf (slot-value w 'image-scale-factor) scale-factor))))))
  108.