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

Drawing into Bitmaps



I need the following functionality: a macro that encloses a body of drawing
routines, with the argument of an existing bitmap, such that the figures
drawn by the drawing routines in absolute coordinates are drawn into the bitmap;
figures drawn overlapping or outside of  the edges of the bitmap are clipped;
and the alu is preserved (allowing selective erasing, flipping, etc.).

My current routine is the following:
(defmacro draw-into-bitmap (my-bitmap &rest body)
"Wrapper for drawing into a bitmap, instead of onto the screen.
   The body *must* use magic variable STREAM as the output.
   UNFORTUNATELY AUTO-ADJUSTS THE BITMAT TO THE UPPER LEFT.
   Remember in bitmaps, X points to the right, Y points down.
"
  `(multiple-value-bind (my-width my-height ignore-span-width)   (decode-raster-array ,my-bitmap)
     (let ((buffer  (tv:with-output-to-bitmap (stream) ,@body)))
	 (multiple-value-bind (new-width new-height ignore-span-width)   (decode-raster-array buffer)
	   (setq my-width (min my-width new-width))
	   (setq my-height (min my-height new-height))
	   (bitblt tv:alu-ior my-width my-height buffer 0 0 ,my-bitmap 0 0)   ;1 bits set; 0 bits left alone
	   )
	 )
     )
)

Example call:
(draw-into-bitmap bitmap-5
    (graphics:draw-polygon '(25 25  25 50  50 25) :stream STREAM :filled T)
)


Unfortunately, tv:with-output-to-bitmap apparently pulls something similar to 
with-room-for-presentation and auto-adjusts the drawn image's coordinates so that
the image is justified to the positive coordinate axes.  Thus the previous example's
triangle appears at (0,0) in the bitmap.  This is not desired.
  In addition, since this routine copies from the stream buffer into the specified
bitmap (one way to support clipping) using alu-ior, there is no way to support
non-drawing alu's in the code body.  E.g., suppose there were a solid rectangle in
the bitmap already, and the desired behavior is to overwrite part of this with a
50% grey filled circle--can't do it currently because the white pixels inside the
circle should erase, while the white pixels outside should leave things alone.

How can I draw graphics into an *existing* bitmap while supporting clipping and alus?

Grateful for any suggestions,
  John Myers~~