[ab] Fast pixel access

Luke Crook luke at balooga.com
Mon Nov 27 20:23:23 CST 2006


Anthony Fairchild <anthonyf at ...> writes:
> 
> The function works but the pixel access is very slow.  

Anthony,

I have added a new macro and a couple of generator functions that should 
hopefully speed things up.

1) The WITH-PIXELS macro allows for 'fast' access to a single surface to read 
and write individual pixels. This should speed up simple operations such as 
line drawing etc. WITH-PIXELS defines 4 local functions that are used to read/
write pixels. WRITE-PIXEL, WRITE-POINT, READ-PIXEL, READ-POINT. E.g.

(sdl:with-pixels (surf)
  (sdl:write-pixel x y (sdl:map-color :color color :surface surf))
  (sdl:write-point point color)

  (sdl:read-pixel x y)
  (sdl:read-point point))


2) GENERATE-READ-PIXEL and GENERATE-WRITE-PIXEL; these funcations return 
functions that can be used to read from or write the pixels of a surface 
respectively. The 
surface should be locked prior to calling the function generated by these 
functions. So in your rotation example you could do something like the 
following:

(let ((src-read  (generate-read-pixel  src-surface))
      (dst-write (generate-write-pixel dst-surface)))
  (sdl:with-locked-surface (src-surface)
    (sdl:with-locked-surface (dst-surface)

      (funcall dst-write x2 y2 (funcall src-read x1 y1)))))





More information about the application-builder mailing list