[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fast Access to PixMap Pixels



I need to access pixels of PixMaps and Bitmaps as fast as possible. Below
is a hack that gives me pretty fast access to 8 bit deep pixmaps (about
55 micro seconds on my good ole MacII), however, to access pixmaps/bitmaps
of any other depth that code is very slow (about 410 micro seconds).

I would really appreciate any hints on how I could make this faster -
especially the part dealing with bitmaps/pixmaps of depth 1.

;..some hack

(defun PIX-REF (Pixmap X Y) "
  in:  Pixmap {pixmap}, X Y {fixnum}.
  out: Pixel-Value {fixnum}."
  (declare (optimize (speed 3) (safety 0))
           (fixnum X Y))
  (case (rref Pixmap :PixMap.pixelSize)
    (8 (%get-byte  
        (rref Pixmap :pixmap.baseaddr) ; special optimized for 8 bit/pixel
        (ccl::%i+ 
         (ccl::%i* 
          (logand 
           #x7fff 
           (rref Pixmap :PixMap.rowBytes))
          Y)
         X)))
    (t
     (load-bits 
      (rref Pixmap :pixmap.baseaddr) 
      (logand #x7fff (rref Pixmap :PixMap.rowBytes))
      (rref Pixmap :PixMap.pixelSize)
      X Y))))

; it's probably the "ldb" that is slow..

(defun LOAD-BITS (Ptr Rowbytes Depth X Y) "
  in: Ptr {mac-pointer}, Rowbytes Depth X Y {fixnum}.
  Get the value from the memory location designated by <Ptr> assuming
  it is a two dimmensional array of pixel values with size <Depth>."
  (multiple-value-bind (N R) (truncate (* X Depth) 8)
    (let ((Byte-Index (+ (* Rowbytes Y) N)))
      (ldb (byte Depth (- 8 Depth R)) (%get-byte Ptr Byte-Index)))))

Time to access a 32 x 32 pixmap:

(pix-ref pixmap8 5 6)   ;=> 57 us
(pix-ref pixmap1 5 6)   ;=> 410 us



Would it be hard to do this better with the MCL lisp assembler?

   Alex Repenning